#!/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 # set -n readonly RUN="/run/archiso/bootmnt/arch/boot" readonly VM="$(dmesg | grep -i "hypervisor")" install() { # function calls prefixed with 'oneshot' will only ever be run once # otherwise the main function can be called repeatedly clear; tput cnorm # unpack the file system oneshot install_base # generate /etc/fstab and touch it up if we used a swapfile genfstab -U $MNT > $MNT/etc/fstab 2>$ERR echeck "genfstab -U $MNT > $MNT/etc/fstab" [[ -f $MNT/swapfile ]] && sed -i "s~${MNT}~~" $MNT/etc/fstab # update the mirrorlist.. MUST be done before updating or it may be slow oneshot mirrorlist_sort # MUST be before bootloader and mkinitcpio oneshot package_operations # set up user login.. MUST be done after package operation oneshot login_manager # mkinitcpio and bootloader install should only be done after installing the packages # and updating the mirrorlist, otherwise the chosen kernel may not be fully set up run_mkinitcpio install_bootloader # hwclock setup, falls back to setting --directisa if the default fails chrun "hwclock --systohc --utc" || chrun "hwclock --systohc --utc --directisa" # create the user last to avoid referencing multiple $HOME locations for liveuser/newuser oneshot create_user # drop off the user at the config editing menu edit_system_configs } install_base() { printf "\nUnpacking base file system --- Total: ~ 2.9G\n\n" rsync -ah --info=progress2 /run/archiso/sfs/airootfs/ $MNT/ # remove archiso init files and clean up install files rm -rf $MNT/etc/{sudoers.d/g_wheel,mkinitcpio-archiso.conf,polkit-1/rules.d/49-nopasswd_global.rules} find $MNT/usr/lib/initcpio -name 'archiso*' -type f -exec rm '{}' \; # 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 if [[ $VM ]]; then # in a VM remove xorg configs, these cause issues rm -rf $MNT/etc/X11/xorg.conf.d elif [[ $(lspci | grep ' VGA ' | grep 'Intel') != "" ]]; then # xorg config for intel, this should never happen in a VM cat > $MNT/etc/X11/xorg.conf.d/20-intel.conf < manufacturer-ucode.img [[ $UCODE ]] && cp -f $RUN/${UCODE/-/_} $MNT/boot/$UCODE # copy network settings cp -rf /etc/NetworkManager/system-connections $MNT/etc/NetworkManager/ cp -f /etc/resolv.conf $MNT/etc/ # set the locale and timezone cat > $MNT/etc/locale.conf << EOF LANG=$LOCALE EOF cat > $MNT/etc/default/locale << EOF LANG=$LOCALE EOF sed -i "s/#en_US.UTF-8/en_US.UTF-8/g; s/#${LOCALE}/${LOCALE}/g" $MNT/etc/locale.gen chrun "locale-gen" 2>/dev/null chrun "ln -sf /usr/share/zoneinfo/$ZONE/$SUBZONE /etc/localtime" 2>/dev/null # set the keymaps cat > $MNT/etc/X11/xorg.conf.d/00-keyboard.conf < $MNT/etc/default/keyboard < $MNT/etc/vconsole.conf < $MNT/etc/hostname << EOF $HOSTNAME EOF 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() { # set root password chrun "chpasswd <<< 'root:$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$ROOT_PASS")'" # edit the group and passwd files in /etc/ to swap the liveuser account sed -i "s/${LIVE}/${NEWUSER}/g" $MNT/etc/{group,gshadow,passwd,shadow} if [[ -d $MNT/home/$NEWUSER ]]; then rm -rf $MNT/home/$LIVE else # fix up some user files that reference the liveuser sed -i "s/${LIVE}/${NEWUSER}/g" $MNT/home/$LIVE/.config/gtk-3.0/bookmarks \ $MNT/home/$LIVE/.mozilla/firefox/archlabs.default/{prefs,sessionstore}.js # remove welcome message sed -i '/printf/d' $MNT/home/$LIVE/.zshrc [[ $INSTALL_WMS =~ bspwm ]] || rm -rf $MNT/home/$LIVE/.config/{bspwm,sxhkd} [[ $INSTALL_WMS =~ i3-gaps ]] || rm -rf $MNT/home/$LIVE/.config/i3 [[ $INSTALL_WMS =~ openbox ]] || rm -rf $MNT/home/$LIVE/.config/{openbox,skippy-xd,jgmenu,conky,tint2} [[ $INSTALL_WMS =~ (openbox|i3-gaps|bspwm) ]] || rm -rf $MNT/home/$LIVE/.config/polybar chrun "mv -f /home/$LIVE /home/$NEWUSER" fi chrun "usermod -aG rfkill,wheel,network,storage,power,video,audio,lp,autologin $NEWUSER" chrun "chpasswd <<< '$NEWUSER:$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$USER_PASS")'" chrun "chown -Rf $NEWUSER:users /home/$NEWUSER" } login_manager() { local service="$MNT/etc/systemd/system/getty@tty1.service.d" if [[ $LOGIN_TYPE == 'lightdm' ]]; then rm -rf $service for f in $MNT/home/$LIVE/.{xinitrc,zprofile}; do awk '{if($0 && $0 !~ "^#") print "# "$0; else print $0}' $f > $f done chrun 'systemctl enable lightdm.service && systemctl set-default graphical.target' cat > $MNT/etc/lightdm/lightdm-gtk-greeter.conf << EOF # LightDM GTK+ Configuration [greeter] active-monitor=0 default-user-image=/usr/share/icons/ArchLabs-Dark/64x64/places/distributor-logo-archlabs.png background=/usr/share/backgrounds/archlabs/archlabs.jpg theme-name=Adwaita-Dark icon-theme-name=Adwaita font-name=DejaVu Sans Mono 11 position=30%,end 50%,end EOF # if [[ $AUTOLOGIN == true ]]; then # chrun "groupadd -r nopasswdlogin && usermod -aG nopasswdlogin $LIVE" # 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 else # xinit login sed -i "s/openbox-session/${LOGIN_WM}/g" $MNT/home/$LIVE/.xinitrc if grep -q '#exec' $MNT/home/$LIVE/.zprofile; then sed -i 's/#exec/exec/' $MNT/home/$LIVE/.zprofile elif grep -q 'exec sudo archlabs-installer' $MNT/home/$LIVE/.zprofile; then sed -i 's|exec sudo archlabs-installer|exec startx -- vt1 >/dev/null 2>&1|' $MNT/home/$LIVE/.zprofile else cat > $MNT/home/$LIVE/.zprofile << EOF if [[ ! \$DISPLAY && \$XDG_VTNR -eq 1 ]]; then exec startx -- vt1 >/dev/null 2>&1 fi EOF fi if [[ $AUTOLOGIN == true ]]; then sed -i "s/${LIVE}/${NEWUSER}/g" $service/autologin.conf else rm -rf $service fi fi } run_mkinitcpio() { local add="" # setup a keyfile for LUKS.. Only when choosing grub and system is UEFI [[ $LUKS && ! $LVM && $SYS == 'UEFI' && $BOOTLDR == 'grub' ]] && luks_keyfile # new hooks needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM [[ $LVM ]] && add="lvm2" [[ $LUKS ]] && add="encrypt$([[ $add ]] && printf " %s" "$add")" sed -i "s/block filesystems/block ${add} filesystems ${MKINIT_HOOKS}/g" $MNT/etc/mkinitcpio.conf chrun "mkinitcpio -p $KERNEL" 2>$ERR echeck "mkinitcpio -p $KERNEL" } mirrorlist_sort() { printf "%s\n\n" "Sorting the mirrorlist" if hash reflector >/dev/null 2>&1; then $MIRROR_CMD --save $MNT/etc/pacman.d/mirrorlist --verbose || reflector --score 100 -l 50 -f 10 \ --sort rate --verbose --save $MNT/etc/pacman.d/mirrorlist else { eval $MIRROR_CMD || curl -s 'https://www.archlinux.org/mirrorlist/all/'; } | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 10 - > $MNT/etc/pacman.d/mirrorlist fi } package_operations() { local inpkg="$PACKAGES" # add the packages chosen during setup local rmpkg="archlabs-installer" # always remove the installer # the LTS kernel uses different packages if [[ $KERNEL == 'linux-lts' ]]; then rmpkg+=" virtualbox-guest-modules-arch linux" inpkg+=" linux-lts" # if the system is a VM then install the needed packages otherwise remove the guest utils [[ $VM ]] && inpkg+=" virtualbox-guest-dkms linux-lts-headers" || rmpkg+=" virtualbox-guest-utils" else # if the system is not a VM then remove the guest utils [[ $VM ]] || rmpkg+=" virtualbox-guest-modules-arch virtualbox-guest-utils" fi # for only gnome or cinnamon we don't need the xfce provided stuff [[ $INSTALL_WMS =~ (gnome|cinnamon) ]] && rmpkg+=" $(pacman -Qssq 'xfce4*' 2>/dev/null)" # when not using grub bootloader remove it's package and configurations if [[ $BOOTLDR != 'grub' ]]; then rmpkg+=" grub" rm -f $MNT/etc/default/grub find $MNT/boot/ -name 'grub*' -exec rm -rf '{}' \; >/dev/null 2>&1 elif [[ $BOOTLDR != 'syslinux' ]]; then # do the same when not using syslinux as the bootloader find $MNT/boot/ -name 'syslinux*' -exec rm -rf '{}' \; >/dev/null 2>&1 fi # iputils, base-devel, and git are all needed and should always be installed separately chrun "pacman -Syyu --noconfirm" chrun "pacman -S iputils --noconfirm; pacman -S base-devel git --needed --noconfirm" chrun "pacman -S $inpkg --needed --noconfirm" chrun "pacman -Rs $rmpkg --noconfirm" # for neovim copy the default vimrc and colorscheme to ~/.config/nvim if [[ $inpkg =~ neovim ]]; then mkdir -p $MNT/home/$LIVE/.config/nvim cp -f $MNT/home/$LIVE/.vimrc $MNT/home/$LIVE/.config/nvim/init.vim cp -rf $MNT/home/$LIVE/.vim/colors $MNT/home/$LIVE/.config/nvim/colors fi # install and setup dwm if [[ $INSTALL_WMS =~ dwm ]]; then mkdir -pv $MNT/home/$LIVE/suckless for i in dwm dmenu st; do p="/home/$LIVE/suckless/$i" chrun "git clone https://bitbucket.org/natemaia/$i $p && { cd $p; rm -f $p/config.h 2>/dev/null; make clean install && make clean; }" done fi }