Example #1
0
def execute(name, config, root):
    hostname = config['hostname']

    hostname_file = os.path.join(root, 'etc/hostname')
    hosts_file = os.path.join(root, 'etc/hosts')

    with open(hostname_file, 'wb') as outfile:
        outfile.write(hostname)

    commons.replace_string_in_file(
        hosts_file, r'127\.0\.0\.1\s+localhost\s*\Z',
        '127.0.0.1\tlocalhost\n127.0.0.1\t' + hostname)
Example #2
0
def execute(name, config, root):
    hostname = config['hostname']

    hostname_file = os.path.join(root, 'etc/hostname')
    hosts_file = os.path.join(root, 'etc/hosts')

    with open(hostname_file, 'wb') as outfile:
        outfile.write(hostname.encode())

    pattern = r'(127\.0\.0\.1)(\s+)(localhost)\s*\Z'
    replace = r'\1\2\3\n\1\2' + hostname
    commons.replace_string_in_file(hosts_file, pattern, replace)
Example #3
0
def execute(installer):
    hostname = installer.install_config['hostname']

    installer.logger.info("Set /etc/hostname to " + hostname)
    hostname_file = os.path.join(installer.photon_root, 'etc/hostname')
    hosts_file    = os.path.join(installer.photon_root, 'etc/hosts')

    with open(hostname_file, 'wb') as outfile:
        outfile.write(hostname.encode())

    pattern = r'(127\.0\.0\.1)(\s+)(localhost)\s*\Z'
    replace = r'\1\2\3\n\1\2' + hostname
    commons.replace_string_in_file(hosts_file, pattern, replace)
Example #4
0
def execute(name, ks_config, config, root):

    if ks_config:
        config["hostname"] = ks_config["hostname"]
    hostname = config['hostname']

    hostname_file = os.path.join(root, 'etc/hostname')
    hosts_file = os.path.join(root, 'etc/hosts')

    with open(hostname_file,  'wb') as outfile:
    	outfile.write(hostname)

    commons.replace_string_in_file(hosts_file, r'127\.0\.0\.1\s+localhost', '127.0.0.1\tlocalhost\n127.0.0.1\t' + hostname)
Example #5
0
def execute(installer):
    shadow_password = installer.install_config['shadow_password']
    installer.logger.info("Set root password")

    passwd_filename = os.path.join(installer.photon_root, 'etc/passwd')
    shadow_filename = os.path.join(installer.photon_root, 'etc/shadow')

    #replace root blank password in passwd file to point to shadow file
    commons.replace_string_in_file(passwd_filename, "root::", "root:x:")

    if os.path.isfile(shadow_filename) == False:
        with open(shadow_filename, "w") as destination:
            destination.write("root:" + shadow_password + ":")
    else:
        #add password hash in shadow file
        commons.replace_string_in_file(shadow_filename, "root::",
                                       "root:" + shadow_password + ":")
        commons.replace_string_in_file(shadow_filename, "root:x:",
                                       "root:" + shadow_password + ":")

    installer.cmd.run_in_chroot(installer.photon_root, "/usr/sbin/pwconv")
    installer.cmd.run_in_chroot(installer.photon_root, "/usr/sbin/grpconv")

    if 'age' in installer.install_config.get('password', {}):
        age = installer.install_config['password']['age']
        login_defs_filename = os.path.join(installer.photon_root,
                                           'etc/login.defs')

        # Do not run 'chroot -R' from outside. It will not find nscd socket.
        if age == -1:
            installer.cmd.run_in_chroot(
                installer.photon_root,
                "chage -I -1 -m 0 -M 99999 -E -1 -W 7 root")
            commons.replace_string_in_file(login_defs_filename,
                                           r'(PASS_MAX_DAYS)\s+\d+\s*',
                                           'PASS_MAX_DAYS\t99999\n')
        elif age == 0:
            installer.cmd.run_in_chroot(installer.photon_root,
                                        "chage -d 0 root")
        else:
            installer.cmd.run_in_chroot(installer.photon_root,
                                        "chage -M {} root".format(age))
            commons.replace_string_in_file(login_defs_filename,
                                           r'(PASS_MAX_DAYS)\s+\d+\s*',
                                           'PASS_MAX_DAYS\t{}\n'.format(age))
def execute(name, ks_config, config, root):

    if ks_config:
        if "hostname" in ks_config:
            config['hostname'] = ks_config["hostname"].strip(" ")
        if "hostname" not in config or config['hostname'] == "":
            random_id = '%12x' % random.randrange(16**12)
            config['hostname'] = "photon-" + random_id.strip()

    hostname = config['hostname']

    hostname_file = os.path.join(root, 'etc/hostname')
    hosts_file = os.path.join(root, 'etc/hosts')

    with open(hostname_file,  'wb') as outfile:
        outfile.write(hostname)

    commons.replace_string_in_file(hosts_file, r'127\.0\.0\.1\s+localhost\s*\Z', '127.0.0.1\tlocalhost\n127.0.0.1\t' + hostname)
