Cleanup needless splitting of code, add more DMs, remove package bit from background install

This commit is contained in:
natemaia 2019-08-26 20:16:36 -07:00
parent 831cfbcc58
commit af36aedb2b

View File

@ -5,7 +5,7 @@
# Some ideas and code reworked from other resources
# AIF, Cnichi, Calamares, Arch Wiki.. Credit where credit is due
VER="2.0.58" # installer version
VER="2.0.59" # installer version
DIST="ArchLabs" # linux distributor
MNT="/mnt" # install mountpoint
ANS="/tmp/ans" # dialog answer file
@ -82,19 +82,11 @@ WARN='' # issued mounting/partitioning warning
SEP_BOOT='' # separate boot partition for BIOS
AUTOLOGIN='' # enable autologin for xinit
CONFIG_DONE='' # basic configuration is finished
BROADCOM_WL='' # fixes for broadcom cards eg. BCM4352
FORMATTED='' # partitions we formatted and should allow skipping
AUTO_ROOT_PART='' # root value from auto partition
AUTO_BOOT_PART='' # boot value from auto partition
# iso base, pacstrap when running the installer from a stock arch iso
ISO_BASE="b43-firmware b43-fwcutter broadcom-wl clonezilla dhclient dhcpcd ethtool wpa_supplicant "
ISO_BASE+="exfat-utils f2fs-tools gptfdisk vim hdparm ipw2100-fw ipw2200-fw nfs-utils nilfs-utils ntfs-3g "
ISO_BASE+="pacman-contrib parted rsync sdparm smartmontools wget wireless_tools wpa_actiond xl2tpd dialog parted "
ISO_BASE+="alsa-firmware alsa-lib alsa-plugins pulseaudio pulseaudio-alsa networkmanager w3m htop wireless-regdb "
ISO_BASE+="lm_sensors lsb-release p7zip pamixer reflector unrar ranger terminus-font ttf-dejavu archlabs-keyring"
# archlabs base
AL_BASE_PKGS="archlabs-skel-base archlabs-fonts archlabs-themes archlabs-dARK archlabs-icons archlabs-wallpapers archlabs-scripts"
@ -220,6 +212,8 @@ declare -A FS_OPTS=(
declare -A LOGIN_PKGS=(
[xinit]='xorg-xinit'
[ly]='archlabs-ly'
[gdm]='gdm'
[sddm]='sddm'
[lightdm]='lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings accountsservice'
) # }
@ -413,31 +407,30 @@ select_login()
{
[[ $INSTALL_WMS ]] || return 0
AUTOLOGIN='' # no autologin unless using xinit
if [[ -z $LOGIN_TYPE ]]; then
dlg LOGIN_TYPE menu "Login Management" "\nSelect what kind of login management to use." \
"xinit" "Console login without a display manager" \
"ly" "TUI display manager with a ncurses-like interface" \
"lightdm" "Lightweight display manager with a gtk greeter" || return 1
"lightdm" "Lightweight display manager with a gtk greeter" \
"gdm" "Gnome display manager" \
"sddm" "Simple desktop display manager" || return 1
fi
if [[ $LOGIN_TYPE == 'xinit' ]]; then
EDIT_FILES[login]="/home/$NEWUSER/.xinitrc /home/$NEWUSER/.xprofile"
# define what wm/de to use for xinit
case $LOGIN_TYPE in
ly) EDIT_FILES[login]="/etc/ly/config.ini" ;;
gdm|sddm) EDIT_FILES[login]="" ;;
lightdm) EDIT_FILES[login]="/etc/lightdm/lightdm.conf /etc/lightdm/lightdm-gtk-greeter.conf" ;;
xinit) EDIT_FILES[login]="/home/$NEWUSER/.xinitrc /home/$NEWUSER/.xprofile"
if (( $(wc -w <<< "$INSTALL_WMS") > 1 )); then
dlg LOGIN_WM menu "Login Management" "$_login" $LOGIN_CHOICES || return 1
LOGIN_WM="${WM_SESSIONS[$LOGIN_WM]}"
fi
[[ -z $LOGIN_WM ]] && LOGIN_WM="${WM_SESSIONS[${INSTALL_WMS%% *}]}"
# autologin
yesno "Autologin" "$(sed "s|USER|$NEWUSER|g; s|RC|$LOGINRC|g" <<< "$_autologin")" && AUTOLOGIN=true || AUTOLOGIN=''
else
AUTOLOGIN='' # no autologin for DMs
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
EDIT_FILES[login]="/etc/lightdm/lightdm.conf /etc/lightdm/lightdm-gtk-greeter.conf"
elif [[ $LOGIN_TYPE == 'ly' ]]; then
EDIT_FILES[login]="/etc/ly/config.ini"
fi
fi
;;
esac
}
select_config()
@ -759,6 +752,7 @@ part_menu()
if [[ $devhash != "$(lsblk -f | base64)" ]]; then
msg "Probing Partitions" "\nInforming the kernel of partition changes using partprobe.\n" 0
partprobe >/dev/null 2>&1
[[ $choice == 'auto' ]] && return
fi
done
}
@ -774,21 +768,6 @@ part_show()
msg "Device Tree" "\n\n$txt\n\n"
}
part_swap()
{
if [[ $1 == "$MNT/swapfile" && $SWAP_SIZE ]]; then
fallocate -l $SWAP_SIZE "$1" 2>$ERR
errshow "fallocate -l $SWAP_SIZE $1"
chmod 600 "$1" 2>$ERR
errshow "chmod 600 $1"
fi
mkswap "$1" >/dev/null 2>$ERR
errshow "mkswap $1"
swapon "$1" >/dev/null 2>$ERR
errshow "swapon $1"
return 0
}
part_auto()
{
local device="$1" table="$2" boot_fs="$3" size="$4" dev_info=""
@ -938,6 +917,21 @@ part_find()
return 0
}
part_swap()
{
if [[ $1 == "$MNT/swapfile" && $SWAP_SIZE ]]; then
fallocate -l $SWAP_SIZE "$1" 2>$ERR
errshow "fallocate -l $SWAP_SIZE $1"
chmod 600 "$1" 2>$ERR
errshow "chmod 600 $1"
fi
mkswap "$1" >/dev/null 2>$ERR
errshow "mkswap $1"
swapon "$1" >/dev/null 2>$ERR
errshow "swapon $1"
return 0
}
part_mount()
{
local part="$1" mountp="${MNT}$2" fs=""
@ -1338,7 +1332,6 @@ install_main()
install_user
install_login
chrun "chown -Rf $NEWUSER:users /home/$NEWUSER"
sleep 1
while :; do
dlg choice menu "Finalization" "$_edit" \
@ -1357,7 +1350,7 @@ install_main()
if [[ -z $choice || $choice == 'finished' ]]; then
[[ $DEBUG == true && -r $DBG ]] && vim $DBG
die 127
clear && die 127
else
local exists=''
for f in ${EDIT_FILES[$choice]}; do
@ -1374,29 +1367,14 @@ install_main()
install_base()
{
if [[ $RSYNC_PID || $MIRROR_PID ]]; then
local oldmsg="" msg=""
if kill -0 "$RSYNC_PID" 2>/dev/null || kill -0 "$MIRROR_PID" 2>/dev/null; then
printf "\nOne or more background install processes are still running, grabbing their output...\n"
printf "\nOne or more background install processes are still running, grabbing their output...\n" && cat /tmp/bg_out
while kill -0 "$RSYNC_PID" 2>/dev/null || kill -0 "$MIRROR_PID" 2>/dev/null; do
msg="$(tail -n 1 /tmp/bg_out)"
if [[ "$msg" != "$oldmsg" ]]; then
printf "\n%s" "$msg"
oldmsg="$msg"
else
printf "."
sleep 0.5
fi
sleep 1
done
fi
trap - EXIT
unset RSYNC_PID MIRROR_PID
else
rsync -ahv /run/archiso/sfs/airootfs/ $MNT/ 2>$ERR
errshow 1 "rsync -ahv /run/archiso/sfs/airootfs/ $MNT/"
install_mirrorlist "$MNT/etc/pacman.d/mirrorlist"
chrun "pacman -Syyu --noconfirm && pacman -S $BASE_PKGS --needed --noconfirm"
fi
rm -rf $MNT/etc/mkinitcpio-archiso.conf
find $MNT/usr/lib/initcpio -name 'archiso*' -type f -delete
@ -1426,11 +1404,6 @@ install_base()
chrun "locale-gen"
chrun "ln -svf /usr/share/zoneinfo/$ZONE/$SUBZ /etc/localtime"
if [[ $BROADCOM_WL ]]; then
echo 'blacklist bcma' >> $MNT/etc/modprobe.d/blacklist.conf
rm -f $MNT/etc/modprobe/
fi
cat > $MNT/etc/X11/xorg.conf.d/00-keyboard.conf <<- EOF
# Use localectl(1) to instruct systemd-localed to update it.
Section "InputClass"
@ -1544,64 +1517,25 @@ install_user()
sed -i '/compton/d' $MNT/home/$NEWUSER/.xprofile $MNT/root/.xprofile
fi
# create user home directories (Music, Documents, Downloads, etc..)
chrun 'xdg-user-dirs-update'
return 0
}
install_xinit()
{
if [[ $INSTALL_WMS ]]; then
if [[ -e $MNT/home/$NEWUSER/.xinitrc ]] && grep -q 'exec' "$MNT/home/$NEWUSER/.xinitrc"; then
sed -i "/exec/ c exec ${LOGIN_WM}" "$MNT/home/$NEWUSER/.xinitrc"
elif [[ $INSTALL_WMS ]]; then
printf "exec %s\n" "$LOGIN_WM" >> "$MNT/home/$NEWUSER/.xinitrc"
else
printf "exec %s\n" "$LOGIN_WM" >> "$MNT/home/$NEWUSER/.xinitrc"
fi
elif [[ -e $MNT/home/$NEWUSER/.xinitrc ]]; then
# no sessions available so remove the exec from ~/.xinitrc and return
sed -i '/exec/d' "$MNT/home/$NEWUSER/.xinitrc"
return 0
fi
[[ ${EDIT_FILES[login]} == *"$LOGINRC"* ]] || EDIT_FILES[login]+=" /home/$NEWUSER/$LOGINRC"
if [[ $AUTOLOGIN ]]; then
sed -i "s/root/${NEWUSER}/g" $SERVICE/autologin.conf
cat > "$MNT/home/$NEWUSER/$LOGINRC" <<- EOF
# ~/$LOGINRC
# sourced by ${MYSHELL##*/} when used as a login shell
# automatically run startx when logging in on tty1
[ -z \$DISPLAY ] && [ \$XDG_VTNR -eq 1 ] && exec startx
EOF
else
rm -rf $SERVICE
fi
}
install_ly()
{
rm -rf "$SERVICE" "$MNT/home/$NEWUSER"/.{xinitrc,profile,zprofile,bash_profile}
chrun 'systemctl enable ly.service' 2>$ERR
errshow 1 "systemctl enable ly.service"
}
install_login()
{
local serv="$MNT/etc/systemd/system/getty@tty1.service.d"
echo "Setting up $LOGIN_TYPE"
SERVICE="$MNT/etc/systemd/system/getty@tty1.service.d"
install_${LOGIN_TYPE:-xinit}
}
install_lightdm()
{
rm -rf "$SERVICE" "$MNT/home/$NEWUSER"/.{xinitrc,profile,zprofile,bash_profile}
chrun 'systemctl enable lightdm.service' 2>$ERR
errshow 1 "systemctl enable lightdm.service"
case $LOGIN_TYPE in
ly|sddm|gdm|lightdm)
rm -rf "$serv" "$MNT/home/$NEWUSER/.xinitrc"
chrun "systemctl enable $LOGIN_TYPE.service" 2>$ERR
errshow 1 "systemctl enable $LOGIN_TYPE.service"
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
cat > $MNT/etc/lightdm/lightdm-gtk-greeter.conf <<- EOF
# LightDM GTK+ Configuration
[greeter]
default-user-image=/usr/share/icons/ArchLabs-Dark/64x64/places/distributor-logo-archlabs.png
background=/usr/share/backgrounds/archlabs/archlabs.jpg
@ -1610,19 +1544,33 @@ install_lightdm()
font-name=DejaVu Sans Mono 11
position=30%,end 50%,end
EOF
fi
;;
xinit)
if [[ $INSTALL_WMS ]]; then
sed -i "/exec/ c exec ${LOGIN_WM}" "$MNT/home/$NEWUSER/.xinitrc"
elif [[ -e $MNT/home/$NEWUSER/.xinitrc ]]; then
sed -i '/exec/d' "$MNT/home/$NEWUSER/.xinitrc"
return 0
fi
if [[ $AUTOLOGIN ]]; then
sed -i "s/root/${NEWUSER}/g" $serv/autologin.conf
cat > "$MNT/home/$NEWUSER/$LOGINRC" <<- EOF
# automatically run startx when logging in on tty1
[ -z \$DISPLAY ] && [ \$XDG_VTNR -eq 1 ] && exec startx
EOF
else
rm -rf $serv
fi
;;
esac
}
install_packages()
{
local rmpkg=""
local rmpkg="archlabs-installer "
local inpkg="$BASE_PKGS ${LOGIN_PKGS[$LOGIN_TYPE]} $PACKAGES $USER_PKGS "
if pacman -Qsq 'archlabs-installer' >/dev/null 2>&1; then
rmpkg+="archlabs-installer "
elif [[ -e "$MNT/usr/bin/archlabs-installer" ]]; then
rm -f "$MNT/usr/bin/archlabs-installer"
fi
# add extra packages chosen throughout the install
if [[ $MYSHELL == '/usr/bin/zsh' ]]; then
inpkg+="zsh-completions "
@ -1630,6 +1578,8 @@ install_packages()
rmpkg+="zsh "
[[ $MYSHELL == '/usr/bin/mksh' ]] && inpkg+="mksh "
fi
# using a different kernel, remove the stock one
if [[ $KERNEL != 'linux' ]]; then
inpkg+="$KERNEL "
rmpkg+="linux "
@ -1648,7 +1598,7 @@ install_packages()
chrun "pacman -Syyu --noconfirm"
# remove the packages we don't want on the installed system
[[ $rmpkg ]] && chrun "pacman -Rns $rmpkg --noconfirm"
[[ $rmpkg ]] && chrun "pacman -Rnsc $rmpkg --noconfirm"
# reinstalling iputils fixes the network issue for non-root users
chrun "pacman -S iputils $UCODE --noconfirm"
@ -1742,15 +1692,11 @@ install_mirrorlist()
install_background()
{
yesno "Background Install" "\nBegin install in the background?\n" || return 0
msg "Background Install" "\nInstall will now begin in the background?\n" 2
rsync -a /run/archiso/sfs/airootfs/ $MNT/ &
RSYNC_PID=$!
mkdir -p $MNT/var/lib/pacman # can help with pacman errors
( install_mirrorlist "$MNT/etc/pacman.d/mirrorlist" >/dev/null 2>&1 && sleep 1 && chrun "pacman -Syyu $BASE_PKGS --needed --noconfirm" >> /tmp/bg_out 2>&1 ) &
( install_mirrorlist "$MNT/etc/pacman.d/mirrorlist" >>/tmp/bg_out 2>&1 ) &
MIRROR_PID=$!
# end the background processes before exiting
trap "kill $RSYNC_PID $MIRROR_PID 2>/dev/null" EXIT
}
@ -2202,7 +2148,7 @@ luks_open()
[[ $LUKS_PART ]] || return 1
luks_pass "$_luksopen" || return 1
msg "$_luksopen" "\nOpening encrypted partition: $LUKS_NAME\n\nDevice or volume used: $LUKS_PART\n" 0
msg "$_luksopen" "\nOpening encrypted partition: $LUKS_NAME\n\nUsing device/volume: $LUKS_PART\n" 0
cryptsetup open --type luks "$LUKS_PART" "$LUKS_NAME" <<< "$LUKS_PASS" 2>$ERR
errshow "cryptsetup open --type luks $LUKS_PART $LUKS_NAME" || return 1
LUKS='encrypted'; luks_show
@ -2264,7 +2210,7 @@ luks_pass()
luks_show()
{
sleep 0.5
msg "$_luksnew" "\nEncrypted partition opened and ready for mounting.\n\n$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE "$LUKS_PART")\n\n"
msg "$_luksnew" "\nEncrypted partition ready for mounting.\n\n$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE "$LUKS_PART")\n\n"
}
luks_setup()
@ -2497,13 +2443,6 @@ errshow()
return 1
}
load_bcm()
{
msg "Broadcom Wireless Setup" "\nDetected chipset is Broadcom BCM4352\n\nDisabling bcma/b43 modules and loading wl module.\n" 1
{ rmmod wl; rmmod bcma; rmmod b43; rmmod ssb; modprobe wl; depmod -a; } >/dev/null 2>&1
BROADCOM_WL=true
}
prechecks()
{
local i=1
@ -2638,10 +2577,6 @@ system_devices
msg "Welcome to the $DIST Installer" "\nThis will help you get $DIST setup on your system.\nHaving previous GNU/Linux and shell experience will be an asset, however we try our best to keep things simple.\n\nIf you are unsure about an option, a default will be listed or\nthe first selected option will usually be the default (excluding language and timezone).\n\n\nMenu Navigation:\n\n - Select items with the arrow keys or the option number.\n - Use [Space] to toggle options and [Enter] to confirm.\n - Switch between buttons using [Tab] or the arrow keys.\n - Use [Page Up] and [Page Down] to jump whole pages\n - Press the highlighted key of an option to select it.\n"
select_keymap || { clear; die 0; }
# try to fix problematic broadcom wireless chipset before network check
lspci -vnn -d 14e4: | grep -q 'BCM4352' && load_bcm
net_connect || { msg "Not Connected" "\nThis installer requires an active internet connection.\n\nExiting..\n" 2; die 1; }
while :; do