#!/usr/bin/bash # vim:ft=sh:fdm=marker:fmr={,} # archlabs installer library script file # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised install_main() { # unpack the whole filesystem to install directory $MNT oneshot install_base genfstab -U $MNT > $MNT/etc/fstab 2>$ERR check_for_errors "genfstab -U $MNT > $MNT/etc/fstab" # touch up fstab if we used a swapfile if [[ -f $MNT/swapfile ]]; then sed -i "s~${MNT}~~" $MNT/etc/fstab 2>$ERR check_for_errors "sed -i s~${MNT}~~ $MNT/etc/fstab" fi # update the mirrorlist, if this isn't done before updating or it may be slow local cmdtail="--verbose --save $MNT/etc/pacman.d/mirrorlist" $MIRROR_CMD $cmdtail || reflector --score 100 -l 50 -f 10 --sort rate $cmdtail oneshot update_system # MUST be before bootloader and mkinitcpio if [[ $LOGIN_TYPE == 'lightdm' ]]; then oneshot setup_lightdm fi run_mkinitcpio || return 1 install_bootloader || return 1 chroot_cmd "hwclock --systohc --utc" || chroot_cmd "hwclock --systohc --utc --directisa" oneshot create_user || return 1 return 0 } install_base() { clear tput cnorm echo -e "\nUnpacking base filesystem..\n\n" rsync -ah --info=progress2 /run/archiso/sfs/airootfs/ $MNT/ # remove archiso init files and clean up install files find $MNT/usr/lib/initcpio -name 'archiso*' -type f -exec rm '{}' \; rm -f $MNT/etc/mkinitcpio-archiso.conf rm -rf $MNT/etc/sudoers.d/g_wheel rm -f $MNT/etc/polkit-1/rules.d/49-nopasswd_global.rules # cleanup system permissions sed -i 's/volatile/auto/g' $MNT/etc/systemd/journald.conf sed -i "s/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g" $MNT/etc/sudoers # for virtual machines remove configs for xorg, these cause mouse issues [[ $VM ]] && rm -rf $MNT/etc/X11/xorg.conf.d # if not installing the lts kernel, copy the kernel image if [[ $KERNEL != 'linux-lts' ]]; then cp -f /run/archiso/bootmnt/arch/boot/x86_64/vmlinuz $MNT/boot/vmlinuz-linux fi setup_configs return 0 } setup_configs() { # copy network settings cp -rf /etc/NetworkManager/system-connections $MNT/etc/NetworkManager/ cp -f /etc/resolv.conf $MNT/etc/ # set the locale and timezone sed -i "s/#en_US.UTF-8/en_US.UTF-8/g; s/#${LOCALE}/${LOCALE}/g" $MNT/etc/locale.gen sed -i "s/en_US.UTF-8/${LOCALE}/g" $MNT/etc/locale.conf cp -f $MNT/etc/locale.conf $MNT/etc/default/locale chroot_cmd "locale-gen" 2>$ERR chroot_cmd "ln -sf /usr/share/zoneinfo/$ZONE/$SUBZONE /etc/localtime" 2>$ERR # setup xorg vsync config for intel graphics if [[ $(lspci | grep ' VGA ' | grep 'Intel') != "" ]]; then cat > $MNT/etc/X11/xorg.conf.d/20-intel.conf < $MNT/etc/X11/xorg.conf.d/00-keyboard.conf < $MNT/etc/default/keyboard < $MNT/etc/vconsole.conf < $MNT/etc/hostname cat > $MNT/etc/hosts << EOF 127.0.0.1 localhost 127.0.1.1 $HOSTNAME ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters EOF return 0 } create_user() { local _home="$MNT/home/$LIVE" local serve="$MNT/etc/systemd/system/getty@tty1.service.d" # set root password chroot_cmd "echo 'root:$ROOT_PASS' | chpasswd" # edit the required files in /etc/ to swap the liveuser account name sed -i "s/${LIVE}/${NEWUSER}/g" $MNT/etc/{group,gshadow,passwd,shadow} # set standard groups for the new user local groups="rfkill,wheel,network,lp,storage,power,video,audio,lp,autologin" if [[ $LOGIN_TYPE == 'lightdm' ]]; then [[ $AUTOLOGIN == true ]] && groups="$groups,nopasswdlogin" rm -rf $_home/.{zprofile,xinitrc} rm -rf $serve else if [[ $AUTOLOGIN == true ]]; then sed -i "s/${LIVE}/${NEWUSER}/g" $serve/autologin.conf fi sed -i "s/:-openbox/:-${LOGIN_WM}/g" $_home/.xinitrc sed -i '/archlabs-installer/d' $_home/.zprofile cat >> $_home/.zprofile << EOF [[ -z \$DISPLAY && \$XDG_VTNR -eq 1 ]] && exec startx -- vt1 &>/dev/null EOF fi sed -i "s/${LIVE}/${NEWUSER}/g" $_home/.config/gtk-3.0/bookmarks sed -i "s/${LIVE}/${NEWUSER}/g" $_home/.mozilla/firefox/archlabs.default/prefs.js sed -i "s/${LIVE}/${NEWUSER}/g" $_home/.mozilla/firefox/archlabs.default/sessionstore.js if ! [[ $INSTALL_WMS =~ openbox ]]; then rm -rf $_home/.config/openbox elif ! [[ $INSTALL_WMS =~ bspwm ]]; then rm -rf $_home/.config/{bspwm,sxhkd} elif ! [[ $INSTALL_WMS =~ i3-gaps ]]; then rm -rf $_home/.config/i3 fi chroot_cmd "mv -f /home/$LIVE /home/$NEWUSER" chroot_cmd "usermod -aG $groups $NEWUSER" chroot_cmd "echo '$NEWUSER:$USER_PASS' | chpasswd" chroot_cmd "chown -Rf $NEWUSER:users /home/$NEWUSER" return 0 } run_mkinitcpio() { # setup a keyfile for LUKS.. Only when choosing grub and system is UEFI if [[ $LUKS -eq 1 && $LVM != 1 && $SYS == 'UEFI' && $BOOTLDR == 'grub' ]]; then luks_keyfile fi # new HOOKS needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM local add (( LVM == 1 )) && add="lvm2" (( LUKS == 1 )) && add="encrypt$([[ $add != "" ]] && echo -n " $add")" local conf="$MNT/etc/mkinitcpio.conf" sed -i "s/block filesystems/block ${add} filesystems ${MKINIT_HOOKS}/g" $conf tput civis chroot_cmd "mkinitcpio -p $KERNEL" 2>$ERR check_for_errors "mkinitcpio -p $KERNEL" return 0 } update_system() { tput cnorm local inpkg="base-devel git" local rmpkg="archlabs-installer" local vbx="virtualbox-guest-modules-arch" if [[ $KERNEL == 'linux-lts' ]]; then rmpkg="$rmpkg $vbx linux" inpkg="linux-lts" if [[ $VM ]]; then inpkg="$inpkg virtualbox-guest-dkms linux-lts-headers" else rmpkg="$rmpkg virtualbox-guest-utils" fi elif ! [[ $VM ]]; then rmpkg="$rmpkg $vbx virtualbox-guest-utils" fi if [[ $INSTALL_WMS == 'dwm' ]]; then inpkg="$inpkg xorg-server" fi # for gnome and cinnamon we don't need the xfce provided stuff if [[ $INSTALL_WMS == 'gnome' || $INSTALL_WMS == 'cinnamon' ]]; then rmpkg="$(pacman -Qssq 'xfce4*' 2>/dev/null)" fi if [[ $BOOTLDR != 'grub' ]]; then rmpkg="$rmpkg grub" rm -f $MNT/etc/default/grub find $MNT/boot/ -name 'grub*' -exec rm -rf '{}' \; >/dev/null 2>&1 fi local update="pacman -Syyu --noconfirm" local network="pacman -S iputils --noconfirm" local install="pacman -S $inpkg $EXTRA_PACKAGES --needed --noconfirm" local remove="pacman -Rs $rmpkg --noconfirm" chroot_cmd "$update; $network; $install; $remove" if [[ $INSTALL_WMS =~ dwm ]]; then mkdir -pv $MNT/home/$LIVE/suckless for prog in dwm st dmenu; do local cmd="git clone https://bitbucket.org/natemaia/$prog /home/$LIVE/suckless/$prog" chroot_cmd "$cmd; cd /home/$LIVE/suckless/$prog && make clean install && make clean" done fi return 0 } setup_lightdm() { local cfg="$MNT/etc/lightdm/lightdm-gtk-greeter.conf" chroot_cmd 'systemctl enable lightdm.service && systemctl set-default graphical.target' sed -i '/#background=/ c background=/usr/share/backgrounds/archlabs/archlabs.jpg' $cfg sed -i '/#theme-name=/ c theme-name=ArchLabs-dARK' $cfg sed -i '/#icon-theme-name=/ c icon-theme-name=ArchLabs-Light' $cfg sed -i '/#position=/ c position=34%,end 66%,end' $cfg sed -i '/#font-name=/ c font-name=DejaVu Sans Mono 11' $cfg sed -i '/\[greeter]/ a default-user-image=/usr/share/icons/ArchLabs-Dark/64x64/places/distributor-logo-archlabs.png' $cfg sed -i '/\[greeter]/ a active-monitor=0' $cfg if [[ $AUTOLOGIN == true ]]; then chroot_cmd 'groupadd -r nopasswdlogin' sed -i '/#%PAM-1.0/ a auth sufficient pam_succeed_if.so user ingroup nopasswdlogin' $MNT/etc/pam.d/lightdm sed -i "/#autologin-session=/ c autologin-session=${LOGIN_WM}" $MNT/etc/lightdm/lightdm.conf sed -i "/#autologin-user=/ c autologin-user=${NEWUSER}" $MNT/etc/lightdm/lightdm.conf fi }