[BACK]Return to tk_asir_contrib_update.rr CVS log [TXT][DIR] Up to [local] / OpenXM / src / asir-contrib / packages / src

File: [local] / OpenXM / src / asir-contrib / packages / src / tk_asir_contrib_update.rr (download)

Revision 1.18, Wed Mar 30 07:16:50 2022 UTC (2 years, 2 months ago) by takayama
Branch: MAIN
CVS Tags: HEAD
Changes since 1.17: +6 -6 lines

Bit pattern is not used.

/* $OpenXM: OpenXM/src/asir-contrib/packages/src/tk_asir_contrib_update.rr,v 1.18 2022/03/30 07:16:50 takayama Exp $ */
/*
  We assume that (windows)
  (1) curl and zip are installed in asir/bin
  (2) %APPDATA%\OpenXM\lib\asir-contrib is in the top of your search path.
  (unix) 
  (1) curl and zip are installed in the search path.
  (2) $OpenXM_tmp/OpenXM/lib/asir-contrib is in the top of your search path.
*/
extern Tk_UpdateCC$
module tk_asir_contrib_update;
static OpenXM_tmp;
localf set_OpenXM_tmp;
localf ostype;
localf mymessage;
localf asir_contrib_update;
localf myshell;
localf mystrtoascii;
localf contain_space; /* should be moved to tk_util.rr */
localf asir_contrib_update_win;
localf asir_contrib_update_unix;

