#include <../../libmodules/guruengine/guruengine.h> #include <../../libmodules/filesystem/filesystem.h> #include #include "xterminals.h" #include "xterminals.m" #include static HELP_FILE help_runtime ("xterminals","runtime"); static bool runtime_introlog; static void runtime_setlog () { if (!runtime_introlog){ net_introlog (NETINTRO_MISC); runtime_introlog = true; } } static bool runtime_rpmok ( const SSTRING &dir, const char *subdir, bool test, SSTRING &mpoint) { bool ret = false; SSTRING tmp; tmp.setfromf ("%s/%s",dir.get(),subdir); if (file_type(tmp.get())==1){ ret = true; }else if (!test){ runtime_setlog(); ret = filesystem_ismounted (tmp.get(),mpoint,""); } return ret; } static bool runtime_rpmok ( const SSTRING &dir, const char *subdir, SSTRING &mpoint) { return runtime_rpmok (dir,subdir,false,mpoint); } /* Check if the RPMS packages are available (already mounted) */ static bool runtime_rpmok (const SSTRING &dir, const char *subdir) { SSTRING mpoint; return runtime_rpmok (dir,subdir,true,mpoint); } /* Execute and present the log if any errors */ static void runtime_exec (const char *cmd, const char *opt) { runtime_setlog(); net_resetnberr(); netconf_system_if (cmd,opt,600); if (net_getnberr()) net_showlastlog(); } static void runtime_install (int sel, const SSTRING &dir, const char *subdir) { static const char *tbsuffix[]={ "redhat6.2", "redhat7.0", "redhat7.1", "redhat7.2", "redhat7.3", "redhat8.0", "mandrake8.0", }; static const char *tboptions[]={ "--nodeps", "", "--nodeps", "--nodeps", "--nodeps", "--nodeps", "--nodeps", }; SSTRING tmp; tmp.setfromf ("--noprompt --RPMS %s/%s --RPMOPTIONS \"%s\" --SUFFIX %s --USELINUXCONF" ,dir.get(),subdir,tboptions[sel],tbsuffix[sel]); runtime_exec ("xterminals-setup.sh",tmp.get()); runtime_exec ("xterminals-setup-post.sh",""); } /* Return true if the module managerpm is enabled. */ static bool runtime_managerpm() { return module_is_enabled ("managerpm"); } enum XTERMKIT_STATUS { XTERMKIT_NOTCHECKED, // We have not probed the rpm yet XTERMKIT_MISSING, // Package not installed XTERMKIT_OK, // Package is installed and current XTERMKIT_OLD, // too old, must upgrade }; /* Return true if the package xtermkit is installed and newer than 2.6. Avoid probing needlessly. */ static void runtime_xtermkit_ok(XTERMKIT_STATUS &checked) { if (checked == XTERMKIT_NOTCHECKED){ checked = XTERMKIT_MISSING; PACKAGE_API *api = package_api_init ("xterminals/runtime"); if (api != NULL){ PACKAGE_VERSION ver; if (api->getver(api,"xtermkit",ver) != -1){ int n = ver.tb[0].val * 100 + ver.tb[1].val; if (n >= 206){ checked = XTERMKIT_OK; }else{ checked = XTERMKIT_OLD; } } } } } void xterminals_install() { char sel; SSTRING cddir; XTERMKIT_STATUS xtermkit; const char *subdir; glocal.subdir = "RedHat/RPMS"; glocal.sel = 0xff; glocal.cddir.setfrom ("/mnt/cdrom"); glocal.xtermkit = XTERMKIT_NOTCHECKED; runtime_introlog = false; (MSG_U(T_XTERMRUNTIME,"X terminals runtime") ,MSG_U(I_XTERMRUNTIME ,"We must install some packages for the X terminals.\n" "These packages will be installed in the directory\n" "/xterminals/root.\n" "We are in fact installing a tiny linux inside your current\n" "Linux installation. Except for the disk space (about 100 megabytes)\n" "the installation is fully independant from the packages\n" "currently installed on this computer.") ,help_runtime); (mode,status); status.is_possible = true; status.some_errors = file_exist ("/xterminals/root"); settitle (MSG_U(T_ISINSTALL,"Is the runtime already installed")); if (!file_exist ("/xterminals/root")){ allfine(); setintro (MSG_U(I_NOTINSTALLED ,"Ok, the runtime is not already installed\n" "(directory /xterminals/root does not exist)\n" "We can proceed")); edit(); }else{ attention(); setintro (MSG_U(I_ISINSTALLED ,"The X terminals runtime is already installed.\n" "Do you want to re-install it ?")); char uninstall=0; dia.newf_chk (MSG_U(F_YESYES,"Yes I am sure"),uninstall ,MSG_U(I_YESYES,"I want to re-install the runtime")); dia.newline(); if (edit()){ if (!uninstall){ xconf_notice (MSG_U(N_LEFTINPLACE,"Ok, current runtime left in place")); }else{ if (dialog_yesno(MSG_U(T_REMOVERUNTIME,"Removing runtime") ,MSG_U(I_REMOVERUNTIME ,"We will erase the directory /xterminals/root.\n" "This will take few seconds.") ,help_nil)==MENU_YES){ runtime_exec ("xterminals-removeruntime","-fr /xterminals/root"); } } } } status.is_possible = !file_exist("/xterminals/root"); status.is_filled = runtime_managerpm(); settitle (MSG_U(T_CHKPACKAGEAPI,"Is the managerpm module enabled ?")); if (runtime_managerpm()){ allfine(); setintro (MSG_U(I_CHKPACKAGEAPIOK ,"The managerpm module is currently enabled.\nNothing to do")); edit(); }else{ attention(); setintro (MSG_U(I_CHKPACKAGEAPINOTOK ,"The managerpm module is not currently enabled.\n" "We will enable it")); if (edit()){ module_setone ("managerpm",true,true); module_load(); } } status.is_possible = !file_exist("/xterminals/root") && runtime_managerpm(); runtime_xtermkit_ok(glocal.xtermkit); status.some_errors = glocal.xtermkit == XTERMKIT_OLD || glocal.xtermkit == XTERMKIT_MISSING; status.is_filled = glocal.xtermkit == XTERMKIT_OK; settitle (MSG_U(T_CHKXTERMKIT,"Is the xtermkit package installed ?")); if (glocal.xtermkit == XTERMKIT_MISSING){ attention(); setintro (MSG_U(I_XTERMKITMISSING ,"The xtermkit package is not installed.\n" "Pick it from http://www.solucorp.qc.ca/xterminals\n" "\n" "We can't do more for now")); edit(); }else if (glocal.xtermkit == XTERMKIT_OLD){ attention(); setintro (MSG_U(I_XTERMKITOLD ,"The xtermkit package is too old.\n" "Upgrade to version 2.5 or more from\n" "http://www.solucorp.qc.ca/xterminals\n" "\n" "We can't do more for now")); edit(); }else{ allfine(); setintro (MSG_U(I_XTERMKITOK ,"The xtermkit package is correctly installed.\n" "We can proceed")); edit(); } status.is_possible = !file_exist("/xterminals/root") && glocal.xtermkit == XTERMKIT_OK; settitle (MSG_U(T_SELECTDIST,"Distribution selection")); setintro (MSG_U(I_SELECTDIST ,"We must select the distribution we will use to install\n" "the X terminals runtime. This may be the same distribution\n" "you are currently using, or a different one.")); if (glocal.sel == 0xff) glocal.sel = 4; for (int i=0; i<5; i++){ static const char *tb[][2]={ {"RedHat Linux", "6.2"}, {"", "7.0"}, {"", "7.1"}, {"", "7.2"}, {"", "7.3"}, {"", "8.0"}, {"Mandrake Linux", "8.0"}, }; dia.newf_radio (tb[i][0],glocal.sel,i,tb[i][1]); dia.newline(); } if (edit (help_runtime)){ glocal.subdir = glocal.sel == 6 ? "Mandrake/RPMS" : "RedHat/RPMS"; } status.is_possible = glocal.sel != 0xff; status.some_errors = file_type (glocal.cddir.get())!=1; settitle (MSG_U(T_CDROMPATH,"Cdrom mount point")); setintro (MSG_U(I_CDROMPATH ,"Enter the path of the CDROM mount point (/mnt/cdrom)\n" "on most distributions")); dia.newf_str (MSG_U(F_CDROMPATH,"Mount point"),glocal.cddir); while (edit(help_runtime)){ const char *dir = glocal.cddir.get(); int type = file_type(dir); if (type != 1){ if (type == -1){ xconf_error (MSG_U(E_DIRMISSING,"%s does not exist") ,dir); }else{ xconf_error (MSG_U(E_NOTADIR,"%s exist but is not a directory") ,dir); } }else{ break; } } status.is_possible = file_type (glocal.cddir.get())==1; status.is_filled = runtime_rpmok (glocal.cddir,glocal.subdir); settitle (MSG_U(T_ISMOUNTED,"Is the CD-rom mounted")); if (runtime_rpmok (glocal.cddir,glocal.subdir)){ allfine(); setintro (MSG_U(I_MOUNTEDOK ,"The packages are available.\n" "We will now proceed to the installation")); if (edit()){ runtime_install(glocal.sel,glocal.cddir,glocal.subdir); } }else{ attention(); setintro (MSG_U(I_MOUNTEDNOTOK ,"The packages are not available.\n" "We will perform the mount to access the CD\n" "and proceed to the installation")); if (edit()){ SSTRING mpoint; runtime_rpmok (glocal.cddir,glocal.subdir,mpoint); runtime_install(glocal.sel,glocal.cddir,glocal.subdir); filesystem_unmountif (mpoint); } } }