Example #1
0
def installBoot(install_root, profile):
    renderTemplates(profile.get('booting', 'bootloader_templates').split(','))

    if os.access('/proc/mdstat', os.R_OK):
        installPackages(profile.get('packages', 'mdadm_package'))

    if execute_lines('/sbin/lvm pvs'):
        installPackages(profile.get('packages', 'lvm_package'))

    if os.access('/sys/fs/bcache', os.R_OK):
        installPackages(profile.get('packages', 'bcache_package'))

    if os.path.exists('/sys/firmware/efi'):
        installPackages(profile.get('packages', 'bootloader_package_efi'))
    else:
        installPackages(profile.get('packages', 'bootloader_package_bios'))

    try:
        chroot_execute(profile.get('booting', 'bootloader_config'))
    except NoOptionError:
        pass

    try:
        installPackages(profile.get('packages', 'kernel_package'))
    except NoOptionError:
        pass

    try:
        bootloader_install = profile.get('booting', 'bootloader_install')
    except NoOptionError:
        bootloader_install = None

    if bootloader_install:
        for drive in fsConfigValues()['boot_drives']:
            chroot_execute(bootloader_install.format(drive))
Example #2
0
def divert( profile ):
  global divert_list

  for item in profile.items( 'packaging' ):
    if item[0].startswith( 'divert_' ):
      ( name, target ) = item[1].split( ':' )
      divert_list.append( ( name.strip(), target.strip() ) )

  if manager_type == 'apt':
    for ( name, target ) in divert_list:
      chroot_execute( '/usr/bin/dpkg-divert --divert {0}.linux-installer --rename {0}'.format( name ) )
      chroot_execute( 'ln -s {0} {1}'.format( target, name ) )
Example #3
0
File: misc.py Project: pnhowe/disks
def postInstallScripts(install_root, value_map):
    if 'postinstall_script' in value_map:  # TODO: http proxy, see also bootstrap
        target_path = os.path.join(install_root, 'postinstall')
        open(target_path,
             'w').write(http_getfile(value_map['postinstall_script']))
        os.chmod(
            target_path,
            os.stat(target_path).st_mode | stat.S_IXUSR | stat.S_IXGRP
            | stat.S_IXOTH)
        chroot_execute('/postinstall')
        os.unlink(target_path)

    for command in value_map.get('postinstall_command_list', []):
        chroot_execute("sh -c '" + command + "'")
Example #4
0
def updatePackages():
    if manager_type == 'apt':
        chroot_execute('/usr/bin/apt-get update')
        chroot_execute('/usr/bin/apt-get upgrade -q -y')
    elif manager_type == 'yum':
        chroot_execute('/usr/bin/yum -y update')
    elif manager_type == 'zypper':
        chroot_execute('/usr/bin/zypper --non-interactive update')
Example #5
0
def installPackages( packages ):
  if manager_type == 'apt':
    chroot_execute( '/usr/bin/apt-get install -q -y {0}'.format( packages ) )
  elif manager_type == 'yum':
    chroot_execute( '/usr/bin/yum -y install {0}'.format( packages ) )
    chroot_execute( '/usr/bin/rpm --query {0}'.format( packages ) )  # yum does not return error if something does not exist, so check to see if what we saied we wanted installed is installed
  elif manager_type == 'zypper':
    chroot_execute( '/usr/bin/zypper --non-interactive install {0}'.format( packages ) )
Example #6
0
def preBaseSetup( profile ):
  renderTemplates( profile.get( 'packaging', 'prebase_templates' ).split( ',' ) )

  for item in profile.items( 'packaging' ):
    if item[0].startswith( 'install_env_var_' ):
      ( name, value ) = item[1].split( ':', 1 )
      chroot_env[ name ] = value  # tehinically we are affecting all the chroot commands, for now this is ok.

  if manager_type == 'apt':
    for item in profile.items( 'packaging' ):
      if item[0].startswith( 'selection_' ):
        chroot_execute( '/usr/bin/debconf-set-selections', item[1] )

  for item in profile.items( 'packaging' ):
    if item[0].startswith( 'prebase_cmd_' ):
      chroot_execute( item[1] )
Example #7
0
def configSources(install_root, profile, value_map):
    global manager_type
    manager_type = profile.get('packaging', 'manager_type')

    if manager_type not in ('apt', 'yum', 'zypper'):
        raise Exception(
            'Unknwon Packaging manager type "{0}"'.format(manager_type))

    if manager_type == 'yum':
        execute('ash -c "rm {0}/etc/yum.repos.d/*"'.format(install_root))

    key_uris = []
    for repo in value_map['repo_list']:
        if 'key_uri' in repo:
            if repo['type'] != manager_type:
                continue

            uri = repo['key_uri']
            if uri not in key_uris:
                try:
                    proxy = repo['proxy']
                except Exception:
                    proxy = None

                tmp = http_getfile(uri, proxy=proxy)

                if 'key_file' in repo:
                    key_file_path = '{0}/{1}'.format(install_root,
                                                     repo['key_file'])
                    if not os.path.isdir(os.path.dirname(key_file_path)):
                        os.makedirs(os.path.dirname(key_file_path))

                    open(key_file_path, 'wb').write(tmp)

                elif manager_type == 'apt':  # for binary keys, write it to a file ^
                    chroot_execute('/usr/bin/apt-key add -', tmp.decode())

                key_uris.append(uri)

    renderTemplates(profile.get('packaging', 'source_templates').split(','))

    print('Updating Repo Data...')
    if manager_type == 'apt':
        chroot_execute('/usr/bin/apt-get update')
