From 83743ec8c861f8f98ec1439a6ccc80b5d5641d76 Mon Sep 17 00:00:00 2001 From: natemaia Date: Fri, 14 Dec 2018 22:51:12 -0800 Subject: [PATCH] Fix: file permissions in the created user's home --- src/archlabs-installer | 2 +- src/lib/boot.sh | 87 ++++++++++++++++++++++++++---------------- src/lib/dialogs.sh | 11 +++--- src/lib/install.sh | 11 +++++- src/lib/luks.sh | 5 +-- src/lib/lvm.sh | 35 +++++++++++++---- src/lib/mount.sh | 61 ++++++----------------------- src/lib/package.sh | 8 ++-- src/lib/part.sh | 12 ++++++ src/lib/utils.sh | 16 +++++--- 10 files changed, 136 insertions(+), 112 deletions(-) diff --git a/src/archlabs-installer b/src/archlabs-installer index 92e32b9..ae63f72 100755 --- a/src/archlabs-installer +++ b/src/archlabs-installer @@ -10,7 +10,7 @@ # immutable globals -readonly VER="1.7.34" # Installer version +readonly VER="1.7.37" # Installer version readonly DIST="ArchLabs" # Linux distributor readonly MNT="/mnt" # Install mountpoint readonly ERR="/tmp/errlog" # Built-in error log diff --git a/src/lib/boot.sh b/src/lib/boot.sh index 93fe8ea..93185e2 100644 --- a/src/lib/boot.sh +++ b/src/lib/boot.sh @@ -1,21 +1,23 @@ #!/usr/bin/bash # vim:ft=sh:fdm=marker:fmr={,} -# shellcheck disable=2034 +# shellcheck disable=2034,2154 # 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 -# command used to install each bootloader, this can be modified later to fit the system +# command used to install each bootloader declare -Ag BCMDS=( -[syslinux]="syslinux-install_update -iam" -[grub]="grub-install --recheck --force" -[systemd-boot]="bootctl --path=/boot install" +[UEFI-syslinux]='efibootmgr -c -d $BOOT_DEVICE -p $BOOT_PART_NUM -l /EFI/syslinux/syslinux.efi -L $DIST' +[BIOS-syslinux]='syslinux-install_update -iam' +[UEFI-grub]='grub-install --recheck --force --bootloader-id=$DIST && grub-mkconfig -o /boot/grub/grub.cfg' +[BIOS-grub]='grub-install --recheck --force --bootloader-id=$DIST --target=i386-pc $BOOT_DEVICE && grub-mkconfig -o /boot/grub/grub.cfg' +[systemd-boot]='bootctl --path=/boot install' ) -# readonly boot partition mount points for each bootloader -declare -Agr BMNTS=( +# boot partition mount points for each bootloader +declare -Ag BMNTS=( [BIOS-grub]="/boot" [UEFI-grub]="/boot/efi" [BIOS-syslinux]="/boot" @@ -23,13 +25,40 @@ declare -Agr BMNTS=( [UEFI-systemd-boot]="/boot" ) -# readonly bootloader options with respective boot partition mountpoint -declare -Agr BOOTLDRS=( +# bootloader options with respective boot partition mountpoint +declare -Ag BOOTLDRS=( [BIOS]="grub ${BMNTS[BIOS-grub]} syslinux ${BMNTS[BIOS-syslinux]}" [UEFI]="systemd-boot ${BMNTS[UEFI-systemd-boot]} grub ${BMNTS[UEFI-grub]} syslinux ${BMNTS[UEFI-syslinux]}" ) -prep_for_grub() +pre_grub() +{ + FILES[9]="/etc/default/grub" + + if [[ $SYS == 'BIOS' && $BOOT_DEVICE == "" ]]; then + select_device 'boot' || return 1 + elif [[ $SYS == 'UEFI' && $ROOT_PART =~ /dev/mapper && ! $LVM && ! $LUKS_PASS ]]; then + luks_pass "$_LuksOpen" "$ROOT_PART" || return 1 + fi + + return 0 +} + +pre_syslinux() +{ + if [[ $SYS == 'BIOS' ]]; then + FILES[9]="/boot/syslinux/syslinux.cfg" + else + FILES[9]="/boot/EFI/syslinux/syslinux.cfg" + fi +} + +pre_systemd-boot() +{ + FILES[9]="/boot/loader/entries/$DIST.conf" +} + +prerun_grub() { local cfg="$MNT/etc/default/grub" sed -i "s/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"${DIST}\"/g; @@ -44,26 +73,22 @@ prep_for_grub() sed -i "s/GRUB_PRELOAD_MODULES=.*/GRUB_PRELOAD_MODULES=\"lvm\"/g" $cfg fi + # needed for os-prober module to work properly in the chroot if [[ $SYS == 'UEFI' ]]; then - # needed for os-prober module to work properly in the chroot - mkdir -p /run/lvm - mkdir -p /run/udev - mkdir -p $MNT/hostrun/lvm - mkdir -p $MNT/hostrun/udev - mount --bind /run/lvm $MNT/hostrun/lvm + # mkdir -p /run/lvm $MNT/hostrun/lvm + # mount --bind /run/lvm $MNT/hostrun/lvm + mkdir -p /run/udev $MNT/hostrun/udev mount --bind /run/udev $MNT/hostrun/udev - BCMDS[grub]="mkdir -p /run/udev; mkdir -p /run/lvm; \ - mount --bind /hostrun/udev /run/udev; \ - mount --bind /hostrun/lvm /run/lvm; \ - ${BCMDS[grub]}; \ - umount /run/udev; \ - umount /run/lvm" + BCMDS[grub]="mkdir -p /run/udev && + mount --bind /hostrun/udev /run/udev && + ${BCMDS[grub]} && + umount /run/udev" fi return 0 } -prep_for_systemd-boot() +prerun_systemd-boot() { # no LVM then systemd-boot uses PARTUUID [[ $ROOT_PART =~ /dev/mapper ]] || ROOT_PART_ID="PART$ROOT_PART_ID" @@ -99,7 +124,7 @@ EOF return 0 } -prep_for_syslinux() +prerun_syslinux() { if [[ $SYS == 'UEFI' ]]; then local cfgdir="${MNT}${BMNTS[$SYS-$BOOTLDR]}/EFI/syslinux" @@ -151,16 +176,13 @@ install_bootloader() -type d -exec rm -rf '{}' \; >/dev/null 2>&1 fi - # sets up the bootloader configs and BCMD (boot command) - prep_for_$BOOTLDR + prerun_$BOOTLDR - # install/setup the bootloader by running the BCMD (boot command) printf "\nInstalling and setting up $BOOTLDR in ${BMNTS[$SYS-$BOOTLDR]}\n\n" - chrun "${BCMDS[$BOOTLDR]}" + chrun "eval ${BCMDS[$SYS-$BOOTLDR]}" - if [[ -d $MNT/hostrun ]]; then - umount $MNT/hostrun/lvm + if [[ -d $MNT/hostrun/udev ]]; then umount $MNT/hostrun/udev rm -rf $MNT/hostrun fi @@ -172,12 +194,12 @@ install_bootloader() uefi_boot_fallback() { - # some UEFI firmware requires a directory in the ESP and a generic bootx64.efi + # some UEFI firmware requires a dir in the ESP with a generic bootx64.efi # see: https://wiki.archlinux.org/index.php/GRUB#UEFI # also: https://wiki.archlinux.org/index.php/syslinux#UEFI_Systems local esp="${MNT}${BMNTS[$SYS-$BOOTLDR]}" - local default="Boot" + local default="boot" default="$(find $esp/EFI/ -maxdepth 1 -mindepth 1 \ -name '[Bb][oO][oO][tT]' -type d)" @@ -197,6 +219,7 @@ uefi_boot_fallback() elif [[ $BOOTLDR == 'grub' ]]; then cp -f $esp/EFI/$DIST/grubia32.efi $esp/EFI/$default/bootia32.efi fi + return 0 } diff --git a/src/lib/dialogs.sh b/src/lib/dialogs.sh index 3a6760f..1ef4e9a 100644 --- a/src/lib/dialogs.sh +++ b/src/lib/dialogs.sh @@ -76,7 +76,7 @@ declare -gA EDIT_FILES=( show_cfg() { local cmd mnt pkgs - cmd="${BCMDS[$BOOTLDR]}" + cmd="$(eval echo ${BCMDS[$SYS-$BOOTLDR]})" mnt="${BMNTS[$SYS-$BOOTLDR]}" msgbox "$_PrepTitle" " @@ -406,9 +406,9 @@ select_packages() 1) PACKAGES+=" $(select_browsers)" ;; 2) PACKAGES+=" $(select_editors)" ;; 3) PACKAGES+=" $(select_terminals)" ;; - 4) PACKAGES+=" $(select_music_and_video)" ;; - 5) PACKAGES+=" $(select_mail_and_chat)" ;; - 6) PACKAGES+=" $(select_office_and_editing)" ;; + 4) PACKAGES+=" $(select_multimedia)" ;; + 5) PACKAGES+=" $(select_mailchat)" ;; + 6) PACKAGES+=" $(select_professional)" ;; 7) PACKAGES+=" $(select_managment)" ;; 8) PACKAGES+=" $(select_extra)" ;; esac @@ -422,7 +422,7 @@ select_packages() # add mksh to package list if it was chosen as the login shell if [[ $MYSHELL == *mksh ]]; then - declare -g PACKAGES="mksh $PACKAGES" + PACKAGES+=" mksh" fi # remove duplicates and leading spaces @@ -521,7 +521,6 @@ edit_configs() edit_configs } - # dialog helper functions msgbox() diff --git a/src/lib/install.sh b/src/lib/install.sh index 5be5278..3ffaca3 100644 --- a/src/lib/install.sh +++ b/src/lib/install.sh @@ -48,6 +48,9 @@ install() # set up user login.. MUST be done after package operation and user creation oneshot login_manager + # fix any messed up file permissions from editing during install + chrun "chown -Rf $NEWUSER:users /home/$NEWUSER" + # drop off the user at the config editing menu edit_configs } @@ -193,7 +196,6 @@ create_user() # Create the user, set password, and make sure the ownership of ~/ is correct chrun "useradd -m -u 1000 -g users -G $groups -s $MYSHELL $NEWUSER" 2>$ERR chrun "chpasswd <<< '$NEWUSER:$USER_PASS'" - chrun "chown -Rf $NEWUSER:users /home/$NEWUSER" # for neovim set up ~/.config/nvim if [[ $PACKAGES =~ neovim ]]; then @@ -309,7 +311,12 @@ 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 + if [[ $LUKS && ! $LVM && $SYS == 'UEFI' && $BOOTLDR == 'grub' ]]; then + if [[ $LUKS_PASS ]]; then + luks_pass "$_LuksOpen" "$LUKS_NAME" || return 1 + fi + luks_keyfile + fi # new hooks needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM [[ $LVM ]] && add="lvm2" diff --git a/src/lib/luks.sh b/src/lib/luks.sh index b96993b..08f6321 100644 --- a/src/lib/luks.sh +++ b/src/lib/luks.sh @@ -178,10 +178,7 @@ luks_keyfile() # Without a keyfile, during boot the user will be asked # to enter password for decryption twice, this is annoying - if [[ ! -e $MNT/crypto_keyfile.bin ]]; then - infobox "$_LuksKeyFileTitle" "$_LuksKeyFileCreate" 0 - printf "$_LuksKeyFileCreate" - + if [[ ! -e $MNT/crypto_keyfile.bin && $LUKS_PASS && $LUKS_UUID ]]; then local n n="$(lsblk -lno NAME,UUID,TYPE | awk "/$LUKS_UUID/"' && /part|crypt|lvm/ {print $1}')" diff --git a/src/lib/lvm.sh b/src/lib/lvm.sh index 1d630e9..62c0858 100644 --- a/src/lib/lvm.sh +++ b/src/lib/lvm.sh @@ -85,9 +85,22 @@ get_lv_size() # check whether the value is greater than or equal to the LV remaining Size. # if not, convert into MB for VG space remaining. case ${VOLUME_SIZE:$lv:1} in - [Gg]) (( m >= VOL_GROUP_MB )) && ERR_SIZE=1 || VOL_GROUP_MB=$((VOL_GROUP_MB - m)) ;; - [Mm]) (( ${VOLUME_SIZE:0:$lv} >= VOL_GROUP_MB )) && ERR_SIZE=1 || VOL_GROUP_MB=$((VOL_GROUP_MB - s)) ;; - *) ERR_SIZE=1 + [Gg]) + if (( m >= VOL_GROUP_MB )); then + ERR_SIZE=1 + else + VOL_GROUP_MB=$((VOL_GROUP_MB - m)) + fi + ;; + [Mm]) + if (( ${VOLUME_SIZE:0:$lv} >= VOL_GROUP_MB )); then + ERR_SIZE=1 + else + VOL_GROUP_MB=$((VOL_GROUP_MB - s)) + fi + ;; + *) + ERR_SIZE=1 esac fi fi @@ -197,14 +210,20 @@ lvm_create_group() done # create it - infobox "$_LvmCreateVG" "$_LvmPvActBody1 $VOLUME_GROUP\n" 0 vgcreate -f "$VOLUME_GROUP" "$GROUP_PARTS" >/dev/null 2>$ERR echeck "vgcreate -f $VOLUME_GROUP $GROUP_PARTS" - # get volume size size and transform size to MB if size is given in GB - GROUP_SIZE=$(vgdisplay "$VOLUME_GROUP" | awk '/VG Size/ {print int($3)}') - GROUP_SIZE_TYPE="$(vgdisplay "$VOLUME_GROUP" | awk '/VG Size/ {print substr($NF, 0, 1)}')" - [[ $GROUP_SIZE_TYPE == 'G' ]] && VOL_GROUP_MB=$((GROUP_SIZE * 1000)) || VOL_GROUP_MB=$GROUP_SIZE + GROUP_SIZE=$(vgdisplay "$VOLUME_GROUP" | + awk '/VG Size/ {print int($3)}') + + GROUP_SIZE_TYPE="$(vgdisplay "$VOLUME_GROUP" | + awk '/VG Size/ {print substr($NF, 0, 1)}')" + + if [[ $GROUP_SIZE_TYPE == 'G' ]]; then + VOL_GROUP_MB=$((GROUP_SIZE * 1000)) + else + VOL_GROUP_MB=$GROUP_SIZE + fi # finished volume group creation local msg="$_LvmPvDoneBody1 $VOLUME_GROUP ($GROUP_SIZE $GROUP_SIZE_TYPE)" diff --git a/src/lib/mount.sh b/src/lib/mount.sh index e6eacde..a593f7f 100644 --- a/src/lib/mount.sh +++ b/src/lib/mount.sh @@ -42,7 +42,14 @@ mnt_menu() select_boot_partition || { BOOT_PART=""; return 1; } fi - select_boot_setup || { BOOTLDR=""; return 1; } + if select_bootloader; then + if [[ $BOOT_PART != "" ]]; then + mount_boot_part || return 1 + fi + else + BOOTLDR="" + return 1 + fi select_swap || return 1 select_extra_partitions || return 1 @@ -53,9 +60,7 @@ select_swap() { # Ask user to select partition or create swapfile tput civis - if ! SWAP_PART="$(menubox "$_SelSwpSetup" "$_SelSwpBody" 0 0 0 \ - "$_SelSwpNone" "-" "$_SelSwpFile" "$SYS_MEM" $PARTS)" || - [[ $SWAP_PART == "$_SelSwpNone" ]]; then + if ! SWAP_PART="$(menubox "$_SelSwpSetup" "$_SelSwpBody" 0 0 0 "$_SelSwpNone" "-" "$_SelSwpFile" "$SYS_MEM" $PARTS)" || [[ $SWAP_PART == "$_SelSwpNone" ]]; then SWAP_PART="" return 0 fi @@ -63,7 +68,6 @@ select_swap() if [[ $SWAP_PART == "$_SelSwpFile" ]]; then tput cnorm local i=0 - while ! [[ ${SWAP_SIZE:0:1} =~ [1-9] && ${SWAP_SIZE: -1} =~ (M|G) ]]; do (( i > 0 )) && msgbox "$_SelSwpSetup Error" "\n$_SelSwpErr $SWAP_SIZE\n" if ! SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "$SYS_MEM")"; then @@ -100,56 +104,15 @@ select_mountpoint() return 0 } -select_boot_setup() +select_bootloader() { - # choose bootloader and mountpoint (if needed) tput civis if ! BOOTLDR="$(menubox "$_PrepMount" "$_MntBootBody" 0 0 0 ${BOOTLDRS[$SYS]})"; then return 1 fi - # grub on BIOS needs an install device, NOT partition eg. /dev/sda - if [[ $SYS == 'BIOS' && $BOOTLDR == 'grub' && $BOOT_DEVICE == "" ]]; then - select_device 'boot' || return 1 - fi - - if [[ $BOOTLDR == 'systemd-boot' ]]; then - FILES[9]="/boot/loader/entries/$DIST.conf" - elif [[ $BOOTLDR == 'syslinux' ]]; then - if [[ $SYS == 'BIOS' ]]; then - FILES[9]="/boot/syslinux/syslinux.cfg" - if ! BCMDS[$BOOTLDR]="$(menubox "$_InstSysTitle" "$_InstSysBody" 0 0 0 \ - "syslinux-install_update -iam" "Install to MBR (Master Boot Record)" \ - "syslinux-install_update -i" "Install to root partition (/)")"; then - return 1 - fi - else - FILES[9]="/boot/EFI/syslinux/syslinux.cfg" - BCMDS[syslinux]="efibootmgr -c -d $BOOT_DEVICE -p $BOOT_PART_NUM -l /EFI/syslinux/syslinux.efi -L $DIST" - fi - else - FILES[9]="/etc/default/grub" - if [[ $SYS == 'UEFI' ]]; then - local ttype="i386-efi" - [[ $IS_64BIT == true ]] && ttype='x86_64-efi' - BCMDS[grub]+=" --target=$ttype --efi-directory=${BMNTS[$SYS-grub]} --bootloader-id=$DIST" - else - BCMDS[grub]+=" --target=i386-pc $BOOT_DEVICE" - fi - BCMDS[grub]+=" && grub-mkconfig -o /boot/grub/grub.cfg" - fi - - if [[ $BOOT_PART != "" ]]; then - infobox "$_PrepMount" "\nSetting up for the bootloader and mounting the boot partition.\n" 1 - setup_boot_device - if ! mount_partition "$BOOT_PART" "${BMNTS[$SYS-$BOOTLDR]}"; then - src /usr/share/archlabs/installer/lib/boot.sh - return 1 - fi - SEPERATE_BOOT=true - fi - - return 0 + [[ $BOOT_PART ]] && setup_boot_device + pre_${BOOTLDR} || return 1 } select_mount_opts() diff --git a/src/lib/package.sh b/src/lib/package.sh index 020d27d..82c2941 100644 --- a/src/lib/package.sh +++ b/src/lib/package.sh @@ -66,7 +66,7 @@ select_terminals() printf "%s" "$pkgs" } -select_music_and_video() +select_multimedia() { local pkgs="" pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \ @@ -84,7 +84,7 @@ select_music_and_video() printf "%s" "$pkgs" } -select_mail_and_chat() +select_mailchat() { local pkgs="" pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \ @@ -99,7 +99,7 @@ select_mail_and_chat() printf "%s" "$pkgs" } -select_office_and_editing() +select_professional() { local pkgs="" pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \ @@ -155,7 +155,7 @@ select_extra() "gpick" "Advanced color picker using GTK+ toolkit" off \ "gcolor2" "A simple GTK+2 color selector" off \ "plank" "An elegant, simple, and clean dock" off \ - "docky" "Full fledged dock that makes opening applications and managing windows faster and easier" off \ + "docky" "Full fledged dock for opening applications and managing windows" off \ "cairo-dock" "Light eye-candy fully themable animated dock" off)" printf "%s" "$pkgs" } diff --git a/src/lib/part.sh b/src/lib/part.sh index 9773d51..69a34d9 100644 --- a/src/lib/part.sh +++ b/src/lib/part.sh @@ -290,6 +290,16 @@ mount_partition() return 0 } +mount_boot_part() +{ + if ! mount_partition "$BOOT_PART" "${BMNTS[$SYS-$BOOTLDR]}"; then + src /usr/share/archlabs/installer/lib/boot.sh + return 1 + else + SEPERATE_BOOT=true + fi +} + find_partitions() { local str="$1" @@ -333,6 +343,8 @@ find_partitions() setup_boot_device() { + infobox "$_PrepMount" "\nSetting device flags for: $BOOT_PART\n" 1 + if [[ $BOOT_PART = /dev/nvme* ]]; then BOOT_DEVICE="${BOOT_PART%p[1-9]}" else diff --git a/src/lib/utils.sh b/src/lib/utils.sh index db3e6b3..65bc3f2 100644 --- a/src/lib/utils.sh +++ b/src/lib/utils.sh @@ -25,7 +25,7 @@ json() src() { # source a file ($1), if it fails we die with an error message - . "$1" || { printf "\nFailed to source file %s\n" "$1"; die 1; } + . "$1" 2>/dev/null || { printf "\nFailed to source file %s\n" "$1"; die 1; } } ssd() @@ -40,18 +40,22 @@ ssd() dev=${dev%[0-9]*} fi - [[ $(cat /sys/block/$dev/queue/rotational) -eq 0 ]] || return 1 + local i + i=$(cat /sys/block/$dev/queue/rotational 2>/dev/null) + [[ $i && $i -eq 0 ]] || return 1 } die() { - if (( $# >= 1 )); then local exitcode=$1 else local exitcode=0 fi + # reset SIGINT + trap - INT + tput cnorm if [[ -d $MNT ]] && command cd /; then umount_dir $MNT @@ -223,8 +227,6 @@ echeck() fi die 1 - - return 0 } debug() @@ -238,6 +240,8 @@ debug() umount_dir() { swapoff -a - [[ -d $1 ]] && umount -R $1 >/dev/null 2>&1 + if [[ -d $1 ]]; then + umount -R $1 >/dev/null 2>&1 + fi return 0 }