def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=" updates python-%s, python3-~ on all hosts from the repo" % (PACKET_NAME)) parser.add_argument( '-x', dest="execute", action="store_true", default=False, help='update python-%s, python3-~ on all nodes, from repo' % (PACKET_NAME)) parser.add_argument('-r', dest="updateRepo", action="store_true", default=False, help='update repo first') args = parser.parse_args() if not args.execute: parser.print_help() return if args.updateRepo: if os.system("./UpdateDebianRepo.py -x"): print "Failed to update the debian repo" return nodes = HasyUtils.readHostList(HOST_LIST) sz = len(nodes) count = 1 countFailed = 0 countOffline = 0 for host in nodes: if not HasyUtils.checkHostRootLogin(host): print "-- checkHostRootLogin returned error %s" % host countOffline += 1 continue cmd = 'ssh -l root %s "apt-get update && apt -y install python-%s && apt install -y python3-%s && dpkg -s python-%s && dpkg -s python3-%s && echo "" > /dev/null 2>&1"' % ( host, PACKET_NAME, PACKET_NAME, PACKET_NAME, PACKET_NAME) # print( "%s" % cmd) if os.system(cmd): print "Failed to update %s" % host countFailed += 1 continue else: print("Updated %s OK" % host) print "\nDoAll: %d/%d (offline %d, failed %d) %s \n" % ( count, sz, countOffline, countFailed, host) count += 1 return
def main(): DIR_NAME = os.getenv("PWD").split("/")[-1] if DIR_NAME == 'hasyutils': PACKET_NAME = "hasyutils" elif DIR_NAME == 'pySpectra': PACKET_NAME = "pyspectra" elif DIR_NAME == 'tngGui': PACKET_NAME = "tnggui" else: print("DisplayVersion.py: failed to identify %s" % DIR_NAME) sys.exit(255) ROOT_DIR = "/home/kracht/Misc/%s" % DIR_NAME nodes = HasyUtils.readHostList(HOST_LIST) sz = len(nodes) count = 1 for host in nodes: if not HasyUtils.checkHostRootLogin(host): print "-- checkHostRootLogin returned error %s" % host continue ret = os.popen("ssh root@%s \"dpkg -l python-%s 2>/dev/null\"" % (host, PACKET_NAME)).read() lst = ret.split('\n') for line in lst: if line.find("python-%s" % PACKET_NAME) > 0: lst1 = line.split() print "%d/%d: %s, python-%s %s" % (count, sz, host, PACKET_NAME, lst1[2]) ret = os.popen("ssh root@%s \"dpkg -l python3-%s 2>/dev/null\"" % (host, PACKET_NAME)).read() lst = ret.split('\n') for line in lst: if line.find("python3-%s" % PACKET_NAME) > 0: lst1 = line.split() print "%d/%d: %s, python3-%s %s" % (count, sz, host, PACKET_NAME, lst1[2]) count += 1 return
def main(): parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, usage='%(prog)s [options]', description="Install %s debian package on some host" % PACKET_NAME) parser.add_argument('hostName', nargs=1, default='None', help='hostname where the package is to be installed') args = parser.parse_args() if args.hostName == "None": print("DoDebianInstall.py: specify hostname") sys.exit(255) if len(args.hostName) != 1: print("DoDebianInstall.py: specify ONE host") sys.exit(255) host = args.hostName[0] print(">>> DoDebianInstall.py %s" % (host)) os.chdir(ROOT_DIR) if not HasyUtils.checkHostOnline(host): print("DoDebinaInstall.py: %s is not online " % host) sys.exit(255) if not HasyUtils.checkHostRootLogin(host): print("DoDebinaInstall.py: %s no root login " % host) sys.exit(255) # # read the version # handleVers = handleVersion.handleVersion(ROOT_DIR) version = handleVers.findVersion() argout = os.popen('ssh root@%s "uname -v"' % host).read() argout = argout.strip() if argout.find('Debian') == -1: print("DoDebinaInstall.py: %s does not run Debian " % host) sys.exit(255) debName3 = "python3-%s_%s_all.deb" % (PACKET_NAME, version) debName = "python-%s_%s_all.deb" % (PACKET_NAME, version) # # copy the package to the install host # if os.system("scp ./DebianPackages/%s root@%s:/tmp" % (debName, host)): print("trouble copying the package to %s" % host) sys.exit(255) if os.system("scp ./DebianPackages/%s root@%s:/tmp" % (debName3, host)): print("trouble copying the package to %s" % host) sys.exit(255) # # remove the existing package, may not exist on the host # if os.system('ssh -l root %s "dpkg -r python-%s > /dev/null 2>&1"' % (host, PACKET_NAME)): pass if os.system('ssh -l root %s "dpkg -r python3-%s > /dev/null 2>&1"' % (host, PACKET_NAME)): pass # # install the new package # if os.system('ssh -l root %s "dpkg -i /tmp/%s"' % (host, debName)): print("trouble installing the package on %s" % host) sys.exit(255) if os.system('ssh -l root %s "dpkg -i /tmp/%s"' % (host, debName3)): print("trouble installing the package on %s" % host) sys.exit(255) # # delete the deb file # if os.system('ssh -l root %s "/bin/rm /tmp/%s"' % (host, debName)): print("trouble removing deb file on %s" % host) sys.exit(255) if os.system('ssh -l root %s "/bin/rm /tmp/%s"' % (host, debName3)): print("trouble removing deb file on %s" % host) sys.exit(255) print(">>> DoDebianInstall.py %s DONE" % host) return