def compile_dir_and_recurse(dir,level,force): global debug global verbosity global errors_are_fatal pid = os.getpid() os.chdir(dir) if force: if verbosity[pid] > 1: v = 'v' else: v = '' os.system("rm -%sf *.so *.o *.pyc" % v) flist = os.listdir('.') if 'compile' in flist: os.system(os.path.realpath('./compile'), errors_are_fatal=errors_are_fatal[pid], verbosity=verbosity[pid], debug=debug[pid]) for f in flist: pathname = os.path.join(dir,f) if f in ('CVS', 'penvironment.d'): continue try: mode = os.stat(pathname)[ST_MODE] if S_ISDIR(mode) and f[0] != '.': compile_dir_and_recurse(pathname,level+1,force) os.chdir(dir) except OSError, e: if verbosity[pid] > 1: print "WARNING: Skipping", pathname, "due to", e
def _update_mpx_python_lib(self): # Ensure the target directory exists. makedirs(MPX_PYTHON_LIB) keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 # # # Install mpxconfig, mpxupgrade and associated libraries. # @fixme Consolodate /usr/lib/mpx/python, site-packages and the # minimal moab... self.cwd.pushd('lib') for module in LIB_MODULES: os.system('rm -f %s/%s.py*' % (MPX_PYTHON_LIB, module), **keywords) file = InstallFile(self.options, module + ".pyc") # !read_only (copy) file.relocate(MPX_PYTHON_LIB) file.chmod(0664) continue self.cwd.popd() self.cwd.pushd('bin') for module in BIN_MODULES: os.system('rm -f %s/%s.py*' % (MPX_PYTHON_LIB, module), **keywords) file = InstallFile(self.options, module + ".pyc") file.relocate(MPX_PYTHON_LIB) file.chmod(0664) continue self.cwd.popd() return
def _update_mpx_python_lib(self): # Ensure the target directory exists. makedirs(MPX_PYTHON_LIB) keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 # # # Install mpxconfig, mpxupgrade and associated libraries. # @fixme Consolodate /usr/lib/mpx/python, site-packages and the # minimal moab... self.cwd.pushd("lib") for module in LIB_MODULES: os.system("rm -f %s/%s.py*" % (MPX_PYTHON_LIB, module), **keywords) file = InstallFile(self.options, module + ".pyc") # !read_only (copy) file.relocate(MPX_PYTHON_LIB) file.chmod(0664) continue self.cwd.popd() self.cwd.pushd("bin") for module in BIN_MODULES: os.system("rm -f %s/%s.py*" % (MPX_PYTHON_LIB, module), **keywords) file = InstallFile(self.options, module + ".pyc") file.relocate(MPX_PYTHON_LIB) file.chmod(0664) continue self.cwd.popd() return
def _force_target_directory(self, directory): makedirs(directory) chown(directory, "root", "mpxadmin", ignore_errors=1) keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 0 os.system("chmod 0770 %s" % (directory, ), **keywords) return
def _force_target_directory(self, directory): makedirs(directory) chown(directory, "root", "mpxadmin", ignore_errors=1) keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 0 os.system("chmod 0770 %s" % (directory,), **keywords) return
def install(self): # # Note: Unfortunately the following two import statements have # the side-effect of trying to create a directory under # /var/mpx. This isn't necessary when just trying to # query this install script and in fact fails in some # cases, so the imports were moved from the top of this # script to here. # from moab.linux.lib.servicemgr import InittabManager from moab.linux.lib.servicemgr import InittabGroup chown(ROOT, MPX_UID, MPX_GID, recurse=1, ignore_errors=1) keywords = {} keywords.update(self.keywords) keywords.update({'ROOT':DUP_DIR}) keywords[CommandKeywords.FATAL_KEY] = 1 # Duplicate the config service so it will work after /usr/lib/broadway # is nuked. makedirs(DUP_DIR) os.system("cp *.pyc %s" % DUP_DIR, **keywords) chown(DUP_DIR, MPX_UID, MPX_GID, recurse=1, ignore_errors=1) os.system("chmod -R %o %s/*" % (0664, DUP_DIR), **keywords) # Create the config_service's custom launcher. create_pyscript(CONFIG_SCRIPT, CONFIG_PYC, **keywords) # Update inittab to include the new config service. inittab = InittabManager(**keywords) gname = 'MEDIATOR_CONFIGURATION_SERVICE' # Remove any existing mpx_igmp entry. for group in inittab.group_list: lines = group.text.split('\n') found = 0 for i in range(0, len(lines)): line = lines[i] if line and line[0] != '#' and line.find('mpx_igmp') != -1: lines[i] = "# %s # - %s" % (line, gname) found = 1 if found: text = lines.pop(0) for line in lines: text = "%s\n%s" % (text, line) group.text = text # Add the Mediator Configuration Service. mcs = inittab.findgroup(gname) text = 'MCS:2345:respawn:%s' % CONFIG_SCRIPT if mcs is None: inittab.addgroup(InittabGroup(gname, text)) else: mcs.text = text inittab.commit() return 0
def _update_bin(self): # Ensure the target directory exists. makedirs(BIN_DIR) self.cwd.pushd('bin') blinky_bill = 'blinky_bill' wdt = 'wdt' bin_list = ('watchdog', ) keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 if os.path.exists(os.path.join(TARGET_ROOT, 'proc/mediator/sig')): # Only copy blinky_bill and wdt if /proc/mediator/pattern exists. bin_list += (blinky_bill, wdt) else: os.system( 'rm -f %s' % os.path.join(BIN_DIR, os.path.basename(blinky_bill)), **keywords) os.system( 'rm -f %s' % os.path.join(BIN_DIR, os.path.basename(wdt)), **keywords) for executable_source in bin_list: executable_target = os.path.join( BIN_DIR, os.path.basename(executable_source)) # Copy the executable to the BIN_DIR. os.system('rm -f %s' % executable_target, **keywords) file = InstallFile(self.options, executable_source) #!read_only file.relocate(BIN_DIR) file.chmod(0775) # Force a specific environment. keywords = {} keywords['ENV'] = properties.as_environment() # @fixme mpxconfig uses tools.lib, which should probably be cloned # somewhere. keywords['ENV']['PYTHONPATH'] = '%s:%s' % (MPX_PYTHON_LIB, ROOT) create_pyscript(MPXCONFIG_SCRIPT, MPXCONFIG_PYC, **keywords) create_pyscript(MPXUPGRADE_SCRIPT, MPXUPGRADE_PYC, **keywords) create_pyscript(IPCHECK_SCRIPT, IPCHECK_PYC, **keywords) # @fixme This could be much cleaner. # Delete versions of old executables in incorrect places. correct_dir = os.path.realpath(BIN_DIR) for old_dir in (os.path.join(TARGET_ROOT, 'bin'), os.path.join(TARGET_ROOT, 'sbin'), os.path.join(TARGET_ROOT, 'usr/bin'), os.path.join(TARGET_ROOT, 'usr/sbin')): old_dir = os.path.realpath(old_dir) if old_dir == correct_dir: # If old_dir == correct_dir, then old_dir 'taint so # old... continue for basename in ('watchdog', 'blinky_bill', 'mpxconfig', 'mpxupgrade', 'ipcheck'): old_file = os.path.join(old_dir, basename) if os.path.exists(old_file): keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 os.system('rm -f %s' % old_file, **keywords) self.cwd.popd() return
def _install_webapi_dir(self,root): webapi_path = os.path.join(root,'webapi') # Ensure that webapi is empty (by deleting it). os.system("rm -rf %s" % (webapi_path,), **self._fatal_keywords()) # Ensure that the root directory exists. makedirs(root) # Copy over the latest webapi with all files as hard links # to avoid wasting space # - not that this makes the assumption that nothing in the # webapi directory is modified by the user - because if it # is this code will break the design goal of having the # install process restore every thing to a known state os.system("cp -r --link client %s" % (webapi_path,),**self.keywords) return
def _update_sbin(self): # Ensure the target directory exists. real_sbin_dir = os.path.join(TARGET_ROOT, 'sbin') makedirs(real_sbin_dir) self.cwd.pushd('bin') keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 for executable in ['hotplug']: # Copy the executable to the real sbin directory. os.system('rm -f %s/%s' % (real_sbin_dir, executable), **keywords) file = InstallFile(self.options, executable) #!read_only file.relocate(real_sbin_dir) file.chmod(0775) self.cwd.popd() return
def _update_webdev_files(self): bin_dir = os.path.join(properties.WWW_ROOT,'bin') etc_dir = os.path.join(properties.WWW_ROOT,'etc') for dir in (bin_dir, etc_dir): makedirs(dir) self.cwd.pushd(bin_dir) for file in ('gzip','ls','tar'): source = os.path.join('/bin',file) target = os.path.join(bin_dir,file) os.system("rm -f %s && ln -s %s %s" % (target,source,target), **self._fatal_keywords()) self.cwd.popd() self.cwd.pushd(etc_dir) self.cwd.popd() return
def _update_sbin(self): # Ensure the target directory exists. real_sbin_dir = os.path.join(TARGET_ROOT, "sbin") makedirs(real_sbin_dir) self.cwd.pushd("bin") keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 for executable in ["hotplug"]: # Copy the executable to the real sbin directory. os.system("rm -f %s/%s" % (real_sbin_dir, executable), **keywords) file = InstallFile(self.options, executable) #!read_only file.relocate(real_sbin_dir) file.chmod(0775) self.cwd.popd() return
def _update_bin(self): # Ensure the target directory exists. makedirs(BIN_DIR) self.cwd.pushd("bin") blinky_bill = "blinky_bill" wdt = "wdt" bin_list = ("watchdog",) keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 if os.path.exists(os.path.join(TARGET_ROOT, "proc/mediator/sig")): # Only copy blinky_bill and wdt if /proc/mediator/pattern exists. bin_list += (blinky_bill, wdt) else: os.system("rm -f %s" % os.path.join(BIN_DIR, os.path.basename(blinky_bill)), **keywords) os.system("rm -f %s" % os.path.join(BIN_DIR, os.path.basename(wdt)), **keywords) for executable_source in bin_list: executable_target = os.path.join(BIN_DIR, os.path.basename(executable_source)) # Copy the executable to the BIN_DIR. os.system("rm -f %s" % executable_target, **keywords) file = InstallFile(self.options, executable_source) #!read_only file.relocate(BIN_DIR) file.chmod(0775) # Force a specific environment. keywords = {} keywords["ENV"] = properties.as_environment() # @fixme mpxconfig uses tools.lib, which should probably be cloned # somewhere. keywords["ENV"]["PYTHONPATH"] = "%s:%s" % (MPX_PYTHON_LIB, ROOT) create_pyscript(MPXCONFIG_SCRIPT, MPXCONFIG_PYC, **keywords) create_pyscript(MPXUPGRADE_SCRIPT, MPXUPGRADE_PYC, **keywords) create_pyscript(IPCHECK_SCRIPT, IPCHECK_PYC, **keywords) # @fixme This could be much cleaner. # Delete versions of old executables in incorrect places. correct_dir = os.path.realpath(BIN_DIR) for old_dir in ( os.path.join(TARGET_ROOT, "bin"), os.path.join(TARGET_ROOT, "sbin"), os.path.join(TARGET_ROOT, "usr/bin"), os.path.join(TARGET_ROOT, "usr/sbin"), ): old_dir = os.path.realpath(old_dir) if old_dir == correct_dir: # If old_dir == correct_dir, then old_dir 'taint so # old... continue for basename in ("watchdog", "blinky_bill", "mpxconfig", "mpxupgrade", "ipcheck"): old_file = os.path.join(old_dir, basename) if os.path.exists(old_file): keywords = {} keywords.update(self.keywords) keywords[CommandKeywords.FATAL_KEY] = 1 os.system("rm -f %s" % old_file, **keywords) self.cwd.popd() return
def _update_mpxadmin_user(self): # # Ensure the mpxadmin group exists. # passwd = PasswdFile() passwd.load() group = GroupFile() group.load() self.options.normal_message("Checking for mpxadmin group.") if "mpxadmin" not in group: self.options.normal_message("No mpxadmin group, adding.") mpxadmin = GroupEntry() mpxadmin.group("mpxadmin") mpxadmin.crypt("*") mpxadmin.gid(int(MPX_GID)) mpxadmin.user_list((mpxadmin.group(), )) group[mpxadmin.group()] = mpxadmin group.save() self.options.normal_message("Added mpxadmin group(%d) in %s.", mpxadmin.gid(), group._file) else: self.options.normal_message("mpxadmin group already exists.") if int(MPX_GID): # Installing as regular user, presumably in penvironment.d, add # the required "root" group. self.options.normal_message("Checking for root group.") if "root" not in group: self.options.normal_message("No root group, adding.") root = GroupEntry() root.group("root") root.crypt("*") root.gid(int(MPX_GID)) root.user_list((root.group(), )) group[root.group()] = root group.save() self.options.normal_message("Added root group(%d) in %s.", root.gid(), group._file) else: self.options.normal_message("root group already exists.") # # Ensure the mpxadmin user exists. # self.options.normal_message("Checking for mpxadmin user.") #if "mpxadmin" not in passwd: # if there is no mpxadmin type user, create a default if len(filter(lambda pw: pw.user_type() == 'mpxadmin', passwd)) == 0: self.options.normal_message( "No mpxadmin user, checking for mpxadmin group.") gid = group["mpxadmin"].gid() # @fixme This is not pretty, but it will work for now. # A new UID would be uid = passwd.new_uid(gid-1) uid = int(MPX_UID) # Hijacking root for superuser privelidges... mpxadmin = PasswdEntry() mpxadmin.user("mpxadmin") mpxadmin.directory(passwd.default_home(mpxadmin.user())) mpxadmin.crypt(_crypted_password("mpxadmin", "mpxadmin")) mpxadmin.uid(uid) mpxadmin.gid(gid) # @fixme Formalize the Mediator concept of meta-data associated # with users. Also consider moving the meta-data out of # /etc/passwd and into a PDO... # META-DATA: # AKA: Allows us to track renames of key users (pppuser, # mpxadmin, webdev, ...) # CSIK: Configuration Service Initial Key (used to calculate # "classic" Configuration Service Security Keys. mpxadmin.gecos("AKA=mpxadmin,CSIK=%s,ROLE=administrator" % (_csiked_password("mpxadmin"), )) mpxadmin.shell("/bin/bash") passwd[mpxadmin.user()] = mpxadmin passwd.save() self.options.normal_message("Added mpxadmin user(%d.%d) in %s.", mpxadmin.uid(), mpxadmin.gid(), passwd._file) # Create and update the mpxadmin user. self._force_target_directory(mpxadmin.directory()) self.cwd.pushd(mpxadmin.directory()) passwd = PasswdFile() passwd.load() group = GroupFile() group.load() os.system("chmod -R ug+Xrw .", **self._fatal_keywords()) chown(".", "mpxadmin", "mpxadmin", recurse=1, ignore_errors=1) self.cwd.popd() else: self.options.normal_message("mpxadmin user already exists.") # # Ensure mpxadmin is a member of the root group. # group = GroupFile() group.load() root = group["root"] user_list = root.user_list() if "mpxadmin" not in user_list: self.options.normal_message( "Adding mpxadmin user to the root group.") user_list.append("mpxadmin") root.user_list(user_list) group["root"] = root group.save() return
def _update_webdev_home(self): self.cwd.pushd(properties.WWW_ROOT) chown(".", "webdev", "webdev", recurse=1, ignore_errors=1, followslinks=0) os.system("chmod -R ug+Xrw . *", **self.keywords) self.cwd.popd() return
def _update_mpxadmin_user(self): # # Ensure the mpxadmin group exists. # passwd = PasswdFile() passwd.load() group = GroupFile() group.load() self.options.normal_message("Checking for mpxadmin group.") if "mpxadmin" not in group: self.options.normal_message("No mpxadmin group, adding.") mpxadmin = GroupEntry() mpxadmin.group("mpxadmin") mpxadmin.crypt("*") mpxadmin.gid(int(MPX_GID)) mpxadmin.user_list((mpxadmin.group(),)) group[mpxadmin.group()] = mpxadmin group.save() self.options.normal_message("Added mpxadmin group(%d) in %s.", mpxadmin.gid(), group._file) else: self.options.normal_message("mpxadmin group already exists.") if int(MPX_GID): # Installing as regular user, presumably in penvironment.d, add # the required "root" group. self.options.normal_message("Checking for root group.") if "root" not in group: self.options.normal_message("No root group, adding.") root = GroupEntry() root.group("root") root.crypt("*") root.gid(int(MPX_GID)) root.user_list((root.group(),)) group[root.group()] = root group.save() self.options.normal_message("Added root group(%d) in %s.", root.gid(), group._file) else: self.options.normal_message("root group already exists.") # # Ensure the mpxadmin user exists. # self.options.normal_message("Checking for mpxadmin user.") # if "mpxadmin" not in passwd: # if there is no mpxadmin type user, create a default if len(filter(lambda pw: pw.user_type() == "mpxadmin", passwd)) == 0: self.options.normal_message("No mpxadmin user, checking for mpxadmin group.") gid = group["mpxadmin"].gid() # @fixme This is not pretty, but it will work for now. # A new UID would be uid = passwd.new_uid(gid-1) uid = int(MPX_UID) # Hijacking root for superuser privelidges... mpxadmin = PasswdEntry() mpxadmin.user("mpxadmin") mpxadmin.directory(passwd.default_home(mpxadmin.user())) mpxadmin.crypt(_crypted_password("mpxadmin", "mpxadmin")) mpxadmin.uid(uid) mpxadmin.gid(gid) # @fixme Formalize the Mediator concept of meta-data associated # with users. Also consider moving the meta-data out of # /etc/passwd and into a PDO... # META-DATA: # AKA: Allows us to track renames of key users (pppuser, # mpxadmin, webdev, ...) # CSIK: Configuration Service Initial Key (used to calculate # "classic" Configuration Service Security Keys. mpxadmin.gecos("AKA=mpxadmin,CSIK=%s,ROLE=administrator" % (_csiked_password("mpxadmin"),)) mpxadmin.shell("/bin/bash") passwd[mpxadmin.user()] = mpxadmin passwd.save() self.options.normal_message( "Added mpxadmin user(%d.%d) in %s.", mpxadmin.uid(), mpxadmin.gid(), passwd._file ) # Create and update the mpxadmin user. self._force_target_directory(mpxadmin.directory()) self.cwd.pushd(mpxadmin.directory()) passwd = PasswdFile() passwd.load() group = GroupFile() group.load() os.system("chmod -R ug+Xrw .", **self._fatal_keywords()) chown(".", "mpxadmin", "mpxadmin", recurse=1, ignore_errors=1) self.cwd.popd() else: self.options.normal_message("mpxadmin user already exists.") # # Ensure mpxadmin is a member of the root group. # group = GroupFile() group.load() root = group["root"] user_list = root.user_list() if "mpxadmin" not in user_list: self.options.normal_message("Adding mpxadmin user to the root group.") user_list.append("mpxadmin") root.user_list(user_list) group["root"] = root group.save() return