def set_OpenXM_tmp() { 
  OpenXM_tmp=getenv("OpenXM_tmp");
  if (OpenXM_tmp == 0) OpenXM_tmp=getenv("HOME")+"/.OpenXM_tmp";
}
def ostype() {
  return sysinfo()[0];
}
def contain_space(S) {
  if (base_subsetq(strtoascii(" "),strtoascii(S))) return 1;
  else return 0;
}
def mymessage(OS) {
   printf("The asir-contrib library and/or other update files provided on our web will be updated to the HEAD branch with the command asir_contrib_update(|update=1)\n");
   printf("If update=2, then documents will be downloaded. If update=3, then both of library files and documents will be downloaded.\n");
   printf("Note that it might cause troubles because of an incompatibility of the binary asir and the asir-contrib.\n");
   printf("If you understand this risk and want to update to the HEAD branch, execute the command above.\n");
   if (OS == "Windows") {
     printf("\n***** Note on Windows *****\n");
     printf("It is installed under "+getenv("APPDATA")+"\\OpenXM\n");
     printf("In order to call pari, download the ox_pari server by asir_contrib_update(|update=4);\n");
     printf("  The option update=4 installs cygwin binary distribution (cygwin executables, ox servers and libraries including ox_pari.exe)\n");
     printf("  It rollbacks the asir-contrib library to the cygwin binary distribution. Then, you need to do update=1 if you want the latest asir-contrib.\n");
     printf("  OpenXM-win may be moved under c:/ProgramData/asir/OpenXM by hand.\n");
   }else {
     printf("It is installed under "+OpenXM_tmp+"/OpenXM\n");
   }
   printf("The following command will be executed with the following options.\n");
}
def asir_contrib_update() {
  Opt=getopt();
  if (ostype() == "windows") {
     return asir_contrib_update_win(|option_list=Opt);
  }else{
     return asir_contrib_update_unix(|option_list=Opt);
  }
}
def myshell(S) {
  printf("%a",S); if (shell(S)) printf(" -->failed.\n"); else printf("\n");
}
def mystrtoascii(S) {
  if (type(S) != 7) return [];
  else return strtoascii(S);
}
/*
options.
update, clean, url, zip_files, tmp, install_dir
*/
def asir_contrib_update_win() {
  Update = 0;
  Clean = 0;
  Tk_UpdateCC = [];
  if (type(getopt(update)) <= 0) {
  }else{
    Update=getopt(update);
  }
  if (type(getopt(clean)) <= 0) { } else { Clean=1;}
  if (!Update && !Clean) mymessage("Windows");
  MyCurl = "\""+getenv("ASIR_ROOTDIR")+"bin\\curl\""; 
  MyUnzip = "\""+getenv("ASIR_ROOTDIR")+"bin\\unzip\""; 
  if (type(getopt(tmp))<=0) MyTmp = getenv("TEMP");
  else MyTmp = getopt(tmp);
  if (type(getopt(install_dir))<=0) InstallDir0=getenv("APPDATA")+"\\OpenXM";
  else InstallDir0 = getopt(install_dir);
  InstallDir=InstallDir0+"\\";
  Trash=getenv("TEMP");
  if (contain_space(InstallDir0)) error("Error: install_dir="+InstallDir0+" contains space characters.");
  if (contain_space(MyTmp)) error("Error: tmp="+MyTmp+" contains space characters");
  if (rtostr(sysinfo()[6]) == "ja") {
    if (util_damepathq(InstallDir0)[0] ) error("Error: install_dir="+InstallDir0+" contains dame-moji.");
    if (util_damepathq(MyTmp)[0] ) error("Error: tmp="+MyTmp+" contains dame-moji.");
  }
  if (type(getopt(url)) <=0) Url = "http://www.math.kobe-u.ac.jp/OpenXM/Current";
  else Url=getopt(url);
  if (type(getopt(zip_files))<=0) ZipFiles = ["lib-asir-contrib.zip"];
  else ZipFiles=getopt(zip_files);

  if (Update && (type(getopt(zip_files))<=0)) {
    ZipFiles=[];
    if (Update==4) ZipFiles = append(["openxm-win-oxpari.zip"],ZipFiles);
    if (Update==2) ZipFiles = append(["doc-asir-contrib.zip","doc-asir2000.zip","doc-other-docs.zip"],ZipFiles);
    if (Update==1) ZipFiles = append(["lib-asir-contrib.zip"],ZipFiles);
  }

  C2move="move /Y " + "\""+InstallDir0+"\"" + " \""+Trash+"\\asir-lib-trash\"";
  C2mkdir = "mkdir  "+"\""+InstallDir+"\"";
  for (I=0; I<length(ZipFiles); I++) {
   ZipFile=ZipFiles[I];
   C1=MyCurl+" "+Url+"/"+ZipFile+" >"+MyTmp+"\\"+ZipFile+" 2> "+MyTmp+"\\asir-contrib-update-error.txt";
   /*   C2=MyUnzip+" -o "+"\""+MyTmp+"\\"+ZipFile+"\" -d "+InstallDir; */
    C2=MyUnzip+" -o "+MyTmp+"\\"+ZipFile+" -d "+InstallDir;    
    if (!Update && !Clean) {
    print("---- update=1 ------");
    print(C1);  
    print(C2mkdir); 
    print(C2);
    print("----- clean=1 ------");
    print(C2move); 
    printf("---------------------------------------------------\n"); 
   }
   if (Clean == 1) {
    myshell(C2move);
    print("Please clean asir-lib-trash on your desktop by hand.");
   }
   Tk_UpdateCC=cons([C1,C2mkdir,C2move,C2],Tk_UpdateCC);
   if (Update) {
    myshell(C1); myshell(C2mkdir); myshell(C2);
   }
  }
}
def asir_contrib_update_unix() {
  Update = 0;
  Clean = 0;
  Tk_UpdateCC = [];
  if (type(getopt(update)) <= 0) {
  }else{
    Update=getopt(update);
  }
  if (type(getopt(clean)) <= 0) { } else { Clean=1;}
  if (!Update && !Clean) mymessage("unix");
  MyCurl = "curl";
  MyUnzip = "unzip";
  if (type(getopt(tmp))<=0) {
    MyTmp = OpenXM_tmp;
  } else MyTmp = getopt(tmp);
  if (type(getopt(install_dir))<=0) InstallDir0=OpenXM_tmp+"/OpenXM";
  else InstallDir0 = getopt(install_dir);
  InstallDir=InstallDir0+"/";
  Trash=getenv("HOME");  /* bug, find .Trash */
  if (contain_space(InstallDir0)) error("Error: install_dir="+InstallDir0+" contains space characters.");
  if (contain_space(MyTmp)) error("Error: tmp="+MyTmp+" contains space characters");
  if (type(getopt(url)) <=0) Url = "http://www.math.kobe-u.ac.jp/OpenXM/Current";
  else Url=getopt(url);
  if (type(getopt(zip_files))<=0) ZipFiles = ["lib-asir-contrib.zip"];
  else ZipFiles=getopt(zip_files);

  if (Update && (type(getopt(zip_files))<=0)) {
    ZipFiles=[];
    if (Update==2) ZipFiles = append(["doc-asir-contrib.zip","doc-asir2000.zip","doc-other-docs.zip"],ZipFiles);
    if (Update==1) ZipFiles = append(["lib-asir-contrib.zip"],ZipFiles);
  }

  C2move="mv " + InstallDir0 + " " + Trash+"/.asir-lib-trash";
  C2mkdir = "mkdir -p "+InstallDir;
  for (I=0; I<length(ZipFiles); I++) {
   ZipFile=ZipFiles[I];
   C1=MyCurl+" "+Url+"/"+ZipFile+" >"+MyTmp+"/"+ZipFile+" 2> "+MyTmp+"/asir-contrib-update-error.txt";
    C2=MyUnzip+" -o "+MyTmp+"/"+ZipFile+" -d "+InstallDir;    
    if (!Update && !Clean) {
    print("---- update=1 ------");
    print(C1);  
    print(C2mkdir); 
    print(C2);
    print("----- clean=1 ------");
    print(C2move); 
    printf("---------------------------------------------------\n"); 
   }
   if (Clean == 1) {
    myshell(C2move);
    print("Please clean asir-lib-trash on your HOME by hand.");
   }
   Tk_UpdateCC=cons([C1,C2mkdir,C2move,C2],Tk_UpdateCC);
   if (Update) {
    myshell(C1); myshell(C2mkdir); myshell(C2);
   }
  }
}
endmodule;
tk_asir_contrib_update.set_OpenXM_tmp()$

end$
/* Note on Windows.
Redirected files must not be enclosed by " for system()
CC2="dir > \"\\users\\math\\t.txt\""; shell(CC2); will cause an error.
"C:\Users\math\Desktop\asir\bin\curl" http://www.math.kobe-u.ac.jp/OpenXM/Current/lib-asir-contrib.zip >"C:\Users\math\AppData\Local\Temp\lib-asir-contrib.zip" 2> "C:\Users\math\AppData\Local\Temp\asir-contrib-update-error.txt"
*/