Ejemplo n.º 1
0
def pubInstall(args):
    '''install      sourceFile [sourceFile ...] targetDir
                  Install source file into target directory
                  with a stamp suffix.'''
    installDir = args.pop()
    for f in args:
        shutil.copy(f,os.path.join(installDir,dws.stampfile(f)))
Ejemplo n.º 2
0
def pubInstall(args):
    '''install      sourceFile [sourceFile ...] targetDir
                  Install source file into target directory
                  with a stamp suffix.'''
    installDir = args.pop()
    for f in args:
        shutil.copy(f,os.path.join(installDir,dws.stampfile(f)))
Ejemplo n.º 3
0
def create_archives(backup_dir, backup_tops):
    '''Create an archive out of each backup_top.'''
    os.chdir(backup_dir)
    for backup_top in backup_tops:
        basename = os.path.basename(backup_top)
        archive = tero.stampfile(basename)
        tero.shell_command([
            'tar', '--bzip2', '-cf', archive, '-C',
            os.path.dirname(backup_top), '--exclude', 'build/', basename
        ])
    tero.dstamp.cleanup_aged_files(backup_dir)
Ejemplo n.º 4
0
def create_archives(backup_dir, backup_tops):
    '''Create an archive out of each backup_top.'''
    os.chdir(backup_dir)
    for backup_top in backup_tops:
        basename = os.path.basename(backup_top)
        archive = tero.stampfile(basename)
        tero.shell_command(['tar', '--bzip2', '-cf', archive,
                          '-C', os.path.dirname(backup_top),
                          '--exclude', 'build/',
                          basename])
    # TODO dstamp hasn't been moved into the tero package yet.
    dstamp.cleanUpAgedFiles(backup_dir)
Ejemplo n.º 5
0
def pub_snap(names):
    """
    Takes a snapshot of running machine
    """
    tero.CONTEXT = tero.Context()
    tero.CONTEXT.locate()
    log_path_prefix = tero.stampfile(
        tero.CONTEXT.log_path(
            os.path.join(tero.CONTEXT.host(), socket.gethostname())))
    fingerprint(tero.CONTEXT,
                log_path_prefix,
                skip_filesystem=True,
                skip_privileged_executables=True,
                skip_apps=False)
