def _checkout(self, arg): orig_cwd = os.getcwd() os.chdir(self.git.path) try: system("sumo-checkout", arg) finally: os.chdir(orig_cwd)
def cpp(input, cpp_opts=[]): """preprocess <input> through cpp -> preprocessed output input may be path/to/file or iterable data type """ args = ["-Ulinux"] for opt, val in cpp_opts: args.append(opt + val) include_path = os.environ.get('FAB_PLAN_INCLUDE_PATH') if include_path: for path in include_path.split(':'): args.append("-I" + path) command = ["cpp", input] if args: command += args trap = stdtrap.StdTrap() try: executil.system(*command) except ExecError, e: trap.close() trapped_stderr = trap.stderr.read() raise ExecError(" ".join(command), e.exitcode, trapped_stderr)
def index(self, component, arch): component_dir = join(self.pool, component) if not exists(join(self.path, component_dir)): raise Error('component does not exist', join(self.path, component_dir)) output_dir = '%s/dists/%s/%s/binary-%s' % (self.path, self.release, component, arch) if not exists(output_dir): os.makedirs(output_dir) output = self._archive_cmd('--arch=%s packages' % arch, component_dir) fh = file(join(output_dir, 'Packages'), "w") fh.write(output) if output: # append newline if packages were in pool print >> fh fh.close() executil.system( "gzip -c %s > %s" % (join(output_dir, 'Packages'), join(output_dir, 'Packages.gz'))) executil.system( "bzip2 -c %s > %s" % (join(output_dir, 'Packages'), join(output_dir, 'Packages.bz2'))) fh = file(join(output_dir, 'Release'), "w") print >> fh, "Origin: %s" % self.origin print >> fh, "Label: %s" % self.origin print >> fh, "Archive: %s" % self.release print >> fh, "Version: %s" % self.version print >> fh, "Component: %s" % component print >> fh, "Architecture: %s" % arch fh.close()
def _amitools_cmd(command, opts): amitools_path = _get_amitools_path() os.environ["EC2_AMITOOL_HOME"] = amitools_path log.debug("amitools_cmd - %s %s", command, opts) cmd = os.path.join(amitools_path, 'bin', command) executil.system(cmd, *opts)
def update(section, name, value): config_path = "/var/www/piwik/config/config.ini.php" if not os.path.exists(config_path): raise Error("config file does not exist: %s" % config_path) config_new = [] in_section = False seen = False for line in file(config_path).readlines(): line = line.rstrip() if line.startswith("["): if line == section: in_section = True else: in_section = False if in_section and line.startswith("%s =" % name) and seen == False: line = "%s = \"%s\"" % (name, value) seen = True config_new.append(line) # write out updated config file(config_path, "w").write("\n".join(config_new) + "\n") # set ownership and permissions system("chown www-data:www-data %s" % config_path) system("chmod 640 %s" % config_path)
def _is_alive(self): try: system('mysqladmin -s ping >/dev/null 2>&1') except ExecError: return False return True
def get(url, dest): """Get file from <url> and save it to <dest>. Tries to retrieve <url> from cache, otherwise stores it in cache following retrieval. """ url = urllib.unquote(url) if url.endswith("/"): raise Error("illegal url - can't get a directory") if os.path.isdir(dest): dest = os.path.join(dest, os.path.basename(url)) else: if dest.endswith("/"): raise Error("no such directory: " + dest) if os.path.lexists(dest): raise Error("won't overwrite already existing file: " + dest) cache = Cache() cached_path = cache.retrieve(url, dest) if cached_path: print "* get: retrieved file from cache" else: print "* get: retrieving file from network..." system("curl -L -f %s -o %s" % (mkarg(url), mkarg(dest))) cached_path = cache.store(url, dest) return cached_path
def ebsmount_add(devname, mountdir): """ebs device attached""" matching_devices = [] for device in udevdb.query(): if device.name.startswith(basename(devname)): matching_devices.append(device) for device in matching_devices: devpath = join('/dev', device.name) mountpath = join(mountdir, device.env.get('ID_FS_UUID', devpath[-1])[:4]) mountoptions = ",".join(config.mountoptions.split()) scriptpath = join(mountpath, ".ebsmount") filesystem = device.env.get('ID_FS_TYPE', None) if not filesystem: log(devname, "could not identify filesystem: %s" % devpath) continue if not filesystem in config.filesystems.split(): log(devname, "filesystem (%s) not supported: %s" % (filesystem,devpath)) continue if is_mounted(devpath): log(devname, "already mounted: %s" % devpath) continue mount(devpath, mountpath, mountoptions) log(devname, "mounted %s %s (%s)" % (devpath, mountpath, mountoptions)) if exists(scriptpath): cmd = "run-parts --verbose --exit-on-error %s" % scriptpath cmd += " 2>&1 | tee -a %s" % config.logfile system(cmd)
def index(self, component, arch): component_dir = join(self.pool, component) if not exists(join(self.path, component_dir)): raise Error('component does not exist', join(self.path, component_dir)) output_dir = '%s/dists/%s/%s/binary-%s' % (self.path, self.release, component, arch) if not exists(output_dir): os.makedirs(output_dir) output = self._archive_cmd('--arch=%s packages' % arch, component_dir) fh = file(join(output_dir, 'Packages'), "w") fh.write(output) if output: # append newline if packages were in pool print >> fh fh.close() executil.system("gzip -c %s > %s" % (join(output_dir, 'Packages'), join(output_dir, 'Packages.gz'))) executil.system("bzip2 -c %s > %s" % (join(output_dir, 'Packages'), join(output_dir, 'Packages.bz2'))) fh = file(join(output_dir, 'Release'), "w") print >> fh, "Origin: %s" % self.origin print >> fh, "Label: %s" % self.origin print >> fh, "Archive: %s" % self.release print >> fh, "Version: %s" % self.version print >> fh, "Component: %s" % component print >> fh, "Architecture: %s" % arch fh.close()
def cpp(input, cpp_opts=[]): """preprocess <input> through cpp -> preprocessed output input may be path/to/file or iterable data type """ args = [ "-Ulinux" ] for opt, val in cpp_opts: args.append(opt + val) include_path = os.environ.get('FAB_PLAN_INCLUDE_PATH') if include_path: for path in include_path.split(':'): args.append("-I" + path) command = ["cpp", input] if args: command += args trap = stdtrap.StdTrap() try: executil.system(*command) except ExecError, e: trap.close() trapped_stderr = trap.stderr.read() raise ExecError(" ".join(command), e.exitcode, trapped_stderr)
def run(self, passphrase, creds=None, debug=False): sys.stdout.flush() if creds: os.environ['AWS_ACCESS_KEY_ID'] = creds.accesskey os.environ['AWS_SECRET_ACCESS_KEY'] = creds.secretkey os.environ['X_AMZ_SECURITY_TOKEN'] = ",".join([creds.producttoken, creds.usertoken]) if PATH_DEPS_BIN not in os.environ['PATH'].split(':'): os.environ['PATH'] = PATH_DEPS_BIN + ':' + os.environ['PATH'] if PATH_DEPS_PYLIB: os.environ['PYTHONPATH'] = PATH_DEPS_PYLIB os.environ['PASSPHRASE'] = passphrase if debug: import executil shell = os.environ.get("SHELL", "/bin/bash") if shell == "/bin/bash": shell += " --norc" executil.system(shell) child = Popen(self.command) del os.environ['PASSPHRASE'] exitcode = child.wait() if exitcode != 0: raise Error("non-zero exitcode (%d) from backup command: %s" % (exitcode, str(self)))
def update(section, name, value): config_path = "/var/www/piwik/config/config.ini.php" if not os.path.exists(config_path): raise Error("config file does not exist: %s" % config_path) config_new = [] in_section = False for line in file(config_path).readlines(): line = line.rstrip() if line.startswith("["): if line == section: in_section = True else: in_section = False if in_section and line.startswith("%s =" % name): line = "%s = \"%s\"" % (name, value) config_new.append(line) # write out updated config file(config_path, "w").write("\n".join(config_new) + "\n") # set ownership and permissions system("chown www-data:www-data %s" % config_path) system("chmod 640 %s" % config_path)
def parun(commands, minheight=DEFAULT_MINHEIGHT, daemon=False, session_name=None): if (termcap_get_lines() - len(commands)) / len(commands) >= minheight: split = True else: split = False stdin = None if not os.isatty(sys.stdin.fileno()): stdin = TempFile() stdin.write(sys.stdin.read()) stdin.close() # screen wants stdin to be connected to a tty os.dup2(sys.stderr.fileno(), sys.stdin.fileno()) screens = fmt_screens(commands, stdin) if split: screenrc = "split\nfocus\n".join([ screen + "\n" for screen in screens ]) else: screenrc = "\n".join(screens) + "\n" + "windowlist -b" + "\n" screenrc_tmp = TempFile() screenrc_tmp.write(screenrc) screenrc_tmp.close() args = ["-c", screenrc_tmp.path] if daemon: args += [ "-dm" ] if session_name: args += [ "-S", session_name ] executil.system("screen", *args) if daemon: time.sleep(1)
def __init__(self): system("mkdir -p /var/run/mysqld") system("chown mysql:root /var/run/mysqld") self.selfstarted = False if not self._is_alive(): self._start() self.selfstarted = True
def mkpart(self): executil.system( 'parted', self.real_path, '--script', 'unit mib mklabel gpt mkpart primary 1 3 name 1 grub set 1 bios_grub on mkpart primary ext4 3 -1 name 2 rootfs quit' ) executil.system('partprobe', self.real_path) self.root_path = self.real_path self.real_path = self.real_path + '2'
def umount(self): if self.mounted_devpts_myself: executil.system("umount", self.paths.dev.pts) self.mounted_devpts_myself = False if self.mounted_proc_myself: executil.system("umount", self.paths.proc) self.mounted_proc_myself = False
def mount(self): if not self._is_mounted(self.paths.proc): executil.system("mount -t proc", "proc-chroot", self.paths.proc) self.mounted_proc_myself = True if not self._is_mounted(self.paths.dev.pts): executil.system("mount -t devpts", "devpts-chroot", self.paths.dev.pts) self.mounted_devpts_myself = True
def unconfigure_if(ifname): try: ifdown(ifname) interfaces = EtcNetworkInterfaces() interfaces.set_manual(ifname) executil.system("ifconfig %s 0.0.0.0" % ifname) ifup(ifname) except Exception, e: return str(e)
def _start(self): system("mysqld --skip-networking >/dev/null 2>&1 &") for i in range(6): if self._is_alive(): return time.sleep(1) raise Error("could not start mysqld")
def mount(devpath, mountpath, options=None): """mount devpath to mountpath with specified options (creates mountpath)""" if not os.path.exists(mountpath): mkdir_parents(mountpath) if options: executil.system("mount", "-o", options, devpath, mountpath) else: executil.system("mount", devpath, mountpath)
def _system(self, command, *args): os.setuid(self.euid) try: try: system(command, *args) except ExecError, e: raise Error(e) finally: os.setreuid(self.uid, self.euid)
def _shutdown(self, text, opt): if self.console.yesno(text) == self.OK: self.running = False cmd = "shutdown %s now" % opt fgvt = os.environ.get("FGVT") if fgvt: cmd = "chvt %s; " % fgvt + cmd executil.system(cmd) return "advanced"
def luksOpen(device, key): """open a luks encrypted <device> using <key> -> _LuksOpened(map, keyslot) <key> can be either a filename or a passphrase """ try: system("cryptsetup isLuks", device) except ExecError, e: raise Error(e)
def run(): retcode, choice = console.menu( TITLE, TEXT, [('Default', "Safe and Default TurnKey permission settings"), ('Risky', "Set risky settings required for updating via WebUI.")]) if choice: cmd = path.join(path.dirname(__file__), 'suitecrm_permissions.sh') system(cmd, choice) console.msgbox(TITLE, choice + ' settings was set.') return
def download(self): print "* get: " + self.filename executil.system("ccurl-get", self.url, self.path) # verify integrity, delete on failure content = file(self.path, 'rb').read() digest = getattr(hashlib, self.hashtype.lower())(content).hexdigest() if not digest == self.digest: os.remove(self.path) executil.system("ccurl-del", self.url) raise Error("verification failed: ", self.filename)
def run(): host = 'localhost' port = '25' login = '' password = '' cmd = path.join(path.dirname(__file__), 'mail_relay.sh') retcode, choice = console.menu( TITLE, TEXT, [('SendinBlue', "TurnKey's preferred SMTP gateway"), ('Custom', 'Custom mail relay configuration'), ('Deconfigure', 'Erase current mail relay settings')]) if choice: if choice == 'Deconfigure': system(cmd, 'deconfigure') console.msgbox( TITLE, 'The mail relay settings were succesfully erased. No relaying will take place from now on.' ) return if choice == 'SendinBlue': host = 'smtp-relay.sendinblue.com' port = '587' field_width = field_limit = 100 while 1: fields = [('Host', host, field_width, field_limit), ('Port', port, field_width, field_limit), ('Login', login, field_width, field_limit), ('Password', password, field_width, field_limit)] retcode, values = console.form(TITLE, FORMNOTE, fields) if retcode is not 0: console.msgbox( TITLE, 'You have cancelled the configuration process. No relaying of mail will be performed.' ) return host, port, login, password = tuple(values) if testsettings(*values): break else: console.msgbox( TITLE, 'Could not connect with supplied parameters. Please check config and try again.' ) system(cmd, host, port, login, password)
def main(): interface = "" if not interface: d = dialog.Dialog(dialog="dialog") d.add_persistent_args(["--backtitle", "Insta-Snorby - First boot configuration"]) interface = interface_menu(d,"Please select an interface to monitor", iface_list()) system("echo " + interface) system("sed -i 's/eth0/%s/g' /etc/snort/barnyard2.conf" % interface) system("sed -i 's/eth0/%s/g' /usr/lib/inithooks/everyboot.d/88snortstart" % interface) system("sed -i 's/eth0/%s/g' /root/pulledpork-0.6.1/etc/pulledpork.conf" % interface) system("sed -i 's/eth0/%s/g' /root/openfpc-0.6-314/etc/openfpc-default.conf" % interface)
def main(): args = sys.argv[1:] if len(args) != 6: usage() arch, suite, target, repo, required_spec, base_spec = args os.environ["REQUIRED_PACKAGES"] = " ".join(get_packages(required_spec)) os.environ["BASE_PACKAGES"] = " ".join(get_packages(base_spec)) repo = abspath(repo) system("debootstrap --arch %s %s %s file://%s" % (arch, suite, target, repo))
def refresh(self): print "Refreshing local cache..." list = "_dists_local_debs_binary-%s_Packages" % self.chanko.architecture list_path = os.path.join(self.cache_lists, list) cmd = "apt-ftparchive packages" cmd += " --db=%s" % os.path.join(self.cache, "dbcache") cmd += " %s > %s" % (self.chanko.archives, list_path) executil.system(cmd) self._cmdcache("gencaches")
def refresh(self): print "Refreshing local cache..." list = "_dists_local_debs_binary-%s_Packages" % self.chanko.architecture list_path = os.path.join(self.cache_lists, list) cmd = "apt-ftparchive packages" cmd += " --db=%s" % os.path.join(self.cache, 'dbcache') cmd += " %s > %s" % (self.chanko.archives, list_path) executil.system(cmd) self._cmdcache("gencaches")
def ebsmount_add(devname, mountdir): """ebs device attached""" matching_devices = [] for device in udevdb.query(): if device.name.startswith(basename(devname)): matching_devices.append(device) for device in matching_devices: devpath = join("/dev", device.name) mountpath = join(mountdir, device.env.get("ID_FS_UUID", devpath[-1])[:6]) mountoptions = ",".join(config.mountoptions.split()) hookspath = join(mountpath, ".ebsmount") filesystem = device.env.get("ID_FS_TYPE", None) if not filesystem: log(devname, "could not identify filesystem: %s" % devpath) continue if not filesystem in config.filesystems.split(): log(devname, "filesystem (%s) not supported: %s" % (filesystem, devpath)) continue if is_mounted(devpath): log(devname, "already mounted: %s" % devpath) continue mount(devpath, mountpath, mountoptions) log(devname, "mounted %s %s (%s)" % (devpath, mountpath, mountoptions)) if exists(hookspath): hooks = os.listdir(hookspath) hooks.sort() if hooks and not config.runhooks.lower() == "true": log(devname, "skipping hooks: RUNHOOKS not set to True") continue for file in hooks: fpath = join(hookspath, file) if not os.access(fpath, os.X_OK): log(devname, "skipping hook: '%s', not executable" % file) continue if not os.stat(fpath).st_uid == 0 or not os.stat(fpath).st_gid == 0: log(devname, "skipping hook: '%s', not owned root:root" % file) continue log(devname, "executing hook: %s" % file) os.environ["HOME"] = pwd.getpwuid(os.getuid()).pw_dir os.environ["MOUNTPOINT"] = mountpath system("/bin/bash --login -c '%s' 2>&1 | tee -a %s" % (fpath, config.logfile))
def ebsmount_add(devname, mountdir): """ebs device attached""" matching_devices = [] for device in udevdb.query(): if device.name.startswith(basename(devname)): matching_devices.append(device) for device in matching_devices: devpath = join('/dev', device.name) mountpath = join(mountdir, device.env.get('ID_FS_UUID', devpath[-1])[:6]) mountoptions = ",".join(config.mountoptions.split()) hookspath = join(mountpath, ".ebsmount") filesystem = device.env.get('ID_FS_TYPE', None) if not filesystem: log(devname, "could not identify filesystem: %s" % devpath) continue if not filesystem in config.filesystems.split(): log(devname, "filesystem (%s) not supported: %s" % (filesystem,devpath)) continue if is_mounted(devpath): log(devname, "already mounted: %s" % devpath) continue mount(devpath, mountpath, mountoptions) log(devname, "mounted %s %s (%s)" % (devpath, mountpath, mountoptions)) if exists(hookspath): hooks = os.listdir(hookspath) hooks.sort() if hooks and not config.runhooks.lower() == "true": log(devname, "skipping hooks: RUNHOOKS not set to True") continue for file in hooks: fpath = join(hookspath, file) if not os.access(fpath, os.X_OK): log(devname, "skipping hook: '%s', not executable" % file) continue if not os.stat(fpath).st_uid == 0 or not os.stat(fpath).st_gid == 0: log(devname, "skipping hook: '%s', not owned root:root" % file) continue log(devname, "executing hook: %s" % file) os.environ['HOME'] = pwd.getpwuid(os.getuid()).pw_dir os.environ['MOUNTPOINT'] = mountpath system("/bin/bash --login -c '%s' 2>&1 | tee -a %s" % (fpath, config.logfile))
def run(self, passphrase, creds=None, debug=False): sys.stdout.flush() if creds: if creds.type in ('devpay', 'iamuser'): os.environ['AWS_ACCESS_KEY_ID'] = creds.accesskey os.environ['AWS_SECRET_ACCESS_KEY'] = creds.secretkey os.environ['X_AMZ_SECURITY_TOKEN'] = (",".join([creds.producttoken, creds.usertoken]) if creds.type == 'devpay' else creds.sessiontoken) elif creds.type == 'iamrole': os.environ['AWS_STSAGENT'] = fmt_internal_command('stsagent') if PATH_DEPS_BIN not in os.environ['PATH'].split(':'): os.environ['PATH'] = PATH_DEPS_BIN + ':' + os.environ['PATH'] if PATH_DEPS_PYLIB: pythonpath = os.environ.get('PYTHONPATH') pythonpath = ((PATH_DEPS_PYLIB + ':' + pythonpath) if pythonpath else PATH_DEPS_PYLIB) os.environ['PYTHONPATH'] = pythonpath os.environ['PASSPHRASE'] = passphrase if debug: print """ The --debug option has dropped you into an interactive shell in which you can explore the state of the system just before the above duplicity command is run, and/or execute it manually. For Duplicity usage info, options and storage backends, run "duplicity --help". To exit from the shell and continue running duplicity "exit 0". To exit from the shell and abort this session "exit 1". """ import executil shell = os.environ.get("SHELL", "/bin/bash") if shell == "/bin/bash": shell += " --norc" executil.system(shell) child = Popen(self.command) del os.environ['PASSPHRASE'] exitcode = child.wait() if exitcode != 0: raise Error("non-zero exitcode (%d) from backup command: %s" % (exitcode, str(self)))
def bundle(rootfs, region, bucket=None, size=10, filesystem='ext4'): _get_amitools_path() pems = _get_pem_paths() log.info('creating loopback, formatting and mounting') image_path = rootfs + '.img' image_mount = rootfs + '.img.mount' utils.mkdir(image_mount) executil.system('dd if=/dev/null of=%s bs=1 seek=%dG' % (image_path, size)) executil.system('mkfs.' + filesystem, '-F', '-j', image_path) executil.system('mount -o loop', image_path, image_mount) log.info('syncing rootfs to loopback') utils.rsync(rootfs, image_mount) log.debug('umounting loopback') executil.system('umount', '-d', image_mount) os.removedirs(image_mount) log.debug('getting unique ami name') app = utils.get_turnkey_version(rootfs) ami_name = utils.get_uniquename(region, app + '.s3') log.info('target ami_name - %s ', ami_name) log.info('bundling loopback into ami') arch = utils.parse_imagename(ami_name)['architecture'] _bundle_image(region, image_path, ami_name, arch, pems) os.remove(image_path) log.info('uploading bundled ami') bucket = bucket if bucket else "turnkeylinux-" + region _bundle_upload(region, ami_name, bucket) log.info("complete - %s %s", bucket, ami_name) return bucket, ami_name
def isolinux2syslinux(self): print "* making isolinux configuration compatible for syslinux" path = self.mountdir.path executil.system('mv %s/isolinux/* %s' % (path, path)) executil.system('mv %s/isolinux.cfg %s/syslinux.cfg' % (path, path)) executil.system('rmdir %s/isolinux' % path) executil.system('rm -f %s/isolinux.bin' % path)
def run(self, passphrase, creds=None, debug=False): sys.stdout.flush() if creds: if creds.type in ('devpay', 'iamuser'): os.environ['AWS_ACCESS_KEY_ID'] = creds.accesskey os.environ['AWS_SECRET_ACCESS_KEY'] = creds.secretkey os.environ['X_AMZ_SECURITY_TOKEN'] = (",".join([ creds.producttoken, creds.usertoken ]) if creds.type == 'devpay' else creds.sessiontoken) elif creds.type == 'iamrole': os.environ['AWS_STSAGENT'] = fmt_internal_command('stsagent') if PATH_DEPS_BIN not in os.environ['PATH'].split(':'): os.environ['PATH'] = PATH_DEPS_BIN + ':' + os.environ['PATH'] if PATH_DEPS_PYLIB: pythonpath = os.environ.get('PYTHONPATH') pythonpath = ((PATH_DEPS_PYLIB + ':' + pythonpath) if pythonpath else PATH_DEPS_PYLIB) os.environ['PYTHONPATH'] = pythonpath os.environ['PASSPHRASE'] = passphrase if debug: print """ The --debug option has dropped you into an interactive shell in which you can explore the state of the system just before the above duplicity command is run, and/or execute it manually. For Duplicity usage info, options and storage backends, run "duplicity --help". To exit from the shell and continue running duplicity "exit 0". To exit from the shell and abort this session "exit 1". """ import executil shell = os.environ.get("SHELL", "/bin/bash") if shell == "/bin/bash": shell += " --norc" executil.system(shell) child = Popen(self.command) del os.environ['PASSPHRASE'] exitcode = child.wait() if exitcode != 0: raise Error("non-zero exitcode (%d) from backup command: %s" % (exitcode, str(self)))
def download(self): print "* get: " + self.destfile if self.filename == "Packages.bz2": path = self.path + ".bz2" executil.system("curl -L -f %s -o %s" % (self.url, path)) executil.system("bzcat %s > %s" % (path, self.path)) elif self.filename == "Packages.gz": path = self.path + ".gz" executil.system("curl -L -f %s -o %s" % (self.url, path)) executil.system("zcat %s > %s" % (path, self.path)) else: executil.system("curl -L -f %s -o %s" % (self.url, self.path))
def _run(self, state): if not isdir(self.path): return for fname in os.listdir(self.path): fpath = join(self.path, fname) if not os.access(fpath, os.X_OK): continue try: executil.system(fpath, self.name, state) except executil.ExecError, e: raise HookError("`%s %s %s` non-zero exitcode (%d)" % \ (fpath, self.name, state, e.exitcode))
def run(): host = 'localhost' port = '25' login = '' password = '' cmd = path.join(path.dirname(__file__), 'mail_relay.sh') retcode, choice = console.menu(TITLE, TEXT, [ ('SendinBlue', "TurnKey's preferred SMTP gateway"), ('Custom', 'Custom mail relay configuration'), ('Deconfigure', 'Erase current mail relay settings') ]) if choice: if choice == 'Deconfigure': system(cmd, 'deconfigure') console.msgbox(TITLE, 'The mail relay settings were succesfully erased. No relaying will take place from now on.') return if choice == 'SendinBlue': host = 'smtp-relay.sendinblue.com' port = '587' field_width = field_limit = 100 while 1: fields = [ ('Host', host, field_width, field_limit), ('Port', port, field_width, field_limit), ('Login', login, field_width, field_limit), ('Password', password, field_width, field_limit) ] retcode, values = console.form(TITLE, FORMNOTE, fields) if retcode is not 0: console.msgbox(TITLE, 'You have cancelled the configuration process. No relaying of mail will be performed.') return host, port, login, password = tuple(values) if testsettings(*values): break else: console.msgbox(TITLE, 'Could not connect with supplied parameters. Please check config and try again.') system(cmd, host, port, login, password)
def cpp(input, cpp_opts=[]): """preprocess <input> through cpp -> preprocessed output input may be path/to/file or iterable data type """ cpp_opts.append("-Ulinux") command = ["cpp", input] command += cpp_opts trap = stdtrap.StdTrap() try: executil.system(*command) except executil.ExecError, e: trap.close() trapped_stderr = trap.stderr.read() raise executil.ExecError(" ".join(command), e.exitcode, trapped_stderr)
def bundle(rootfs, snapshot_name, size=10, filesystem='ext4'): log.info('target snapshot - %s ', snapshot_name) log.info('creating volume, attaching, formatting and mounting') volume = Volume() volume.create(size) device = Device() volume.attach(utils.get_instanceid(), device) log.info('creating partitions') device.mkpart() device.mkfs(filesystem) mount_path = rootfs + '.mount' device.mount(mount_path) log.info('syncing rootfs to partition') utils.rsync(rootfs, mount_path) log.info('installing GRUB on volume') submounts = ['/sys', '/proc', '/dev'] for s in submounts: executil.system('mount', '--bind', '--make-rslave', s, mount_path + s) executil.system('chroot', mount_path, 'grub-install', device.root_path) executil.system('chroot', mount_path, 'update-grub') executil.system('chroot', mount_path, 'update-initramfs', '-u') submounts.reverse() for s in submounts: executil.system('umount', '-l', mount_path + s) device.umount() volume.detach() os.removedirs(mount_path) log.info('creating snapshot from volume') snapshot = Snapshot() snapshot.create(volume.vol.id, snapshot_name) volume._wait("available") volume.delete() log.info("complete - %s %s", snapshot.snap.id, snapshot.snap.description) return snapshot.snap.id, snapshot.snap.description
def make_release_deb(path_changelog, path_output, depends=[]): name, version, maintainer = parse_changelog(path_changelog) tmpdir = TempDir() os.mkdir(join(tmpdir.path, "DEBIAN")) control = file(join(tmpdir.path, "DEBIAN/control"), "w") content = Template(CONTROL_TPL).substitute(NAME=name, VERSION=version, MAINTAINER=maintainer, DEPENDS=", ".join(depends)) print >> control, re.sub("Depends: \n", "", content), control.close() tmpdir_doc = join(tmpdir.path, "usr/share/doc/" + name) os.makedirs(tmpdir_doc) shutil.copy(path_changelog, tmpdir_doc) system("dpkg-deb -b", tmpdir.path, path_output)
def generate_release(self, gpgkey=None): def get_archs(): archs = set() dist_path = join(self.path, 'dists', self.release) for component in os.listdir(dist_path): component_path = join(dist_path, component) if not isdir(component_path): continue for binary in os.listdir(component_path): if binary == 'binary-all': continue archs.add(binary.replace('binary-', '')) return archs components_dir = join(self.path, self.pool) release_dir = join('dists', self.release) release = join(self.path, release_dir, 'Release') release_gpg = join(self.path, release_dir, 'Release.gpg') for path in (release, release_gpg): if exists(path): os.remove(path) hashes = self._archive_cmd('release', release_dir) fh = file(release, "w") print >> fh, "Origin: %s" % self.origin print >> fh, "Label: %s" % self.origin print >> fh, "Suite: %s" % self.release print >> fh, "Version: %s" % self.version print >> fh, "Codename: %s" % self.release print >> fh, "Architectures: %s" % ' '.join(get_archs()) print >> fh, "Components: %s" % ' '.join(os.listdir(components_dir)) print >> fh, "Description: %s %s %s" % (self.origin, self.release, self.version) print >> fh, hashes fh.close() if gpgkey: cmd = "gpg -abs -u %s -o %s %s" % (gpgkey, release_gpg, release) executil.system(cmd)
def main(): interface = "" if not interface: d = dialog.Dialog(dialog="dialog") d.add_persistent_args( ["--backtitle", "Insta-Snorby - First boot configuration"]) interface = interface_menu(d, "Please select an interface to monitor", iface_list()) system("echo " + interface) system("sed -i 's/eth0/%s/g' /etc/snort/barnyard2.conf" % interface) system( "sed -i 's/eth0/%s/g' /usr/lib/inithooks/everyboot.d/88snortstart" % interface) system( "sed -i 's/eth0/%s/g' /root/pulledpork-0.6.1/etc/pulledpork.conf" % interface) system( "sed -i 's/eth0/%s/g' /root/openfpc-0.6-314/etc/openfpc-default.conf" % interface)
def _run_hooks(path, args, keyring=None): if not isdir(path): return for fname in os.listdir(path): fpath = join(path, fname) if not os.access(fpath, os.X_OK): continue if fpath.endswith(".sig"): continue if keyring and not _is_signed(fpath, keyring): continue try: executil.system(fpath, *args) except executil.ExecError, e: raise HookError("`%s %s` non-zero exitcode (%d)" % \ (fpath, " ".join(args), e.exitcode))