def purge_old_birch(): print_label("Purging old BIRCH") os.chdir(ARGS.install_dir) contents=os.listdir(os.getcwd()) if "install-birch" in contents: for each in birch_files: if (each!="local" and each.count("birch_backup")!=1 and os.path.lexists(ARGS.install_dir+"/"+each)): print_console("Removing old BIRCH component: "+each) filename=ARGS.install_dir+"/"+each if (os.path.isdir(filename)): try: shutil.rmtree(filename) if (os.path.isdir(filename)): os.remove(filename) except: err=traceback.format_exc() print_console(err) JOptionPane.showMessageDialog(None, "An error occurred deleting file: "+filename) else: pass
def replace_all(file,searchExp,replaceExp): print_console("Replacing lines in file"+file) if (os.path.lexists(file)): for line in fileinput.input(file, inplace=1): if searchExp in line: line = line.replace(searchExp,replaceExp) sys.stdout.write(line)
def purge_old_birch(): print_label("Purging old BIRCH") os.chdir(ARGS.install_dir) contents = os.listdir(os.getcwd()) if "install-birch" in contents: for each in birch_files: if (each != "local" and each.count("birch_backup") != 1 and os.path.lexists(ARGS.install_dir + "/" + each)): print_console("Removing old BIRCH component: " + each) filename = ARGS.install_dir + "/" + each if (os.path.isdir(filename)): try: shutil.rmtree(filename) if (os.path.isdir(filename)): os.remove(filename) except: err = traceback.format_exc() print_console(err) JOptionPane.showMessageDialog( None, "An error occurred deleting file: " + filename) else: pass
def extract_binary(binary): if (os.path.lexists(ARGS.install_dir +"/"+binary+ ".tar.gz")): if (windows): cygwin_untar(ARGS.install_dir +"/"+binary+ ".tar.gz",binary+ ".tar.gz") else: untar(binary+ ".tar.gz") else: print_console( "The required file "+binary+ ".tar.gz was not found")
def check_depend(depend): #if the dependency is found, then this will evaluate to true, else, false found= os.popen("which "+depend).read().strip() !="" print_console("Dependancy \""+depend+"\" found: "+str(found)) if (not found): return False else: return True
def get_binary(platform): url = ARGS.BIN_URL url=url.replace("$PLATFORM",platform) if (ARGS.is_development): url=url.replace("$TYPE","D") url=url.replace("CURRENT","Development") else: url=url.replace("$TYPE",ARGS.NEWEST_VERSION) print_console( "Downloading binaries for platform \"" + platform + "\" to " + ARGS.install_dir + " from " + url) wget(url, platform+".tar.gz",CONSOLE)
def clobber_check(): if (os.path.lexists(ARGS.install_dir)): contents=os.listdir(ARGS.install_dir) if (contents.count("local")!=0 or os.path.exists(ARGS.install_dir+"/admin/BIRCH.properties")): print_console("ERROR! The directory specified already contains a BIRCH installation! Aborting") JOptionPane.showMessageDialog(None,"Installation cancelled to prevent clobbering existing installation.\nPlease restart installer and select a different directory, or remove old installation") shutdown() else: check=os.popen("echo $BIRCH").read().strip() if (check!=None and check!=""): print_console("An existing BIRCH installation was found at:\""+check+"\"") if (os.path.lexists(check) and os.path.samefile(check, ARGS.install_dir)): message="The installation directory that you specified:\n"+ARGS.install_dir+"\nAlready contains a BIRCH installation. Are you sure you wish to proceed?(NOT recommended)" reload = JOptionPane.showConfirmDialog(None,message, "Input",JOptionPane.YES_NO_OPTION); if (reload==JOptionPane.NO_OPTION): print_console("User aborted install.") shutdown() else: print_console("User decided to install over old installation.") return
def set_permissions(home): print_console("Setting permissions") os.popen("chmod a+rx .") os.popen("chmod a+rx newuser "+home+"/install-birch/makelinks.sh") os.popen("chmod a+rx "+home) contents=os.listdir(home) for each in contents: if (os.path.isdir(each)): os.popen("chmod a+rx "+each) os.popen("chmod a+rx "+home+"/admin/launchers/birch.desktop")
def update_birch(): print_label("Updating BIRCH") check_directory(ARGS.install_dir) os.chdir(ARGS.install_dir) if (ARGS.make_backup): compress_old_birch() run_nobirch() purge_old_birch() main_install() print_console("Update complete")
def check_depends(): def check_depend(depend): #if the dependency is found, then this will evaluate to true, else, false found= os.popen("which "+depend).read().strip() !="" print_console("Dependancy \""+depend+"\" found: "+str(found)) if (not found): return False else: return True dependancies=["csh","java","python"] foundall=True for each in dependancies: foundall=check_depend(each) if (not foundall): print_console("Dependancy " + each+ " not found on system path!") return False return foundall
def main(homedir,homepath): if (os.path.isdir(homedir)): mini = check_mini(homedir) print_console("minibirch = "+str(mini)) os.chdir(homedir+"/admin") if (homepath!=None): home=homepath else: home=homedir if (mini): print_console("Minibirch is not currently supported by birchhome") setup_mini(home) else: setup_birch(home) replace_all_ldirs(home) set_permissions(home) set_db_id(home,"frist") set_db_id(home,"psgendb") else: print_console("No such directory: "+homedir+", exitting in failure") exit(1)
def check_directory(path): if (os.path.lexists(path)): contents = os.listdir(path) if (contents.count("install-birch") == 0): print_console("The selected directory " + path + " does NOT contain a BIRCH installation!") message = "The selected path does NOT contain a BIRCH installation.\nPlease select the base directory of the installation that you wish to update,\nOr click \"no\" to cancel update." reload = JOptionPane.showConfirmDialog(None, message, "Input", JOptionPane.YES_NO_OPTION) if (reload == JOptionPane.NO_OPTION): print_console("User aborted install.") commonlib.shutdown() fc = JFileChooser() fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY) fc.showOpenDialog(None) path = fc.getSelectedFile().getPath() check_directory(path) else: ARGS.install_dir = path print_console("The selected directory " + path + " contains a BIRCH installation, it will be updated")
def main(cwd): try: start = time.time() run_main(cwd) #this will produce a crash: must be called as module end = time.time() elapsed= end - start min = elapsed/60 print_console("Installation took "+str(min)+" minutes.") JOptionPane.showMessageDialog(None,"Please bookmark BIRCH custom documentation, which will appear in a web browser") showCustomDoc() JOptionPane.showMessageDialog(None,"Installation completed successfully.") except: # print_console(err) err=traceback.format_exc() print_console(err) #print_console("Sending bug to bugmail") #ARGS.log_file.flush() #ARGS.log_file.close() #from bugmail import send_bug #send_bug() JOptionPane.showMessageDialog(None,"Installation failed, please try again and submit install log as a bug report.") finally: print_console("Installation finished") shutdown()
def run_main(cwd): print_label("Running getbirch installer process") if (ARGS.is_update): print_console("Updating an existing BIRCH installation") ARGS.set_installdir(cwd) if "winxp-32" in ARGS.platform: print_console("This is a windows install") has_depends=True else: has_depends=check_depends() if (not has_depends): print_console("A required dependancy is not present on system path, BIRCH cannot be installed") shutdown() if (not ARGS.is_update): clobber_check() if (os.path.lexists(ARGS.install_dir)): os.chdir(ARGS.install_dir) fetch = True if (ARGS.disc_install): disc_prepare() fetch = False
def extract_tarballs(windows=False): def extract_binary(binary): if (os.path.lexists(ARGS.install_dir +"/"+binary+ ".tar.gz")): if (windows): cygwin_untar(ARGS.install_dir +"/"+binary+ ".tar.gz",binary+ ".tar.gz") else: untar(binary+ ".tar.gz") else: print_console( "The required file "+binary+ ".tar.gz was not found") print_console( "Decompressing framework...") os.chdir(ARGS.install_dir) if (os.path.lexists(ARGS.install_dir + "/framework.tar.gz")): if (windows and not ARGS.isGitDev): cygwin_untar(ARGS.install_dir + "/framework.tar.gz","framework.tar.gz") elif(not ARGS.isGitDev): untar("framework.tar.gz") elif (ARGS.isGitDev): if (windows): cygwin_untar(ARGS.install_dir + "/framework.tar.gz","framework.tar.gz",noroot=True) else: excludelist=list() if (ARGS.is_update): exclude.append("local") untar("framework.tar.gz",path=".",noroot=True,exclude=excludelist) #print_console("Restoring permission/time data.") #restoreMetaData(ARGS.install_dir) #print_console("Metadata restored.") else: print_console( "The required file framework.tar.gz was not found") return print_console( "Decompressing binaries...") if (not ARGS.multi_bins): extract_binary(ARGS.platform) else: for each in ARGS.platforms: extract_binary(each)
def disc_prepare(): binaries= tarfile.open(ARGS.top_dir+"/binaries.tar.gz") def untar_binary_tar(name): print_console("Extracting "+name+ " to "+ARGS.install_dir+"/"+name) binaries.extract(name,ARGS.install_dir) print_console("This is a disc install, must decompress binaries to install directory") print_console("Copying framework to installation directory...") shutil.copy(ARGS.top_dir+"/framework.tar.gz", ARGS.install_dir) print_console("Copying binaries to installation directory...") for each in ARGS.platforms: untar_binary_tar(each+".tar.gz")
def set_birch_home(files,home): if (home[len(home)-1]=="/"): home=home[0:len(home)-1] print_console("Using "+home+" as home directory for replacement") for each in files: each=each.replace("$BIRCH",home) if (os.path.lexists(each)): print_console("Setting location of BIRCH home directory as "+home+" in "+each) #replace all $BIRCH tags with the actual path to $BIRCH replace_all(each, "$BIRCH/",home+"/")#note that the slash is necessary because of vars like $BIRCH_DEBUG replace_all(each, "$BIRCH ",home)#note that the space is necessary #replace /home/psgendb tags with home replace_all(each,REPLACEKEY,home) else: print_console("The path "+each+" does not exist")
def check_directory(path): if (os.path.lexists(path)): contents=os.listdir(path) if (contents.count("install-birch")==0): print_console("The selected directory "+path+" does NOT contain a BIRCH installation!") message="The selected path does NOT contain a BIRCH installation.\nPlease select the base directory of the installation that you wish to update,\nOr click \"no\" to cancel update." reload = JOptionPane.showConfirmDialog(None,message, "Input",JOptionPane.YES_NO_OPTION); if (reload==JOptionPane.NO_OPTION): print_console("User aborted install.") commonlib.shutdown() fc = JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.showOpenDialog(None); path = fc.getSelectedFile().getPath(); check_directory(path) else: ARGS.install_dir=path print_console("The selected directory "+path+" contains a BIRCH installation, it will be updated")
def get_framework(): url=None os.chdir(ARGS.install_dir) if(ARGS.isGitDev): ARGS.GITDEV_HASHMAP["h"]=ARGS.selectedTag[1] params=urllib.urlencode(ARGS.GITDEV_HASHMAP) ARGS.FRAMEWORK_URL=ARGS.GITDEV_URL+"%s"%params url=ARGS.FRAMEWORK_URL print_console("Using Git: Downloading development framework to " + ARGS.install_dir + " from " + url) print_console("Please wait... a fresh archive is being cooked up...") else: if (not ARGS.is_mini and not ARGS.is_development): url=ARGS.FRAMEWORK_URL url=url.replace("$TYPE",ARGS.NEWEST_VERSION) print_console( "Downloading birch framework to " + ARGS.install_dir + " from " + url) elif (not ARGS.is_development and ARGS.is_mini): url=ARGS.MINI_URL url=url.replace("$TYPE",ARGS.NEWEST_VERSION) print_console( "Downloading miniBirch framework to " + ARGS.install_dir + " from " + url) elif(ARGS.is_development and not ARGS.is_mini): url=ARGS.FRAMEWORK_URL url=url.replace("$TYPE","D") url=url.replace("CURRENT","Development") print_console( "Downloading development framework to " + ARGS.install_dir + " from " + url) elif(ARGS.is_development and ARGS.is_mini): url=ARGS.MINI_URL url=url.replace("$TYPE","D") url=url.replace("CURRENT","Development") print_console( "Downloading miniBirch development framework to " + ARGS.install_dir + " from " + url) wget(url, "framework.tar.gz",CONSOLE)
def untar_binary_tar(name): print_console("Extracting "+name+ " to "+ARGS.install_dir+"/"+name) binaries.extract(name,ARGS.install_dir)
def compress_old_birch(): print_label("Archiving old BIRCH") filename="birch_backup"+str(datetime.datetime.now()).replace(" ","")+".tar" filename=filename.replace(":","") filename=filename.replace("-","") print_console("Saving old BIRCH in "+filename) tar = tarfile.open(filename, "w") os.chdir(ARGS.install_dir) for each in birch_files: if (os.path.lexists(ARGS.install_dir+"/"+each)): print_console("Archiving old birch directory "+ each) try: tar.add(each) except IOError: print_console("Could not add file: \""+each+"\" to archive:") ioerr=traceback.format_exc() print_console(str(ioerr)) message="An IO error occurred, the file \""+each+"\"could not be added to the archive, do you still wish to proceed?" cont=JOptionPane.showConfirmDialog(None,message, "Input",JOptionPane.YES_NO_OPTION); if (cont==JOptionPane.NO_OPTION): print_console("User aborted installation") JOptionPane.showMessageDialog("It is recommended that you archive manually archive your previous BIRCH installation before you proceed with the update.") commonlib.shutdown() except: err=traceback.format_exc() print_console(err) print_console("Unhandled exception occurred, this is a bug. For safety reasons, the update has been aborted") JOptionPane.showMessageDialog(None,"Unhandled exception occurred, this is a bug. For safety reasons, the update has been aborted") commonlib.shutdown() tar.close()
def set_db_id(home,original): print_console("Setting values for acedb") db_file=home+"/public_html/birchdb/wspec/passwd.wrm" replace_all(db_file,original,USER) os.popen("chmod a+r "+db_file)
def run_uninstall(directory=None,quiet=False): answer =None if (("-Q" in sys.argv) or quiet): print_console("Running in quiet mode") answer='y' else: print_console (">>> You are about remove access to the BIRCH system for this account!") while (answer != "y" and answer !="n"): answer = raw_input(">>> Type y to continue, n to exit\n") if (answer=="n"): print_console("User cancelled operation.") exit() if(directory==None): os.system("python $BIRCH/admin/rmlauncher.py") directory="$BIRCH" elif(os.path.lexists(directory)): os.system("python "+directory+"/script/rmlauncher.py") os.chdir(os.getenv('HOME')) for file in FILE_LIST: remove_birch(os.getenv('HOME')+"/"+file) print_console("Done!") print_console("Logout and login again so that the changes can take effect.") print_console("If you wish to restore BIRCH access, type") print_console(directory+"/admin/newuser")
def compress_old_birch(): print_label("Archiving old BIRCH") filename = "birch_backup" + str(datetime.datetime.now()).replace( " ", "") + ".tar" filename = filename.replace(":", "") filename = filename.replace("-", "") print_console("Saving old BIRCH in " + filename) tar = tarfile.open(filename, "w") os.chdir(ARGS.install_dir) for each in birch_files: if (os.path.lexists(ARGS.install_dir + "/" + each)): print_console("Archiving old birch directory " + each) try: tar.add(each) except IOError: print_console("Could not add file: \"" + each + "\" to archive:") ioerr = traceback.format_exc() print_console(str(ioerr)) message = "An IO error occurred, the file \"" + each + "\"could not be added to the archive, do you still wish to proceed?" cont = JOptionPane.showConfirmDialog(None, message, "Input", JOptionPane.YES_NO_OPTION) if (cont == JOptionPane.NO_OPTION): print_console("User aborted installation") JOptionPane.showMessageDialog( "It is recommended that you archive manually archive your previous BIRCH installation before you proceed with the update." ) commonlib.shutdown() except: err = traceback.format_exc() print_console(err) print_console( "Unhandled exception occurred, this is a bug. For safety reasons, the update has been aborted" ) JOptionPane.showMessageDialog( None, "Unhandled exception occurred, this is a bug. For safety reasons, the update has been aborted" ) commonlib.shutdown() tar.close()