def configure_system(self): """ Final install steps Set clock, language, timezone Run mkinitcpio Populate pacman keyring Setup systemd services ... and more """ # First and last thing we do here mounting/unmouting special dirs. chroot.mount_special_dirs(DEST_DIR) self.queue_event('pulse', 'start') self.queue_event('action', _("Configuring your new system")) self.auto_fstab() logging.debug(_('fstab file generated.')) # Copy configured networks in Live medium to target system if self.network_manager == 'NetworkManager': self.copy_network_config() logging.debug(_('Network configuration copied.')) # enable services # self.enable_services([self.network_manager]) # cups_service = os.path.join(DEST_DIR, "usr/lib/systemd/system/org.cups.cupsd.service") # if os.path.exists(cups_service): # self.enable_services(['org.cups.cupsd'])""" # enable targets # self.enable_targets(['remote-fs.target']) # logging.debug('Enabled installed services.') # Wait FOREVER until the user sets the timezone while self.settings.get('timezone_done') is False: # wait five seconds and try again time.sleep(5) if self.settings.get("use_ntp"): self.enable_services(["ntpd"]) # Set timezone zoneinfo_path = os.path.join("/usr/share/zoneinfo", self.settings.get("timezone_zone")) chroot_run(['ln', '-s', zoneinfo_path, "/etc/localtime"]) logging.debug(_('Time zone set.')) # Wait FOREVER until the user sets his params while self.settings.get('user_info_done') is False: # wait five seconds and try again time.sleep(5) # Set user parameters username = self.settings.get('username') fullname = self.settings.get('fullname') password = self.settings.get('password') root_password = self.settings.get('root_password') hostname = self.settings.get('hostname') sudoers_path = os.path.join(DEST_DIR, "etc/sudoers.d/10-installer") with open(sudoers_path, "w") as sudoers: sudoers.write('{0} ALL=(ALL) ALL\n'.format(username)) subprocess.check_call(["chmod", "440", sudoers_path]) logging.debug(_('Sudo configuration for user {0} done.'.format(username))) default_groups = 'lp,video,network,storage,wheel,audio' if self.settings.get('require_password') is False: chroot_run(['groupadd', 'autologin']) default_groups += ',autologin' chroot_run(['useradd', '-m', '-s', '/bin/bash', '-g', 'users', '-G', default_groups, username]) logging.debug(_('User {0} added.'.format(username))) self.change_user_password(username, password) chroot_run(['chfn', '-f', fullname, username]) chroot_run(['chown', '-R', '{0}:users'.format(username), "/home/{0}".format(username)]) hostname_path = os.path.join(DEST_DIR, "etc/hostname") with open(hostname_path, "w") as hostname_file: hostname_file.write(hostname) logging.debug(_('Hostname {0} set.'.format(hostname))) # Set root password if root_password is not '': self.change_user_password('root', root_password) logging.debug(_('Set root password.')) else: self.change_user_password('root', password) logging.debug(_('Set the same password to root.')) # Generate locales locale = self.settings.get("locale") self.queue_event('info', _("Generating locales ...")) self.uncomment_locale_gen(locale) chroot_run(['locale-gen']) locale_conf_path = os.path.join(DEST_DIR, "etc/locale.conf") with open(locale_conf_path, "w") as locale_conf: locale_conf.write('LANG={0}\n'.format(locale)) keyboard_layout = self.settings.get("keyboard_layout") keyboard_variant = self.settings.get("keyboard_variant") # Set /etc/vconsole.conf vconsole_conf_path = os.path.join(DEST_DIR, "etc/vconsole.conf") with open(vconsole_conf_path, "w") as vconsole_conf: vconsole_conf.write('KEYMAP={0}\n'.format(keyboard_layout)) # Write xorg keyboard configuration xorg_conf_dir = os.path.join(DEST_DIR, "etc/X11/xorg.conf.d") os.makedirs(xorg_conf_dir, exist_ok=True) fname = "{0}/etc/X11/xorg.conf.d/00-keyboard.conf".format(DEST_DIR) with open(fname, 'w') as file: default_keyboard_layout = "us" default_keyboard_model = "pc105" if keyboard_layout == default_keyboard_layout: xkblayout = "{}".format(keyboard_layout) xkbvariant = "{}".format(keyboard_variant) else: xkblayout = "{},{}".format(keyboard_layout, default_keyboard_layout) xkbvariant = "{},".format(keyboard_variant) file.write("\n" "Section \"InputClass\"\n" " Identifier \"system-keyboard\"\n" " MatchIsKeyboard \"on\"\n" " Option \"XkbLayout\" \"{}\"\n" " Option \"XkbModel\" \"{}\"\n" " Option \"XkbVariant\" \"{}\"\n" " Option \"XkbOptions\" \"{}\"\n" "EndSection\n" .format(xkblayout, default_keyboard_model, xkbvariant, "terminate:ctrl_alt_bksp,grp:alt_shift_toggle")) self.queue_event('info', _("Adjusting hardware clock ...")) self.auto_timesetting() # Install configs for root # chroot_run(['cp', '-av', '/etc/skel/.', '/root/']) self.queue_event('info', _("Configuring hardware ...")) # Configure ALSA self.alsa_mixer_setup() logging.debug(_("Updated Alsa mixer settings")) '''# Set pulse if os.path.exists(os.path.join(DEST_DIR, "usr/bin/pulseaudio-ctl")): chroot_run(['pulseaudio-ctl', 'set', '75%'])''' # Install xf86-video driver if os.path.exists("/opt/livecd/pacman-gfx.conf"): self.queue_event('info', _("Installing drivers ...")) mhwd_script_path = os.path.join(self.settings.get("thus"), "scripts", MHWD_SCRIPT) try: subprocess.check_call(["/usr/bin/bash", mhwd_script_path]) logging.debug("Finished installing drivers.") except subprocess.CalledProcessError as e: txt = "CalledProcessError.output = {0}".format(e.output) logging.error(txt) self.queue_fatal_event(txt) return False self.queue_event('info', _("Configure display manager ...")) # Setup slim if os.path.exists("/usr/bin/slim"): self.desktop_manager = 'slim' # Setup sddm if os.path.exists("/usr/bin/sddm"): self.desktop_manager = 'sddm' # setup lightdm if os.path.exists("{0}/usr/bin/lightdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() if default_desktop_environment is not None: os.system("sed -i -e 's/^.*user-session=.*/user-session={0}/' \ {1}/etc/lightdm/lightdm.conf".format(default_desktop_environment.desktop_file, DEST_DIR)) os.system("ln -s /usr/lib/lightdm/lightdm/gdmflexiserver {0}/usr/bin/gdmflexiserver".format(DEST_DIR)) os.system("chmod +r {0}/etc/lightdm/lightdm.conf".format(DEST_DIR)) self.desktop_manager = 'lightdm' # Setup gdm if os.path.exists("{0}/usr/bin/gdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() if default_desktop_environment is not None: os.system("echo \"XSession={0}\" >> \ {1}/var/lib/AccountsService/users/gdm".format(default_desktop_environment.desktop_file, DEST_DIR)) os.system("echo \"Icon=\" >> {0}/var/lib/AccountsService/users/gdm".format(DEST_DIR)) self.desktop_manager = 'gdm' # Setup mdm if os.path.exists("{0}/usr/bin/mdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() if default_desktop_environment is not None: os.system("sed -i 's|default.desktop|{0}.desktop|g' \ {1}/etc/mdm/custom.conf".format(default_desktop_environment.desktop_file, DEST_DIR)) self.desktop_manager = 'mdm' # Setup lxdm if os.path.exists("{0}/usr/bin/lxdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() if default_desktop_environment is not None: os.system("sed -i -e 's|^.*session=.*|session={0}|' \ {1}/etc/lxdm/lxdm.conf".format(default_desktop_environment.executable, DEST_DIR)) self.desktop_manager = 'lxdm' # Setup kdm if os.path.exists("{0}/usr/bin/kdm".format(DEST_DIR)): self.desktop_manager = 'kdm' self.queue_event('info', _("Configure System ...")) # Add BROWSER var os.system("echo \"BROWSER=/usr/bin/xdg-open\" >> {0}/etc/environment".format(DEST_DIR)) os.system("echo \"BROWSER=/usr/bin/xdg-open\" >> {0}/etc/skel/.bashrc".format(DEST_DIR)) os.system("echo \"BROWSER=/usr/bin/xdg-open\" >> {0}/etc/profile".format(DEST_DIR)) # Add TERM var if os.path.exists("{0}/usr/bin/mate-session".format(DEST_DIR)): os.system("echo \"TERM=mate-terminal\" >> {0}/etc/environment".format(DEST_DIR)) os.system("echo \"TERM=mate-terminal\" >> {0}/etc/profile".format(DEST_DIR)) # Adjust Steam-Native when libudev.so.0 is available if (os.path.exists("{0}/usr/lib/libudev.so.0".format(DEST_DIR)) or os.path.exists("{0}/usr/lib32/libudev.so.0".format(DEST_DIR))): os.system("echo -e \"STEAM_RUNTIME=0\nSTEAM_FRAME_FORCE_CLOSE=1\" >> {0}/etc/environment".format(DEST_DIR)) # Remove thus if os.path.exists("{0}/usr/bin/thus".format(DEST_DIR)): self.queue_event('info', _("Removing live configuration (packages)")) chroot_run(['pacman', '-R', '--noconfirm', 'thus']) # Remove virtualbox driver on real hardware p1 = subprocess.Popen(["mhwd"], stdout=subprocess.PIPE) p2 = subprocess.Popen(["grep", "0300:80ee:beef"], stdin=p1.stdout, stdout=subprocess.PIPE) num_res = p2.communicate()[0] if num_res == "0": chroot_run(['sh', '-c', 'pacman -Rsc --noconfirm $(pacman -Qq | grep virtualbox-guest-modules)']) # Set unique machine-id chroot_run(['dbus-uuidgen', '--ensure=/etc/machine-id']) chroot_run(['dbus-uuidgen', '--ensure=/var/lib/dbus/machine-id']) # Setup pacman self.queue_event("action", _("Configuring package manager")) # Copy mirror list shutil.copy2('/etc/pacman.d/mirrorlist', os.path.join(DEST_DIR, 'etc/pacman.d/mirrorlist')) # Copy random generated keys by pacman-init to target if os.path.exists("{0}/etc/pacman.d/gnupg".format(DEST_DIR)): os.system("rm -rf {0}/etc/pacman.d/gnupg".format(DEST_DIR)) os.system("cp -a /etc/pacman.d/gnupg {0}/etc/pacman.d/".format(DEST_DIR)) chroot_run(['pacman-key', '--populate', 'archlinux', 'manjaro']) self.queue_event('info', _("Finished configuring package manager.")) # Workaround for pacman-key bug FS#45351 https://bugs.archlinux.org/task/45351 # We have to kill gpg-agent because if it stays around we can't reliably unmount # the target partition. chroot_run(['killall', '-9', 'gpg-agent']) # Let's start without using hwdetect for mkinitcpio.conf. # I think it should work out of the box most of the time. # This way we don't have to fix deprecated hooks. # NOTE: With LUKS or LVM maybe we'll have to fix deprecated hooks. self.queue_event('info', _("Running mkinitcpio ...")) mkinitcpio.run(DEST_DIR, self.settings, self.mount_devices, self.blvm) self.queue_event('info', _("Running mkinitcpio - done")) # Set autologin if selected # In openbox "desktop", the post-install script writes /etc/slim.conf # so we always have to call set_autologin AFTER the post-install script. if self.settings.get('require_password') is False: self.set_autologin() # Encrypt user's home directory if requested # FIXME: This is not working atm if self.settings.get('encrypt_home'): logging.debug(_("Encrypting user home dir...")) encfs.setup(username, DEST_DIR) logging.debug(_("User home dir encrypted")) # Install boot loader (always after running mkinitcpio) if self.settings.get('bootloader_install'): try: self.queue_event('info', _("Installing bootloader...")) from installation import bootloader boot_loader = bootloader.Bootloader(DEST_DIR, self.settings, self.mount_devices) boot_loader.install() except Exception as error: logging.error(_("Couldn't install boot loader: {0}" .format(error))) self.queue_event('pulse', 'stop') chroot.umount_special_dirs(DEST_DIR)
def install_gummiboot(self): """ Install Gummiboot bootloader to the EFI System Partition """ # Setup bootloader menu menu_dir = os.path.join(self.dest_dir, "boot/loader") os.makedirs(menu_dir) menu_path = os.path.join(menu_dir, "loader.conf") with open(menu_path, 'w') as menu_file: menu_file.write("default apricity") # Setup boot entries conf = {} if not self.settings.get('use_luks'): conf['default'] = [] conf['default'].append("title\tApricity\n") conf['default'].append("linux\t/vmlinuz-linux\n") conf['default'].append("initrd\t/initramfs-linux.img\n") conf['default'].append("options\troot=UUID={0} rw quiet\n\n".format(self.root_uuid)) conf['fallback'] = [] conf['fallback'].append("title\tApricity (fallback)\n") conf['fallback'].append("linux\t/vmlinuz-linux\n") conf['fallback'].append("initrd\t/initramfs-linux-fallback.img\n") conf['fallback'].append("options\troot=UUID={0} rw quiet\n\n".format(self.root_uuid)) if self.settings.get('feature_lts'): conf['lts'] = [] conf['lts'].append("title\tApricity LTS\n") conf['lts'].append("linux\t/vmlinuz-linux-lts\n") conf['lts'].append("initrd\t/initramfs-linux-lts.img\n") conf['lts'].append("options\troot=UUID={0} rw quiet\n\n".format(self.root_uuid)) conf['lts_fallback'] = [] conf['lts_fallback'].append("title\tApricity LTS (fallback)\n\n") conf['lts_fallback'].append("linux\t/vmlinuz-linux-lts\n") conf['lts_fallback'].append("initrd\t/initramfs-linux-lts-fallback.img\n") conf['lts_fallback'].append("options\troot=UUID={0} rw quiet\n\n".format(self.root_uuid)) else: luks_root_volume = self.settings.get('luks_root_volume') luks_root_volume_device = "/dev/mapper/{0}".format(luks_root_volume) luks_root_volume_uuid = fs.get_info(luks_root_volume_device)['UUID'] # In automatic mode, root_device is in self.mount_devices, as it should be root_device = self.root_device if self.method == "advanced" and self.settings.get('use_luks_in_root'): root_device = self.settings.get('luks_root_device') root_uuid = fs.get_info(root_device)['UUID'] key = "" if self.settings.get("luks_root_password") == "": key = "cryptkey=UUID={0}:ext2:/.keyfile-root".format(self.boot_uuid) root_uuid_line = "cryptdevice=UUID={0}:{1} {2} root=UUID={3} rw quiet" root_uuid_line = root_uuid_line.format(root_uuid, luks_root_volume, key, luks_root_volume_uuid) conf['default'] = [] conf['default'].append("title\tApricity\n") conf['default'].append("linux\t/vmlinuz-linux\n") conf['default'].append("options\tinitrd=/initramfs-linux.img {0}\n\n".format(root_uuid_line)) conf['fallback'] = [] conf['fallback'].append("title\tApricity (fallback)\n") conf['fallback'].append("linux\t/vmlinuz-linux\n") conf['fallback'].append("options\tinitrd=/initramfs-linux-fallback.img {0}\n\n".format(root_uuid_line)) if self.settings.get('feature_lts'): conf['lts'] = [] conf['lts'].append("title\tApricity LTS\n") conf['lts'].append("linux\t/vmlinuz-linux-lts\n") conf['lts'].append("options\tinitrd=/initramfs-linux-lts.img {0}\n\n".format(root_uuid_line)) conf['lts_fallback'] = [] conf['lts_fallback'].append("title\tApricity LTS (fallback)\n") conf['lts_fallback'].append("linux\t/vmlinuz-linux-lts\n") conf['lts_fallback'].append("options\tinitrd=/initramfs-linux-lts-fallback.img {0}\n\n".format(root_uuid_line)) # Write boot entries entries_dir = os.path.join(self.dest_dir, "boot/loader/entries") os.makedirs(entries_dir) entry_path = os.path.join(entries_dir, "apricity.conf") with open(entry_path, 'w') as entry_file: for line in conf['default']: entry_file.write(line) entry_path = os.path.join(entries_dir, "apricity-fallback.conf") with open(entry_path, 'w') as entry_file: for line in conf['fallback']: entry_file.write(line) if self.settings.get('feature_lts'): entry_path = os.path.join(entries_dir, "apricity-lts.conf") with open(entry_path, 'w') as entry_file: for line in conf['lts']: entry_file.write(line) entry_path = os.path.join(entries_dir, "apricity-lts-fallback.conf") with open(entry_path, 'w') as entry_file: for line in conf['lts_fallback']: entry_file.write(line) # Install bootloader logging.debug(_("Installing gummiboot bootloader...")) try: chroot.mount_special_dirs(self.dest_dir) cmd = ['gummiboot', '--path=/boot', 'install'] chroot.run(cmd, self.dest_dir, 300) chroot.umount_special_dirs(self.dest_dir) logging.info(_("Gummiboot install completed successfully")) self.settings.set('bootloader_installation_successful', True) except subprocess.CalledProcessError as process_error: logging.error(_('Command gummiboot failed. Error output: %s'), process_error.output) self.settings.set('bootloader_installation_successful', False) except subprocess.TimeoutExpired: logging.error(_('Command gummiboot timed out.')) self.settings.set('bootloader_installation_successful', False) except Exception as general_error: logging.error(_('Command gummiboot failed. Unknown Error: %s'), general_error) self.settings.set('bootloader_installation_successful', False)
def configure_system(self): """ Final install steps Set clock, language, timezone Run mkinitcpio Populate pacman keyring Setup systemd services ... and more """ # First and last thing we do here mounting/unmouting special dirs. chroot.mount_special_dirs(DEST_DIR) self.queue_event('pulse', 'start') self.queue_event('action', _("Configuring your new system")) self.auto_fstab() logging.debug(_('fstab file generated.')) # Copy configured networks in Live medium to target system if self.network_manager == 'NetworkManager': self.copy_network_config() logging.debug(_('Network configuration copied.')) # enable services # self.enable_services([self.network_manager]) # cups_service = os.path.join(DEST_DIR, "usr/lib/systemd/system/org.cups.cupsd.service") # if os.path.exists(cups_service): # self.enable_services(['org.cups.cupsd'])""" # enable targets # self.enable_targets(['remote-fs.target']) # logging.debug('Enabled installed services.') # Wait FOREVER until the user sets the timezone while self.settings.get('timezone_done') is False: # wait five seconds and try again time.sleep(5) if self.settings.get("use_ntp"): self.enable_services(["ntpd"]) # Set timezone zoneinfo_path = os.path.join("/usr/share/zoneinfo", self.settings.get("timezone_zone")) chroot_run(['ln', '-s', zoneinfo_path, "/etc/localtime"]) logging.debug(_('Time zone set.')) # Wait FOREVER until the user sets his params while self.settings.get('user_info_done') is False: # wait five seconds and try again time.sleep(5) # Set user parameters username = self.settings.get('username') fullname = self.settings.get('fullname') password = self.settings.get('password') root_password = self.settings.get('root_password') hostname = self.settings.get('hostname') sudoers_path = os.path.join(DEST_DIR, "etc/sudoers.d/10-installer") with open(sudoers_path, "w") as sudoers: sudoers.write('{0} ALL=(ALL) ALL\n'.format(username)) subprocess.check_call(["chmod", "440", sudoers_path]) logging.debug( _('Sudo configuration for user {0} done.'.format(username))) default_groups = 'lp,video,network,storage,wheel,users' if self.settings.get('require_password') is False: chroot_run(['groupadd', 'autologin']) default_groups += ',autologin' chroot_run([ 'useradd', '-m', '-s', '/bin/bash', '-U', '-G', default_groups, username ]) logging.debug(_('User {0} added.'.format(username))) self.change_user_password(username, password) chroot_run(['chfn', '-f', fullname, username]) chroot_run([ 'chown', '-R', '{0}:{1}'.format(username, username), "/home/{0}".format(username) ]) hostname_path = os.path.join(DEST_DIR, "etc/hostname") with open(hostname_path, "w") as hostname_file: hostname_file.write(hostname) logging.debug(_('Hostname {0} set.'.format(hostname))) # Set root password if root_password is not '': self.change_user_password('root', root_password) logging.debug(_('Set root password.')) else: self.change_user_password('root', password) logging.debug(_('Set the same password to root.')) # Generate locales locale = self.settings.get("locale") self.queue_event('info', _("Generating locales ...")) self.uncomment_locale_gen(locale) chroot_run(['locale-gen']) locale_conf_path = os.path.join(DEST_DIR, "etc/locale.conf") with open(locale_conf_path, "w") as locale_conf: locale_conf.write('LANG={0}\n'.format(locale)) keyboard_layout = self.settings.get("keyboard_layout") keyboard_variant = self.settings.get("keyboard_variant") # Set /etc/vconsole.conf vconsole_conf_path = os.path.join(DEST_DIR, "etc/vconsole.conf") with open(vconsole_conf_path, "w") as vconsole_conf: vconsole_conf.write('KEYMAP={0}\n'.format(keyboard_layout)) # Write xorg keyboard configuration xorg_conf_dir = os.path.join(DEST_DIR, "etc/X11/xorg.conf.d") os.makedirs(xorg_conf_dir, exist_ok=True) fname = "{0}/etc/X11/xorg.conf.d/00-keyboard.conf".format(DEST_DIR) with open(fname, 'w') as file: default_keyboard_layout = "us" default_keyboard_model = "pc105" if keyboard_layout == default_keyboard_layout: xkblayout = "{}".format(keyboard_layout) xkbvariant = "{}".format(keyboard_variant) else: xkblayout = "{},{}".format(keyboard_layout, default_keyboard_layout) xkbvariant = "{},".format(keyboard_variant) file.write("\n" "Section \"InputClass\"\n" " Identifier \"system-keyboard\"\n" " MatchIsKeyboard \"on\"\n" " Option \"XkbLayout\" \"{}\"\n" " Option \"XkbModel\" \"{}\"\n" " Option \"XkbVariant\" \"{}\"\n" " Option \"XkbOptions\" \"{}\"\n" "EndSection\n".format( xkblayout, default_keyboard_model, xkbvariant, "terminate:ctrl_alt_bksp,grp:alt_shift_toggle")) self.queue_event('info', _("Adjusting hardware clock ...")) self.auto_timesetting() # Install configs for root # chroot_run(['cp', '-av', '/etc/skel/.', '/root/']) self.queue_event('info', _("Configuring hardware ...")) # Configure ALSA self.alsa_mixer_setup() logging.debug(_("Updated Alsa mixer settings")) '''# Set pulse if os.path.exists(os.path.join(DEST_DIR, "usr/bin/pulseaudio-ctl")): chroot_run(['pulseaudio-ctl', 'set', '75%'])''' if os.path.exists("/opt/livecd"): repo_path = "/opt/livecd/pacman-gfx.conf" else: repo_path = "/opt/live/pacman-gfx.conf" # Install xf86-video driver if os.path.exists(repo_path): self.queue_event('info', _("Installing drivers ...")) mhwd_script_path = os.path.join(self.settings.get("thus"), "scripts", MHWD_SCRIPT) try: subprocess.check_call(["/usr/bin/bash", mhwd_script_path]) logging.debug("Finished installing drivers.") except subprocess.CalledProcessError as e: txt = "CalledProcessError.output = {0}".format(e.output) logging.error(txt) self.queue_fatal_event(txt) return False self.queue_event('info', _("Configure display manager ...")) # Setup slim if os.path.exists("/usr/bin/slim"): self.desktop_manager = 'slim' # Setup sddm if os.path.exists("/usr/bin/sddm"): self.desktop_manager = 'sddm' # setup lightdm if os.path.exists("{0}/usr/bin/lightdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() if default_desktop_environment is not None: os.system("sed -i -e 's/^.*user-session=.*/user-session={0}/' \ {1}/etc/lightdm/lightdm.conf".format( default_desktop_environment.desktop_file, DEST_DIR)) os.system( "ln -s /usr/lib/lightdm/lightdm/gdmflexiserver {0}/usr/bin/gdmflexiserver" .format(DEST_DIR)) os.system("chmod +r {0}/etc/lightdm/lightdm.conf".format(DEST_DIR)) self.desktop_manager = 'lightdm' # Setup gdm if os.path.exists("{0}/usr/bin/gdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() os.system( "echo \"[User]\" > {0}/var/lib/AccountsService/users/{1}". format(DEST_DIR, username)) if default_desktop_environment is not None: os.system("echo \"XSession={0}\" >> \ {1}/var/lib/AccountsService/users/{2}".format( default_desktop_environment.desktop_file, DEST_DIR, username)) os.system( "echo \"Icon=\" >> {0}/var/lib/AccountsService/users/{1}". format(DEST_DIR, username)) self.desktop_manager = 'gdm' # Setup mdm if os.path.exists("{0}/usr/bin/mdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() if default_desktop_environment is not None: os.system("sed -i 's|default.desktop|{0}.desktop|g' \ {1}/etc/mdm/custom.conf".format( default_desktop_environment.desktop_file, DEST_DIR)) self.desktop_manager = 'mdm' # Setup lxdm if os.path.exists("{0}/usr/bin/lxdm".format(DEST_DIR)): default_desktop_environment = self.find_desktop_environment() if default_desktop_environment is not None: os.system("sed -i -e 's|^.*session=.*|session={0}|' \ {1}/etc/lxdm/lxdm.conf".format( default_desktop_environment.executable, DEST_DIR)) self.desktop_manager = 'lxdm' # Setup kdm if os.path.exists("{0}/usr/bin/kdm".format(DEST_DIR)): self.desktop_manager = 'kdm' self.queue_event('info', _("Configure System ...")) # Adjust Steam-Native when libudev.so.0 is available if (os.path.exists("{0}/usr/lib/libudev.so.0".format(DEST_DIR)) or os.path.exists("{0}/usr/lib32/libudev.so.0".format(DEST_DIR))): os.system( "echo -e \"STEAM_RUNTIME=0\nSTEAM_FRAME_FORCE_CLOSE=1\" >> {0}/etc/environment" .format(DEST_DIR)) # Remove thus if os.path.exists("{0}/usr/bin/thus".format(DEST_DIR)): self.queue_event('info', _("Removing live configuration (packages)")) chroot_run(['pacman', '-R', '--noconfirm', 'thus']) # Remove virtualbox driver on real hardware p1 = subprocess.Popen(["mhwd"], stdout=subprocess.PIPE) p2 = subprocess.Popen(["grep", "0300:80ee:beef"], stdin=p1.stdout, stdout=subprocess.PIPE) num_res = p2.communicate()[0] if num_res == "0": chroot_run([ 'sh', '-c', 'pacman -Rsc --noconfirm $(pacman -Qq | grep virtualbox-guest-modules)' ]) # Set unique machine-id chroot_run(['dbus-uuidgen', '--ensure=/etc/machine-id']) chroot_run(['dbus-uuidgen', '--ensure=/var/lib/dbus/machine-id']) # Setup pacman self.queue_event("action", _("Configuring package manager")) # Copy mirror list shutil.copy2('/etc/pacman.d/mirrorlist', os.path.join(DEST_DIR, 'etc/pacman.d/mirrorlist')) # Copy random generated keys by pacman-init to target if os.path.exists("{0}/etc/pacman.d/gnupg".format(DEST_DIR)): os.system("rm -rf {0}/etc/pacman.d/gnupg".format(DEST_DIR)) os.system( "cp -a /etc/pacman.d/gnupg {0}/etc/pacman.d/".format(DEST_DIR)) chroot_run(['pacman-key', '--populate', 'archlinux', 'manjaro']) self.queue_event('info', _("Finished configuring package manager.")) # Workaround for pacman-key bug FS#45351 https://bugs.archlinux.org/task/45351 # We have to kill gpg-agent because if it stays around we can't reliably unmount # the target partition. chroot_run(['killall', '-9', 'gpg-agent']) # Let's start without using hwdetect for mkinitcpio.conf. # I think it should work out of the box most of the time. # This way we don't have to fix deprecated hooks. # NOTE: With LUKS or LVM maybe we'll have to fix deprecated hooks. self.queue_event('info', _("Running mkinitcpio ...")) mkinitcpio.run(DEST_DIR, self.settings, self.mount_devices, self.blvm) self.queue_event('info', _("Running mkinitcpio - done")) # Set autologin if selected # In openbox "desktop", the post-install script writes /etc/slim.conf # so we always have to call set_autologin AFTER the post-install script. if self.settings.get('require_password') is False: self.set_autologin() # Encrypt user's home directory if requested # FIXME: This is not working atm if self.settings.get('encrypt_home'): logging.debug(_("Encrypting user home dir...")) encfs.setup(username, DEST_DIR) logging.debug(_("User home dir encrypted")) # Install boot loader (always after running mkinitcpio) if self.settings.get('bootloader_install'): try: self.queue_event('info', _("Installing bootloader...")) from installation import bootloader boot_loader = bootloader.Bootloader(DEST_DIR, self.settings, self.mount_devices) boot_loader.install() except Exception as error: logging.error( _("Couldn't install boot loader: {0}".format(error))) self.queue_event('pulse', 'stop') chroot.umount_special_dirs(DEST_DIR)
def configure_system(self): """ Final install steps Set clock, language, timezone Run mkinitcpio Populate pacman keyring Setup systemd services ... and more """ self.queue_event('pulse', 'start') self.queue_event('info', _("Configuring your new system")) # This mounts (binds) /dev and others to /DEST_DIR/dev and others chroot.mount_special_dirs(DEST_DIR) self.auto_fstab() logging.debug("fstab file generated.") # If SSD was detected copy udev rule for deadline scheduler if self.ssd: self.set_scheduler() logging.debug("SSD udev rule copied successfully") # Copy configured networks in Live medium to target system if self.network_manager == 'NetworkManager': self.copy_network_config() if self.desktop == "base": # Setup systemd-networkd for systems that won't use the # networkmanager or connman daemons (atm it's just base install) # Enable systemd_networkd services # See: https://github.com/Antergos/Cnchi/issues/332#issuecomment-108745026 self.enable_services(["systemd-networkd", "systemd-resolved"]) # Setup systemd_networkd # TODO: Ask user for SSID and passphrase if a wireless link is found # (should this be done here or inside systemd_networkd.setup() ?) from installation import systemd_networkd systemd_networkd.setup() logging.debug("Network configuration done.") # Copy mirror list mirrorlist_src_path = '/etc/pacman.d/mirrorlist' mirrorlist_dst_path = os.path.join(DEST_DIR, 'etc/pacman.d/mirrorlist') try: shutil.copy2(mirrorlist_src_path, mirrorlist_dst_path) logging.debug("Mirror list copied.") except FileNotFoundError: logging.error("Can't copy mirrorlist file. File %s not found", mirrorlist_src_path) except FileExistsError: logging.warning("File %s already exists.", mirrorlist_dst_path) # Add Antergos repo to /etc/pacman.conf self.update_pacman_conf() logging.debug("pacman.conf has been created successfully") # Enable some useful services services = [] if self.desktop != "base": # In base there's no desktop manager ;) services.append(self.desktop_manager) # In base we use systemd-networkd (setup already done above) services.append(self.network_manager) services.extend(["ModemManager", "haveged"]) self.enable_services(services) # Enable timesyncd service if self.settings.get("use_timesyncd"): timesyncd_path = os.path.join(DEST_DIR, "etc/systemd/timesyncd.conf") with open(timesyncd_path, 'w') as timesyncd: timesyncd.write("[Time]\n") timesyncd.write("NTP=0.arch.pool.ntp.org 1.arch.pool.ntp.org 2.arch.pool.ntp.org 3.arch.pool.ntp.org\n") timesyncd.write("FallbackNTP=0.pool.ntp.org 1.pool.ntp.org 0.fr.pool.ntp.org\n") chroot_run(['timedatectl', 'set-ntp', 'true']) # Set timezone zoneinfo_path = os.path.join("/usr/share/zoneinfo", self.settings.get("timezone_zone")) chroot_run(['ln', '-s', zoneinfo_path, "/etc/localtime"]) logging.debug("Timezone set.") # Wait FOREVER until the user sets his params # FIXME: We can wait here forever! while self.settings.get('user_info_done') is False: # Wait five seconds and try again time.sleep(5) # Set user parameters username = self.settings.get('username') fullname = self.settings.get('fullname') password = self.settings.get('password') hostname = self.settings.get('hostname') sudoers_dir = os.path.join(DEST_DIR, "etc/sudoers.d") if not os.path.exists(sudoers_dir): os.mkdir(sudoers_dir, 0o710) sudoers_path = os.path.join(sudoers_dir, "10-installer") try: with open(sudoers_path, "w") as sudoers: sudoers.write('{0} ALL=(ALL) ALL\n'.format(username)) os.chmod(sudoers_path, 0o440) logging.debug("Sudo configuration for user %s done.", username) except IOError as io_error: # Do not fail if can't write 10-installer file. Something bad must be happening, though. logging.error(io_error) # Configure detected hardware # NOTE: Because hardware can need extra repos, this code must run # always after having called the update_pacman_conf method if self.hardware_install: try: logging.debug("Running hardware drivers post-install jobs...") self.hardware_install.post_install(DEST_DIR) except Exception as general_error: logging.error("Unknown error in hardware module. Output: %s", general_error) # Setup user default_groups = 'lp,video,network,storage,wheel,audio' if self.vbox: # Why there is no vboxusers group? Add it ourselves. chroot_run(['groupadd', 'vboxusers']) default_groups += ',vboxusers,vboxsf' self.enable_services(["vboxservice"]) if self.settings.get('require_password') is False: # Prepare system for autologin. LightDM needs the user to be in the autologin group. chroot_run(['groupadd', 'autologin']) default_groups += ',autologin' cmd = ['useradd', '-m', '-s', '/bin/bash', '-g', 'users', '-G', default_groups, username] chroot_run(cmd) logging.debug("User %s added.", username) self.change_user_password(username, password) cmd = ['chfn', '-f', fullname, username] chroot_run(cmd) cmd = ['chown', '-R', '{0}:users'.format(username), os.path.join("/home", username)] chroot_run(cmd) hostname_path = os.path.join(DEST_DIR, "etc/hostname") if not os.path.exists(hostname_path): with open(hostname_path, "w") as hostname_file: hostname_file.write(hostname) logging.debug("Hostname set to %s", hostname) # User password is the root password self.change_user_password('root', password) logging.debug("Set the same password to root.") # Generate locales locale = self.settings.get("locale") self.queue_event('info', _("Generating locales...")) self.uncomment_locale_gen(locale) chroot_run(['locale-gen']) locale_conf_path = os.path.join(DEST_DIR, "etc/locale.conf") with open(locale_conf_path, "w") as locale_conf: locale_conf.write('LANG={0}\n'.format(locale)) locale_conf.write('LC_COLLATE={0}\n'.format(locale)) # environment_path = os.path.join(DEST_DIR, "etc/environment") # with open(environment_path, "w") as environment: # environment.write('LANG={0}\n'.format(locale)) self.queue_event('info', _("Adjusting hardware clock...")) self.auto_timesetting() self.queue_event('info', _("Configuring keymap...")) keyboard_layout = self.settings.get("keyboard_layout") keyboard_variant = self.settings.get("keyboard_variant") if self.desktop != "base": # Set /etc/X11/xorg.conf.d/00-keyboard.conf for the xkblayout logging.debug("Set /etc/X11/xorg.conf.d/00-keyboard.conf for the xkblayout") xorg_conf_dir = os.path.join(DEST_DIR, "etc/X11/xorg.conf.d") if not os.path.exists(xorg_conf_dir): os.mkdir(xorg_conf_dir, 0o755) xorg_conf_xkb_path = os.path.join(xorg_conf_dir, "00-keyboard.conf") try: with open(xorg_conf_xkb_path, "w") as xorg_conf_xkb: xorg_conf_xkb.write( "# Read and parsed by systemd-localed. It's probably wise not to edit this file\n") xorg_conf_xkb.write('# manually too freely.\n') xorg_conf_xkb.write('Section "InputClass"\n') xorg_conf_xkb.write(' Identifier "system-keyboard"\n') xorg_conf_xkb.write(' MatchIsKeyboard "on"\n') xorg_conf_xkb.write(' Option "XkbLayout" "{0}"\n'.format(keyboard_layout)) if keyboard_variant and len(keyboard_variant) > 0: xorg_conf_xkb.write(' Option "XkbVariant" "{0}"\n'.format(keyboard_variant)) xorg_conf_xkb.write('EndSection\n') logging.debug("00-keyboard.conf written.") except IOError as io_error: # Do not fail if 00-keyboard.conf can't be created. # Something bad must be happening, though. logging.error(io_error) # Set vconsole.conf for console keymap if keyboard_layout == "gb": # The keyboard layout for Great Britain is "uk" in the cli and # "gb" (not uk) in X, just to make things more complicated. keyboard_layout_cli = "uk" else: keyboard_layout_cli = keyboard_layout vconsole_path = os.path.join(DEST_DIR, "etc/vconsole.conf") with open(vconsole_path, 'w') as vconsole: vconsole.write("KEYMAP={0}\n".format(keyboard_layout_cli)) # Install configs for root cmd = ['cp', '-av', '/etc/skel/.', '/root/'] chroot_run(cmd) self.queue_event('info', _("Configuring hardware...")) # Copy generated xorg.conf to target if os.path.exists("/etc/X11/xorg.conf"): shutil.copy2( "/etc/X11/xorg.conf", os.path.join(DEST_DIR, 'etc/X11/xorg.conf')) # Configure ALSA #self.alsa_mixer_setup() #logging.debug("Updated Alsa mixer settings") # Set pulse #if os.path.exists(os.path.join(DEST_DIR, "usr/bin/pulseaudio-ctl")): # chroot_run(['pulseaudio-ctl', 'normal']) # Set fluidsynth audio system (in our case, pulseaudio) self.set_fluidsynth() logging.debug("Updated fluidsynth configuration file") # Let's start without using hwdetect for mkinitcpio.conf. # It should work out of the box most of the time. # This way we don't have to fix deprecated hooks. # NOTE: With LUKS or LVM maybe we'll have to fix deprecated hooks. self.queue_event('info', _("Configuring System Startup...")) mkinitcpio.run(DEST_DIR, self.settings, self.mount_devices, self.blvm) logging.debug("Running Cnchi post-install script") # Call post-install script to fine tune our setup script_path_postinstall = os.path.join( self.settings.get('cnchi'), "scripts", POSTINSTALL_SCRIPT) cmd = ["/usr/bin/bash", script_path_postinstall, username, DEST_DIR, self.desktop, keyboard_layout] if keyboard_variant: cmd.append(keyboard_variant) else: cmd.append("") cmd.append(str(self.vbox)) try: subprocess.check_call(cmd, timeout=300) logging.debug("Post install script completed successfully.") except subprocess.CalledProcessError as process_error: # Even though Post-install script call has failed we will go on logging.error("Error running post-install script, command %s failed: %s", process_error.cmd, process_error.output) except subprocess.TimeoutExpired as timeout_error: logging.error(timeout_error) # Set lightdm config including autologin if selected if self.desktop != "base": self.setup_display_manager() # Configure user features (firewall, libreoffice language pack, ...) self.setup_features() # Encrypt user's home directory if requested # FIXME: This is not working atm if self.settings.get('encrypt_home'): logging.debug("Encrypting user home dir...") encfs.setup(username, DEST_DIR) logging.debug("User home dir encrypted") # Install boot loader (always after running mkinitcpio) if self.settings.get('bootloader_install'): try: logging.debug("Installing bootloader...") from installation import bootloader boot_loader = bootloader.Bootloader(DEST_DIR, self.settings, self.mount_devices) boot_loader.install() except Exception as general_error: logging.warning("While installing boot loader Cnchi encountered this error: %s", general_error) # This unmounts (unbinds) /dev and others to /DEST_DIR/dev and others chroot.umount_special_dirs(DEST_DIR) # Copy installer log to the new installation (just in case something goes wrong) logging.debug("Copying install log to /var/log.") self.copy_log() self.queue_event('pulse', 'stop')
def run(dest_dir, settings, mount_devices, blvm): """ Runs mkinitcpio """ cpu = get_cpu() # Add lvm and encrypt hooks if necessary hooks = ["base", "udev", "autodetect", "modconf", "block", "keyboard", "keymap"] modules = [] # It is important that the plymouth hook comes before any encrypt hook plymouth_bin = os.path.join(dest_dir, "usr/bin/plymouth") if os.path.exists(plymouth_bin): hooks.append("plymouth") # It is important that the encrypt hook comes before the filesystems hook # (in case you are using LVM on LUKS, the order should be: encrypt lvm2 filesystems) if settings.get("use_luks"): if os.path.exists(plymouth_bin): hooks.append("plymouth-encrypt") else: hooks.append("encrypt") modules.extend(["dm_mod", "dm_crypt", "ext4"]) arch = os.uname()[-1] if arch == 'x86_64': modules.extend(["aes_x86_64"]) else: modules.extend(["aes_i586"]) modules.extend(["sha256", "sha512"]) if settings.get("f2fs"): modules.append("f2fs") if blvm or settings.get("use_lvm"): hooks.append("lvm2") if "swap" in mount_devices: hooks.append("resume") hooks.append("filesystems") if settings.get('btrfs') and cpu is not 'genuineintel': modules.append('crc32c') elif settings.get('btrfs') and cpu is 'genuineintel': modules.append('crc32c-intel') else: hooks.append("fsck") set_hooks_and_modules(dest_dir, hooks, modules) # Run mkinitcpio on the target system # Fix for bsdcpio error. See: http://forum.antergos.com/viewtopic.php?f=5&t=1378&start=20#p5450 locale = settings.get('locale') chroot.mount_special_dirs(dest_dir) cmd = ['sh', '-c', 'LANG={0} /usr/bin/mkinitcpio -p linux'.format(locale)] chroot.run(cmd, dest_dir) if settings.get('feature_lts'): cmd = ['sh', '-c', 'LANG={0} /usr/bin/mkinitcpio -p linux-lts'.format(locale)] chroot.run(cmd, dest_dir) chroot.umount_special_dirs(dest_dir)