コード例 #1
0
def update(filename, log):
    """ Invoked if the user has chosen to update his system """
    
    # Check if the platform is supported
    utils.check_platform_supported()
    
    # Check if the user is running with super-user priviliges
    utils.check_root()
    
    #FIXME: Unicode Fix
    # This is only a workaround.
    # When using locales, we get translation files. But apt doesn't extract the URI properly.
    # Once the extraction problem is root-caused, we can fix this easily.
    os.environ['__apt_set_update'] = filename
    try:
            old_environ = os.environ['LANG']
    except KeyError:
            old_environ = "C"
    os.environ['LANG'] = "C"
    log.verbose( "Set environment variable for LANG from %s to %s temporarily.\n" % ( old_environ, os.environ['LANG'] ) )
    if os.system( '/usr/bin/apt-get -qq --print-uris update >> $__apt_set_update' ) != 0:
            log.err( "FATAL: Something is wrong with the apt system.\n" )
            Bool_SetterErrors = True
    log.verbose( "Set environment variable for LANG back to its original from %s to %s.\n" % ( os.environ['LANG'], old_environ ) )
    os.environ['LANG'] = old_environ
コード例 #2
0
def install_packages(filename, install_packages_list, target_release, log):
    """ Invoked if the user wants to install packages """
    
    # Check if the platform is supported
    utils.check_platform_supported()
    
    # Check if the user is running with super-user priviliges
    utils.check_root()
    
    comma_sep_package_list = ", ".join(install_packages_list)
    log.msg( "\nGenerating database of package %s and its dependencies.\n" % (comma_sep_package_list) )
    
    package_list = " ".join(install_packages_list)
    os.environ['__apt_set_install_packages'] = package_list
    
    os.environ['__apt_set_install'] = filename
    
    # If the target release is specified, include it as -t switch
    if target_release:
        os.environ['__apt_set_install_release'] = target_release
        if os.system( '/usr/bin/apt-get -qq --print-uris -t $__apt_set_install_release install $__apt_set_install_packages >> $__apt_set_install' ) != 0:
            raise AptSystemBrokenError(APT_SYSTEM_BROKEN)
    else:
        #FIXME: Find a more Pythonic implementation
        if os.system( '/usr/bin/apt-get -qq --print-uris install $__apt_set_install_packages >> $__apt_set_install' ) != 0:
            raise AptSystemBrokenError(APT_SYSTEM_BROKEN)

    return True
コード例 #3
0
def upgrade(filename, upgrade_type, log):
    """ Invoked if the user wants to perform an upgrade """
    
    # Check if the platform is supported
    utils.check_platform_supported()
    
    # Check if the user is running with super-user priviliges
    utils.check_root()
    
    # Check if the provided upgrade type is valid or not
    utils.check_valid_upgrade_type(upgrade_type)
    
    if upgrade_type == "upgrade":
        res = upgrade_upgrade(filename ,log)
    elif upgrade_type == "dist-upgrade":
        res = upgrade_dist_upgrade(filename ,log)
    elif upgrade_type == "dselect-upgrade":
        res = upgrade_dist_upgrade(filename ,log)
        
    return res