Example #8
0
def installBase( install_root, profile ):
  if manager_type == 'apt':
    chroot_execute( '/usr/bin/apt-get install -q -y {0}'.format( profile.get( 'packaging', 'base' ) ) )

  elif manager_type == 'yum':
    chroot_execute( '/usr/bin/yum -y groupinstall {0}'.format( profile.get( 'packaging', 'base' ) ) )
    chroot_execute( '/usr/bin/yum -y reinstall yum centos-release' )  # find a better way to figure out what needs to be re-installed
    execute( 'ash -c "rm {0}/etc/yum.repos.d/*"'.format( install_root ) )  # clean up extra repos that some package might have left behind... this is the last time we will do this.... any package after this we will allow to keep their repos, we are really just after the base ones
    renderTemplates( profile.get( 'packaging', 'source_templates' ).split( ',' ) )

  elif manager_type == 'zypper':
    chroot_execute( '/usr/bin/zypper --non-interactive install {0}'.format( profile.get( 'packaging', 'base' ) ) )
Example #9
0
def cleanPackaging( install_root ):
  if manager_type == 'apt':
    chroot_execute( '/usr/bin/apt-get clean' )

  elif manager_type == 'yum':
    chroot_execute( '/usr/bin/yum clean all' )
    execute( '/bin/find {0} \( -path {0}/proc -o -path {0}/sys \) -prune -o -name *.rpmnew -exec rm {{}} \;'.format( install_root ) )
    execute( '/bin/find {0} \( -path {0}/proc -o -path {0}/sys \) -prune -o -name *.rpmsave -exec rm {{}} \;'.format( install_root ) )

  elif manager_type == 'zypper':
    chroot_execute( '/usr/bin/zypper --non-interactive clean' )
    execute( '/bin/find {0} \( -path {0}/proc -o -path {0}/sys \) -prune -o -name *.rpmnew -exec rm {{}} \;'.format( install_root ) )
    execute( '/bin/find {0} \( -path {0}/proc -o -path {0}/sys \) -prune -o -name *.rpmsave -exec rm {{}} \;'.format( install_root ) )
Example #10
0
installOtherPackages(profile, value_map)

contractor.postMessage('Installing Filesystem Utils...')
installFilesystemUtils(profile)

contractor.postMessage('Updating Packages...')
updatePackages()

updateConfig('bootloader', grubConfigValues(install_root))

contractor.postMessage('Writing Full Config...')
fullConfig()

for item in profile.items('general'):
    if item[0].startswith('after_cmd_'):
        chroot_execute(item[1])

contractor.postMessage('Post Install Scripts...')
postInstallScripts(install_root, value_map)

contractor.postMessage('Removing Diverts...')
undivert(profile)

contractor.postMessage('Cleaning up...')
cleanPackaging(install_root)

os.unlink('/target/config_data')

if os.access(os.path.join(install_root, 'usr/sbin/config-curator'), os.X_OK):
    contractor.postMessage('Running config-curator...')
    chroot_execute('/usr/sbin/config-curator -c -a -f -b')
Example #11
0
    contractor.postMessage('Installing Filesystem Utils...')
    installFilesystemUtils(profile)

    contractor.postMessage('Updating Packages...')
    updatePackages()

updateConfig('bootloader', grubConfigValues(install_root))

contractor.postMessage('Writing Full Config...')
fullConfig()

if not image_package:
    for item in profile.items('general'):
        if item[0].startswith('after_cmd_'):
            chroot_execute(item[1])

    contractor.postMessage('Post Install Scripts...')
    postInstallScripts(install_root, value_map)

    contractor.postMessage('Removing Diverts...')
    undivert(profile)

    contractor.postMessage('Cleaning up...')
    cleanPackaging(install_root)

else:
    contractor.postMessage('Setting Up Users....')
    setupUsers(install_root, profile, value_map)

    contractor.postMessage('Running Package Setup...')
