From 98d38ad037ed2feb57e37163a38be20c25ffb75f Mon Sep 17 00:00:00 2001 From: natemaia Date: Wed, 4 Nov 2020 10:39:02 -0800 Subject: [PATCH] Move to pacstrap only base install, simplify some sections. --- installer | 117 ++++++++++++++++-------------------------------------- 1 file changed, 35 insertions(+), 82 deletions(-) diff --git a/installer b/installer index a30cf9e..9d5089b 100755 --- a/installer +++ b/installer @@ -10,14 +10,13 @@ VER=2.1.64 # default values { -: "${DIST=ArchLabs}" # distro name if not set -: "${MNT=/mnt}" # installation root mountpoint if not set +DIST=$(awk -F'"' '/^NAME=/ {print $2}' /etc/os-release 2> /dev/null) +MNT=/mnt # installation root mountpoint if not set SYS=Unknown # boot type, to be determined: UEFI/BIOS FONT=ter-i16n # font used for the linux console HOOKS=shutdown # additional mkinitcpio HOOKS SEL=0 # currently selected main menu item BTRFS=0 # is btrfs used, 1 = btrfs alone, 2 = btrfs + subvolume(s) -PACSTRAP=1 # use pacstrap or copy the iso filesystem EXMNTS='' # extra partitions that were mounted, used to verify mountpoint and show user USERCMD='' # optional command(s) entered by the user to run in the chroot ANS=/tmp/ans # dialog answer output file @@ -354,7 +353,6 @@ _format="is already formatted correctly.\n\nFor a clean install, existing partit _swapsize="\nEnter the size of the swapfile in megabytes (M) or gigabytes (G).\n\ne.g. 100M will create a 100 megabyte swapfile, while 10G will create a 10 gigabyte swapfile.\n\nFor ease of use and as an example it is filled in to match the size of your system memory (RAM).\n\nMust be greater than 1, contain only whole numbers, and end with either M or G." _expart="\nYou can now choose any additional partitions you want mounted, you'll be asked for a mountpoint after.\n\nSelect 'done' to finish the mounting step and begin unpacking the base system in the background." _exmnt="\nWhere do you want the partition mounted?\n\nEnsure the name begins with a slash (/).\nExamples include: /usr, /home, /var, etc." -_bginstall="\nThe background base install will now start, select which base to use\n\nPacstrap - downloads all packages, avoids issues but can be slower depending on your network.\n\nCopy ISO - faster and not network dependant but can result in installation issues when using an older ISO.\n" _user="\nEnter a name and password for the new user account.\n\nThe name must not use capital letters, contain any periods (.), end with a hyphen (-), or include any colons (:)\n\nNOTE: Use [Up], [Down], or [Tab] to switch between fields, and [Enter] to accept." _hostname="\nEnter a hostname for the new system.\n\nA hostname is used to identify systems on the network.\n\nIt's restricted to alphanumeric characters (a-z, A-Z, 0-9).\nIt can contain hyphens (-) BUT NOT at the beginning or end." _locale="\nLocale determines the system language and currency formats.\n\nThe format for locale names is languagecode_COUNTRYCODE\n\ne.g. en_US is: English United States\n en_GB is: English Great Britain" @@ -1140,12 +1138,12 @@ part_swap() local size=0 if [[ $swp == "$MNT/swapfile" && $SWAP_S ]]; then - msg "Swap Setup" "\nActivating $SWAP_S swapfile at /swapfile\n" 1 + msg "Swap Setup" "\nCreating $SWAP_S swapfile at /swapfile\n\nThis can take a while.\n" 1 case "${SWAP_S: -1}" in G) size=$(( ${SWAP_S:0:-1} * 1024 )) ;; M) size=${SWAP_S:0:-1} ;; esac - dd if=/dev/zero of="$swp" bs=1M count=$size + dd if=/dev/zero of="$swp" bs=1M count=$size 2> "$ERR" errshow 0 "dd if=/dev/zero of='$swp' bs=1M count=$size" chmod 600 "$swp" 2> "$ERR" errshow 0 "chmod 600 '$swp'" @@ -1681,7 +1679,7 @@ install_main() install_login # changing distro name? - if grep -q 'ArchLabs' "$MNT/etc/lsb-release" && [[ $DIST != 'ArchLabs' ]]; then + if grep -q 'ArchLabs' "$MNT/etc/os-release" && [[ $DIST != 'ArchLabs' ]]; then sed -i "s/ArchLabs/$DIST/g" "$MNT/etc/lsb-release" sed -i "s/ArchLabs/$DIST/g" "$MNT/etc/os-release" else @@ -1692,8 +1690,6 @@ install_main() # allow members of the wheel group to run commands as root sed -i "s/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g" "$MNT/etc/sudoers" - chrun "chown -Rf $NEWUSER:users /home/$NEWUSER" - if [[ "$USERCMD" ]]; then chrun "$USERCMD" 2> "$ERR" 2>&1 errshow 0 "chrun '$USERCMD'" @@ -1745,31 +1741,12 @@ install_base() mkdir -pv "$MNT/etc/default" mkdir -pv "$MNT/etc/X11/xorg.conf.d/" - if (( ! PACSTRAP )); then - # remove archiso files when copying iso - rm -rf "$MNT/etc/mkinitcpio-archiso.conf" - find "$MNT/usr/lib/initcpio" -name 'archiso*' -type f -delete - - # vmlinuz, if this isn't copied the vanilla kernel may fail mkinitcpio - cp -vf "$RUN/x86_64/vmlinuz" "$MNT/boot/vmlinuz-linux" 2> "$ERR" - errshow 1 "cp -vf '$RUN/x86_64/vmlinuz' '$MNT/boot/vmlinuz-linux'" - - # remove/disable customizations done to airootfs during building - chrun "systemctl disable pacman-init.service" > /dev/null 2>&1 - rm -f "$MNT/etc/systemd/system/pacman-init.service" - rm -f "$MNT/etc/systemd/system/etc-pacman.d-gnupg.mount" - sed -i 's/#\(Storage=\)volatile/\1auto/' "$MNT/etc/systemd/journald.conf" - sed -i 's/\(HandleLidSwitch=\)ignore/#\1suspend/' "$MNT/etc/systemd/logind.conf" - sed -i 's/\(HandleSuspendKey=\)ignore/#\1suspend/' "$MNT/etc/systemd/logind.conf" - sed -i 's/\(HandleHibernateKey=\)ignore/#\1hibernate/' "$MNT/etc/systemd/logind.conf" - find "$MNT/boot" -name '*-ucode.img' -delete - elif [[ $DIST == "ArchLabs" ]]; then + if [[ $DIST == "ArchLabs" ]]; then # we have some customizations in /etc on the iso we want to preserve + cp -vf /etc/pacman.conf "$MNT/etc/" cp -vf /etc/modprobe.d/* "$MNT/etc/modprobe.d/" # */ cp -vf /etc/X11/xorg.conf.d/* "$MNT/etc/X11/xorg.conf.d/" # */ - cp -vf /etc/dialogrc "$MNT/etc/dialogrc" cp -vf /etc/os-release "$MNT/etc/os-release" - cp -vf /etc/lsb-release "$MNT/etc/lsb-release" cp -vf /etc/skel/.zshrc "$MNT/etc/skel/.zshrc" fi @@ -1853,6 +1830,9 @@ install_user() install_cleanup "$NEWUSER" + # make sure the new user owns files in their $HOME + chrun "chown -Rf $NEWUSER:users /home/$NEWUSER" + return 0 } @@ -1906,7 +1886,6 @@ install_cleanup() if [[ $LOGIN_WM =~ (startplasma-x11|gnome-session|startdde|cinnamon-session) || ($LOGIN_TYPE != 'xinit' && $INSTALL_WMS =~ (plasma|gnome|cinnamon|deepin)) ]]; then sed -i '/super/d; /nitrogen/d; /picom/d' "$MNT/home/$user/.xprofile" "$MNT/root/.xprofile" fi - } install_bootldr() @@ -1999,24 +1978,15 @@ install_packages() inpkg+=("$i") done - if [[ $PACSTRAP -eq 1 ]]; then - blk="$(lsblk -f)" - lspci | grep -qi 'broadcom' && inpkg+=('b43-firmware' 'b43-fwcutter' 'broadcom-wl') - [[ $blk =~ ntfs ]] && inpkg+=('ntfs-3g') - [[ $blk =~ jfs ]] && inpkg+=('jfsutils') - [[ $blk =~ xfs ]] && inpkg+=('xfsprogs') - [[ $blk =~ reiserfs ]] <<< "$blk" && inpkg+=('reiserfsprogs') - [[ $LVM ]] && inpkg+=('lvm2') - if [[ $BTRFS_MNT ]] || [[ $blk =~ btrfs ]]; then - inpkg+=('btrfs-progs') - fi - else - [[ $NEWSHELL == 'zsh' ]] || rmpkg+=('zsh') - if pacman -Qq archlabs-installer >/dev/null 2>&1; then - rmpkg+=('archlabs-installer') - else - rm -fv "$MNT/usr/bin/installer" - fi + blk="$(lsblk -f)" + lspci | grep -qi 'broadcom' && inpkg+=('b43-firmware' 'b43-fwcutter' 'broadcom-wl') + [[ $blk =~ ntfs ]] && inpkg+=('ntfs-3g') + [[ $blk =~ jfs ]] && inpkg+=('jfsutils') + [[ $blk =~ xfs ]] && inpkg+=('xfsprogs') + [[ $blk =~ reiserfs ]] <<< "$blk" && inpkg+=('reiserfsprogs') + [[ $LVM ]] && inpkg+=('lvm2') + if [[ $BTRFS_MNT ]] || [[ $blk =~ btrfs ]]; then + inpkg+=('btrfs-progs') fi [[ $NEWSHELL == 'zsh' ]] && inpkg+=('zsh-completions') @@ -2175,11 +2145,6 @@ install_tearfree() fi fi fi - - if [[ $PACSTRAP != 1 ]]; then - # remove nvidia installer from installed system - [[ $xpath == *"$MNT"* ]] && rm -rf "$MNT/usr/bin/nvidia-installer" "$MNT/var/lib/nvidia-installer" - fi } install_mkinitcpio() @@ -2202,6 +2167,7 @@ install_mirrorlist() # avoid SSL errors when the time is wrong timedatectl set-ntp 1 && timedatectl > /dev/null 2>&1 + # make a mirrorlist backup in case of issues [[ -f /etc/pacman.d/mirrorlist.bak ]] || cp -f /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak if hash reflector > /dev/null 2>&1; then @@ -2247,34 +2213,17 @@ install_background() [[ $LUKS ]] && luks='cryptsetup' select_mirrors || AUTO_MIRROR=true - - if hash rsync > /dev/null 2>&1; then # ask whether to pacstrap or copy if rsync is installed - yesno 'Background Install' "$_bginstall" 'Pacstrap' 'Copy ISO' || PACSTRAP=0 - fi - ( install_mirrorlist > /tmp/bgout 2>&1 + pacman -Sy >> /tmp/bgout 2>&1 + pacstrap /mnt >> /tmp/bgout 2>&1 - if [[ $PACSTRAP == 1 ]]; then - pacman -Sy >> /tmp/bgout 2>&1 - pacstrap /mnt >> /tmp/bgout 2>&1 - else - rsync -avh /run/archiso/sfs/airootfs/ "$MNT/" >> /tmp/bgout 2>&1 - fi + cp -Rf /etc/pacman.d "$MNT/etc/" + cp -f /etc/pacman.conf "$MNT/etc/" + cp -f /etc/pacman.d/mirrorlist "$MNT/etc/pacman.d/" + al_repo "$MNT/etc/pacman.conf" || chrun "pacman -Syyu --noconfirm" >> /tmp/bgout 2>&1 - mkdir -p "$MNT/etc/pacman.d" - cp -Rf /etc/pacman.d "$MNT/etc/pacman.d" - - cp /etc/pacman.conf "$MNT/etc/pacman.conf" - cp /etc/pacman.d/mirrorlist "$MNT/etc/pacman.d/mirrorlist" - al_repo "$MNT/etc/pacman.conf" - - if [[ $PACSTRAP == 1 ]]; then - chrun "pacman -S ${ISO_PKGS[*]} $net $luks --noconfirm --needed" >> /tmp/bgout 2>&1 - else - chrun 'pacman -Sy' >> /tmp/bgout 2>&1 - chrun "pacman -S $net --noconfirm --needed" >> /tmp/bgout 2>&1 - fi + chrun "pacman -S ${ISO_PKGS[*]} $net $luks --noconfirm --needed" >> /tmp/bgout 2>&1 if [[ $net == "networkmanager" ]]; then chrun 'systemctl enable NetworkManager.service' >> /tmp/bgout 2>&1 @@ -2352,7 +2301,7 @@ config_lightdm() { sed -i "/greeter-session=/ c greeter-session=lightdm-$LIGHTDM_GREETER" "$MNT/etc/lightdm/lightdm.conf" - if [[ $LIGHTDM_GREETER == 'gtk-greeter' ]]; then + if [[ $LIGHTDM_GREETER == 'gtk-greeter' && $DIST == "ArchLabs" ]]; then mkdir -p "$MNT/etc/lightdm" cat > "$MNT/etc/lightdm/lightdm-gtk-greeter.conf" <<- EOF [greeter] @@ -3245,7 +3194,7 @@ al_repo() { local conf="$1" - grep -q 'archlabs_repo' "$conf" && return 0 + grep -q 'archlabs_repo' "$conf" 2> /dev/null && return 0 cat >> "$conf" <<- EOF @@ -3258,6 +3207,7 @@ al_repo() Server = https://github.com/ARCHLabs/\$repo/raw/master/\$arch EOF + return 1 } termcol() @@ -3317,6 +3267,9 @@ errshow() prechecks() { + # check whether we have all steps done for a given level ($1) + # if a fail is encountered we display an error dialog and set + # the selected entry number ($SEL) back to the step required to progress local i=1 if (( $1 >= 0 )) && ! grep -q " $MNT " /proc/mounts; then @@ -3487,14 +3440,14 @@ while getopts ":htl:Dnr:b:m:d:" OPT; do d) DIST="$OPTARG" ;; r) if [[ ! -b $OPTARG ]]; then - msg "Invalid Root" "\nThe installer expects a full path to a block device for root.\n\nExiting..\n" 2 + msg "Invalid Root" "\nThe installer expects a full path to a block device for root, e.g. /dev/sda2.\n\nExiting..\n" 2 die 1 fi ROOT="$OPTARG" ;; b) if [[ ! -b $OPTARG ]]; then - msg "Invalid Boot" "\nThe installer expects a full path to a block device for boot.\n\nExiting..\n" 2 + msg "Invalid Boot" "\nThe installer expects a full path to a block device for boot, e.g. /dev/sda1.\n\nExiting..\n" 2 die 1 fi BOOT="$OPTARG"