コード例 #4
0
ファイル: luchizz.py プロジェクト: Dark-Vex/luchizz
def main():
    parser = OptionParser("usage: luchizz.py --host hosts [options]",
                          version="luchizz {}".format(__version__))
    parser.add_option("-H", "--hosts", dest="HOSTS",
                      help="comma-separated list of hosts to operate on",
                      type='string', metavar="HOSTS")
    parser.add_option("-p", "--packages-file", dest="PKGS_FILE",
                      help="yaml file for the debian packages you want to "
                      "install via apt-get",
                      type='string', metavar="PKGS_FILE")
    parser.add_option("-d", "--debug", dest="DEBUG",
                      help="all output from fabric", action='store_true',
                      default=False)
    (options, args) = parser.parse_args()

    # Setting up the target hosts
    if options.HOSTS:
        env.host_string = options.HOSTS.split(',')[0]

    # Setting up the default path for the packages yaml
    if not options.PKGS_FILE:
        options.PKGS_FILE = os.path.join(LUCHIZZ_DIR, 'packages.yaml')
    # Make sure the package file exists
    if os.path.isfile(options.PKGS_FILE):
        # get the dictionary from the yaml file
        p = open(options.PKGS_FILE, 'r')
        packages = yaml.load(p.read())
        p.close()
    else:
        print "IOError: packages file not found {}".format(options.PKGS_FILE)
        sys.exit(1)

    # Setting up fabric output for debug
    # FIXME here there are problem with the overrided options context managers
    # needs to be always used probably
    if options.DEBUG:
        to_set = {'aborts': True,
                  'debug': True,
                  'running': True,
                  'status': True,
                  'stderr': True,
                  'stdout': True,
                  'user': True,
                  'warnings': True}
    # Setting up fabric output for normal usage
    else:
        to_set = {'aborts': True,
                  'debug': False,
                  'running': False,
                  'status': False,
                  'stderr': False,
                  'stdout': True,
                  'user': False,
                  'warnings': True}
    # Apply the dictionary structure to the output handler of fabric
    for key in to_set.keys():
        fabric_output[key] = to_set[key]

    print_splash(__version__)
    with quiet():
        check_root()
    print("\nReady to luchizz: {}?\n"
          "CTRL-C to abort\n".format(env.host_string))
    time.sleep(1)

    # Setup etckeeper
    if not is_installed('etckeeper'):
        if query_yes_no("SETUP etckeeper to track changes in /etc "
                        "using git?", 'yes'):
            setup_etckeeper()

    # Luchizz the shell
    if query_yes_no("Do you want to `luchizz` root and all users "
                    "with a home folder in /home?", 'yes'):
        with quiet():
            luchizz_shell()
        # If luchizz shell is applied a dedicated commit is applied
        # 127 return code is in case etckeeper is not installed won't fail
        with settings(ok_ret_codes=(0, 1, 127)), quiet():
            sudo('etckeeper commit -m "luchizzed shell"')

    # Install luchizz scripts
    if query_yes_no("INSTALL luchizz scripts in /usr/local/bin?", 'yes'):
        with quiet():
            luchizz_scripts()

    # Copy ssh keys
    if query_yes_no("CONFIGURE local ssh keys as authorized for "
                    "authentication?", 'yes'):
        with quiet():
            set_authentication_keys()

    # Copy .gitconfig
    if os.path.isfile(os.path.join(os.getenv('HOME'), '.gitconfig')):
        if query_yes_no("CONFIGURE .gitconfig file from the local user?",
                        'yes'):
            with quiet():
                set_gitconfig()

    if query_yes_no("CONFIGURE do you want to luchizz the gitconfig for"
                    "local user?", 'yes'):
            with quiet():
                luchizz_gitconfig()

    # Disable backports
    if query_yes_no("DISABLE backports repositories?", 'yes'):
        with quiet():
            set_disable_backports()

    # Disable automatic installation of suggested and recommended packages
    if query_yes_no("DISABLE automatic installation of recommended packages?",
                    'yes'):
        with quiet():
            set_disable_recommended()

    for pkg_section in packages.keys():
        if query_yes_no("INSTALL {} packages?".format(pkg_section),
                        'yes'):
            install_packages(packages[pkg_section])

    # ~shorewall = query_yes_no("Do you want to install shorewall and setup "
    # ~"as one interface server?""", 'no')
    # ~if shorewall:
    # ~setup_shorewall_one_interface()

    # Catch all commit for etckeeper
    # 127 return code is in case etckeeper is not installed won't fail
    with settings(ok_ret_codes=(0, 1, 127)), quiet():
        sudo('etckeeper commit -m "final luchizz commit"')

    print "\nluchizz done"
    return 0