Example #12
0
def bootstrap(mount_point, source,
              profile):  # TODO: bootstrap http proxy, also see misc
    bootstrap_type = profile.get('bootstrap', 'type')

    # debians copy over /etc/hostname and /etc/resolv.conf, but cent dosen't (SELS Unknown), and pre_base_cmd is chrooted, so for now we will do these here
    shutil.copyfile('/etc/hostname', os.path.join(mount_point, 'etc/hostname'))
    shutil.copyfile('/etc/resolv.conf',
                    os.path.join(mount_point, 'etc/resolv.conf'))

    try:
        packages = profile.get('bootstrap', 'packages')
    except NoOptionError:
        packages = ''

    if bootstrap_type == 'debbootstrap':
        if packages:
            execute(
                '/usr/sbin/debootstrap --arch amd64 --include {0} {1} {2} {3}'.
                format(packages, profile.get('bootstrap', 'distro'),
                       mount_point, source))
        else:
            execute('/usr/sbin/debootstrap --arch amd64 {0} {1} {2}'.format(
                profile.get('bootstrap', 'distro'), mount_point, source))

    elif bootstrap_type == 'squashimg':  # we should change this to using the squash fs as a intermediat step to do a boot strap from scratch https://wiki.centos.org/HowTos/ManualInstall
        version = profile.get('bootstrap', 'version')
        repo_root = '{0}{1}/os/x86_64/'.format(source, version)

        print('Getting Treeinfo...')
        execute('/bin/wget -O /tmp/treeinfo {0}.treeinfo'.format(repo_root))
        treeinfo = ConfigParser()
        treeinfo.read('/tmp/treeinfo')
        image = treeinfo.get('stage2', 'mainimage')
        print('   Stage 2 image "{0}"'.format(image))

        print('Downloading image...')
        execute('/bin/wget -O {0}/bootstrap.img {1}{2}'.format(
            mount_point, repo_root, image))

        print('Extractig image...')
        file_list = execute_lines(
            '/bin/unsquashfs -d . -ls {0}/bootstrap.img'.format(mount_point))
        execute(
            '/bin/unsquashfs -f -d {0} {0}/bootstrap.img'.format(mount_point))
        os.unlink('{0}/bootstrap.img'.format(mount_point))

        if file_list[-1] == './LiveOS/rootfs.img':  # Centos 7
            os.rename('{0}/LiveOS/rootfs.img'.format(mount_point),
                      '{0}/rootfs.img'.format(mount_point))
            os.rmdir('{0}/LiveOS'.format(mount_point))
            os.mkdir('/tmp/mnt')
            execute('/bin/mount -oloop,ro {0}/rootfs.img /tmp/mnt'.format(
                mount_point))
            execute('/bin/cp -ar /tmp/mnt/. {0}'.format(mount_point))
            execute('/bin/umount /tmp/mnt')
            os.unlink('{0}/rootfs.img'.format(mount_point))
            os.rmdir('/tmp/mnt')
            shutil.copyfile(
                '/etc/resolv.conf', os.path.join(
                    mount_point,
                    'etc/resolv.conf'))  # get's overwritten by the rootfs

        print('Retreiving Package List...')
        execute('/bin/wget -q -O /tmp/pkglist {0}Packages/'.format(repo_root))
        yum_match = re.compile('"(yum-[^"]*\.rpm)"')
        release_match = re.compile('"(centos-release-[^"]*\.rpm)"')
        yum_filename = None
        release_filename = None
        for line in open('/tmp/pkglist', 'r').readlines():
            tmp = yum_match.search(line)
            if tmp:
                yum_filename = tmp.group(1)

            tmp = release_match.search(line)
            if tmp:
                release_filename = tmp.group(1)

            if release_filename and yum_filename:
                break

        execute(
            'rm /tmp/pkglist'
        )  # if there are more packages installed here, make sure to update the list in packaging.py - installBase
        print('   YUM rpm filename "{0}"'.format(yum_filename))
        print('   release rpm filename "{0}"'.format(release_filename))

        print('Retreiving YUM...')
        execute('/bin/wget -q -O {0} {1}Packages/{2}'.format(
            os.path.join(mount_point, 'tmp.rpm'), repo_root, yum_filename))
        print('Instaing YUM...')
        chroot_execute('/usr/bin/rpm -i --nodeps /tmp.rpm')
        chroot_execute('rm /tmp.rpm')

        print('Retreiving Release...')
        execute('/bin/wget -q -O {0} {1}Packages/{2}'.format(
            os.path.join(mount_point, 'tmp.rpm'), repo_root, release_filename))
        print('Instaiing Release...')
        chroot_execute('/usr/bin/rpm -i --nodeps /tmp.rpm')
        chroot_execute('rm /tmp.rpm')

    else:
        raise Exception('Unknown "{0}" type'.format(bootstrap_type))
Example #13
0
def undivert(profile):
    if manager_type == 'apt':
        for (name, target) in divert_list:
            chroot_execute('rm {0}'.format(name))
            chroot_execute(
                '/usr/bin/dpkg-divert --rename --remove {0}'.format(name))
Example #14
0
def baseConfig( profile ):
  renderTemplates( profile.get( 'config', 'base_templates' ).split( ',' ) )
  try:
    chroot_execute( profile.get( 'config', 'base_cmd' ) )
  except NoOptionError:
    pass