Ejemplo n.º 6
0
def main(args):
    '''Configure a machine to serve as a forum server, with ssh, e-mail
       and web daemons. Hook-up the server machine with a dynamic DNS server
       and make it reachable from the internet when necessary.'''

    import __main__
    import argparse

    # We keep a starting time stamp such that we can later on
    # find out the services that need to be restarted. These are
    # the ones whose configuration files have a modification
    # later than *start_timestamp*.
    start_timestamp = datetime.datetime.now()
    prev = os.getcwd()

    bin_base = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))

    parser = argparse.ArgumentParser(
        usage='%(prog)s [options] *profile*\n\nVersion:\n  %(prog)s version ' \
            + str(__version__))
    parser.add_argument('profiles',
                        nargs='*',
                        help='Profiles to use to configure the machine.')
    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s ' + str(__version__))
    parser.add_argument(
        '-D',
        dest='defines',
        action='append',
        default=[],
        help='Add a (key,value) definition to use in templates.')
    parser.add_argument(
        '--fingerprint',
        dest='fingerprint',
        action='store_true',
        default=False,
        help='Fingerprint the system before making modifications')
    parser.add_argument('--skip-recurse', dest='install',
        action='store_false', default=True,
        help='Assumes all prerequisites to build the'\
' configuration package have been installed correctly. Generate'\
' a configuration package but donot install it.')
    parser.add_argument('--dyndns',
                        dest='dyndns',
                        action='store_true',
                        help='Add configuration for dynamic DNS')
    parser.add_argument('--sshkey', dest='sshkey', action='store_true',
        help='Configure the ssh daemon to disable password login and use'\
' keys instead')
    options = parser.parse_args(args[1:])
    if len(options.profiles) < 1:
        parser.print_help()
        sys.exit(1)

    # siteTop where packages are built
    conf_top = os.getcwd()
    tero.ASK_PASS = os.path.join(bin_base, 'askpass')

    # -- Let's start the configuration --
    if not os.path.isdir(conf_top):
        os.makedirs(conf_top)
    os.chdir(conf_top)
    tero.USE_DEFAULT_ANSWER = True
    tero.CONTEXT = Context()
    tero.CONTEXT.config_filename = os.path.join(conf_top, 'dws.mk')
    tero.CONTEXT.buildTopRelativeCwd \
        = os.path.dirname(tero.CONTEXT.config_filename)
    tero.CONTEXT.environ['version'] = __version__

    # Configuration information
    # Add necessary variables in context, then parse a list of variable
    # definitions with format key=value from the command line and append
    # them to the context.
    for define in options.defines:
        key, value = define.split('=')
        tero.CONTEXT.environ[key] = value

    project_name = tero.CONTEXT.value('PROJECT_NAME')

    log_path_prefix = stampfile(
        tero.CONTEXT.log_path(
            os.path.join(tero.CONTEXT.host(), socket.gethostname())))
    if options.fingerprint:
        fingerprint(tero.CONTEXT, log_path_prefix)

    if options.install:
        # \todo We ask sudo password upfront such that the non-interactive
        # install process does not bail out because it needs a password.
        try:
            shell_command(
                ['SUDO_ASKPASS="******"' % tero.ASK_PASS, 'sudo', 'echo', 'hello'])
        except Error:
            # In case sudo requires a password, let's explicitely ask for it
            # and cache it now.
            sys.stdout.write("%s is asking to cache the sudo password such"\
" that it won\'t be asked in the non-interactive part of the script.\n"
                % sys.argv[0])
            shell_command(
                ['SUDO_ASKPASS="******"' % tero.ASK_PASS, 'sudo', '-A', '-v'])

    setups = prepare_local_system(tero.CONTEXT, project_name, options.profiles)
    os.chdir(prev)
    try:
        with open(os.path.join(tero.CONTEXT.value('modEtcDir'), 'config.book'),
                  'w') as book:
            book.write('''<?xml version="1.0"?>
<section xmlns="http://docbook.org/ns/docbook"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xmlns:xi="http://www.w3.org/2001/XInclude">
  <info>
    <title>Modification to configuration files</title>
  </info>
  <section>
<programlisting>''')
            cmd = subprocess.Popen(' '.join([
                'diff', '-rNu',
                tero.CONTEXT.value('tplEtcDir'),
                tero.CONTEXT.value('modEtcDir')
            ]),
                                   shell=True,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT)
            book.write(''.join(cmd.stdout.readlines()))
            book.write('</programlisting>\n</section>\n')
    except Error:
        # We donot check error code here since the diff will complete
        # with a non-zero error code if we either modified the config file.
        pass

    # Create the postinst script
    create_postinst(start_timestamp, setups)
    final_install_package = create_install_script(
        project_name, tero.CONTEXT, install_top=os.path.dirname(bin_base))

    # Install the package as if it was a normal distribution package.
    if options.install:
        if not os.path.exists('install'):
            os.makedirs('install')
        shutil.copy(final_install_package, 'install')
        os.chdir('install')
        install_basename = os.path.basename(final_install_package)
        project_name = '.'.join(install_basename.split('.')[:-2])
        shell_command(['tar', 'jxf', os.path.basename(final_install_package)])
        sys.stdout.write('ATTENTION: A sudo password is required now.\n')
        os.chdir(project_name)
        shell_command(['./install.sh'], admin=True)