Example #7
0
def execute(name, ks_config, config, root):

    if ks_config:
        if "hostname" in ks_config:
            config['hostname'] = ks_config["hostname"].strip(" ")
        if "hostname" not in config or config['hostname'] == "":
            random_id = '%12x' % random.randrange(16**12)
            config['hostname'] = "photon-" + random_id.strip()

    hostname = config['hostname']

    hostname_file = os.path.join(root, 'etc/hostname')
    hosts_file = os.path.join(root, 'etc/hosts')

    with open(hostname_file, 'wb') as outfile:
        outfile.write(hostname)

    commons.replace_string_in_file(
        hosts_file, r'127\.0\.0\.1\s+localhost\s*\Z',
        '127.0.0.1\tlocalhost\n127.0.0.1\t' + hostname)
Example #8
0
def execute(name, ks_config, config, root):

    if ks_config:
        # crypt the password if needed
        if ks_config['password']['crypted']:
            config['password'] = ks_config['password']['text']
        else:
            config['password'] = crypt.crypt(
                ks_config['password']['text'], "$6$" + "".join([
                    random.choice(string.ascii_letters + string.digits)
                    for _ in range(16)
                ]))

    shadow_password = config['password']

    passwd_filename = os.path.join(root, 'etc/passwd')
    shadow_filename = os.path.join(root, 'etc/shadow')

    #replace root blank password in passwd file to point to shadow file
    commons.replace_string_in_file(passwd_filename, "root::", "root:x:")

    if os.path.isfile(shadow_filename) == False:
        with open(shadow_filename, "w") as destination:
            destination.write("root:" + shadow_password + ":")
    else:
        #add password hash in shadow file
        commons.replace_string_in_file(shadow_filename, "root::",
                                       "root:" + shadow_password + ":")
        commons.replace_string_in_file(shadow_filename, "root:x:",
                                       "root:" + shadow_password + ":")
def execute(name, ks_config, config, root):

    if ks_config:
        # crypt the password if needed
        if ks_config['password']['crypted']:
            config['password'] = ks_config['password']['text']
        else:
            config['password'] = crypt.crypt(ks_config['password']['text'], 
                "$6$" + "".join([random.choice(string.ascii_letters + string.digits) for _ in range(16)]))
    
    shadow_password = config['password']

    passwd_filename = os.path.join(root, 'etc/passwd')
    shadow_filename = os.path.join(root, 'etc/shadow')
    
    #replace root blank password in passwd file to point to shadow file
    commons.replace_string_in_file(passwd_filename,  "root::", "root:x:")

    if os.path.isfile(shadow_filename) == False:
        with open(shadow_filename, "w") as destination:
            destination.write("root:"+shadow_password+":")
    else:
        #add password hash in shadow file
        commons.replace_string_in_file(shadow_filename, "root::", "root:"+shadow_password+":")
        commons.replace_string_in_file(shadow_filename, "root:x:", "root:"+shadow_password+":")
Example #10
0
def execute(config, root):
    shadow_password = config['password']

    passwd_filename = os.path.join(root, 'etc/passwd')
    shadow_filename = os.path.join(root, 'etc/shadow')

    #replace root blank password in passwd file to point to shadow file
    commons.replace_string_in_file(passwd_filename, "root::", "root:x:")

    if os.path.isfile(shadow_filename) == False:
        with open(shadow_filename, "w") as destination:
            destination.write("root:" + shadow_password + ":")
    else:
        #add password hash in shadow file
        commons.replace_string_in_file(shadow_filename, "root::", "root:"+shadow_password+":")
        commons.replace_string_in_file(shadow_filename, "root:x:", "root:"+shadow_password+":")
Example #11
0
def execute(installer):
    shadow_password = installer.install_config['password']
    installer.logger.info("Set root password")

    passwd_filename = os.path.join(installer.photon_root, 'etc/passwd')
    shadow_filename = os.path.join(installer.photon_root, 'etc/shadow')

    #replace root blank password in passwd file to point to shadow file
    commons.replace_string_in_file(passwd_filename, "root::", "root:x:")

    if os.path.isfile(shadow_filename) == False:
        with open(shadow_filename, "w") as destination:
            destination.write("root:" + shadow_password + ":")
    else:
        #add password hash in shadow file
        commons.replace_string_in_file(shadow_filename, "root::", "root:"+shadow_password+":")
        commons.replace_string_in_file(shadow_filename, "root:x:", "root:"+shadow_password+":")