Fix: file permissions in the created user's home

This commit is contained in:
natemaia 2018-12-14 22:51:12 -08:00
parent 0572d16454
commit 83743ec8c8
10 changed files with 136 additions and 112 deletions

View File

@ -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

View File

@ -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
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
if [[ $SYS == 'UEFI' ]]; then
# 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
}

View File

@ -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()

View File

@ -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"

View File

@ -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}')"

View File

@ -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)"

View File

@ -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()

View File

@ -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"
}

View File

@ -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

View File

@ -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
}