Ejemplo n.º 7
0
def main(args):
    '''Configure a machine to serve as a forum server, with ssh, e-mail
       and web daemons. Hook-up the server machine with a dynamic DNS server
       and make it reachable from the internet when necessary.'''

    import __main__
    import argparse

    # We keep a starting time stamp such that we can later on
    # find out the services that need to be restarted. These are
    # the ones whose configuration files have a modification
    # later than *start_timestamp*.
    start_timestamp = datetime.datetime.now()
    prev = os.getcwd()

    bin_base = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))

    parser = argparse.ArgumentParser(
        usage='%(prog)s [options] *profile*\n\nVersion:\n  %(prog)s version ' \
            + str(__version__))
    parser.add_argument('profiles', nargs='*',
        help='Profiles to use to configure the machine.')
    parser.add_argument('--version', action='version',
        version='%(prog)s ' + str(__version__))
    parser.add_argument('-D', dest='defines', action='append', default=[],
        help='Add a (key,value) definition to use in templates.')
    parser.add_argument('--fingerprint', dest='fingerprint',
        action='store_true', default=False,
        help='Fingerprint the system before making modifications')
    parser.add_argument('--skip-recurse', dest='install',
        action='store_false', default=True,
        help='Assumes all prerequisites to build the'\
' configuration package have been installed correctly. Generate'\
' a configuration package but donot install it.')
    parser.add_argument('--dyndns', dest='dyndns', action='store_true',
        help='Add configuration for dynamic DNS')
    parser.add_argument('--sshkey', dest='sshkey', action='store_true',
        help='Configure the ssh daemon to disable password login and use'\
' keys instead')
    options = parser.parse_args(args[1:])
    if len(options.profiles) < 1:
        parser.print_help()
        sys.exit(1)

    # siteTop where packages are built
    conf_top = os.getcwd()
    tero.ASK_PASS = os.path.join(bin_base, 'askpass')

    # -- Let's start the configuration --
    if not os.path.isdir(conf_top):
        os.makedirs(conf_top)
    os.chdir(conf_top)
    tero.USE_DEFAULT_ANSWER = True
    tero.CONTEXT = Context()
    tero.CONTEXT.config_filename = os.path.join(conf_top, 'dws.mk')
    tero.CONTEXT.buildTopRelativeCwd \
        = os.path.dirname(tero.CONTEXT.config_filename)
    tero.CONTEXT.environ['version'] = __version__

    # Configuration information
    # Add necessary variables in context, then parse a list of variable
    # definitions with format key=value from the command line and append
    # them to the context.
    for define in options.defines:
        key, value = define.split('=')
        tero.CONTEXT.environ[key] = value

    project_name = tero.CONTEXT.value('PROJECT_NAME')

    log_path_prefix = stampfile(tero.CONTEXT.log_path(
            os.path.join(tero.CONTEXT.host(), socket.gethostname())))
    if options.fingerprint:
        fingerprint(tero.CONTEXT, log_path_prefix)

    if options.install:
        # \todo We ask sudo password upfront such that the non-interactive
        # install process does not bail out because it needs a password.
        try:
            shell_command(
                ['SUDO_ASKPASS="******"' % tero.ASK_PASS, 'sudo', 'echo', 'hello'])
        except Error:
            # In case sudo requires a password, let's explicitely ask for it
            # and cache it now.
            sys.stdout.write("%s is asking to cache the sudo password such"\
" that it won\'t be asked in the non-interactive part of the script.\n"
                % sys.argv[0])
            shell_command(
                ['SUDO_ASKPASS="******"' % tero.ASK_PASS, 'sudo', '-A', '-v'])

    setups = prepare_local_system(tero.CONTEXT, project_name, options.profiles)
    os.chdir(prev)
    try:
        with open(os.path.join(
                tero.CONTEXT.value('modEtcDir'), 'config.book'), 'w') as book:
            book.write('''<?xml version="1.0"?>
<section xmlns="http://docbook.org/ns/docbook"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xmlns:xi="http://www.w3.org/2001/XInclude">
  <info>
    <title>Modification to configuration files</title>
  </info>
  <section>
<programlisting>''')
            cmd = subprocess.Popen(' '.join(['diff', '-rNu',
                tero.CONTEXT.value('tplEtcDir'),
                tero.CONTEXT.value('modEtcDir')]),
                shell=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT)
            book.write(''.join(cmd.stdout.readlines()))
            book.write('</programlisting>\n</section>\n')
    except Error:
        # We donot check error code here since the diff will complete
        # with a non-zero error code if we either modified the config file.
        pass

    # Create the postinst script
    create_postinst(start_timestamp, setups)
    final_install_package = create_install_script(project_name, tero.CONTEXT,
        install_top=os.path.dirname(bin_base))

    # Install the package as if it was a normal distribution package.
    if options.install:
        if not os.path.exists('install'):
            os.makedirs('install')
        shutil.copy(final_install_package, 'install')
        os.chdir('install')
        install_basename = os.path.basename(final_install_package)
        project_name = '.'.join(install_basename.split('.')[:-2])
        shell_command(['tar', 'jxf', os.path.basename(final_install_package)])
        sys.stdout.write('ATTENTION: A sudo password is required now.\n')
        os.chdir(project_name)
        shell_command(['./install.sh'], admin=True)