Fix format asking permission and other small issues

This commit is contained in:
natemaia
2018-08-26 21:08:51 -07:00
parent 224ea1c18a
commit 0e51c6ce6a
8 changed files with 358 additions and 407 deletions

View File

@ -3,22 +3,16 @@
# vim:ft=sh:fdm=marker:fmr={,}
# This program is free software, provided under the GNU GPL
# Written by Nathaniel Maia for use in Archlabs
# Some ideas and code were taken from other installers
# AIF, Cnichi, Calamares, The Arch Wiki.. Credit where credit is due
# dry run performing no action, good for checking syntax errors
# set -n
######################################################################
## Script Setup Functions ##
######################################################################
# immutable variables {
readonly DIST="ArchLabs" # Linux distributor
readonly VER="1.6.54" # Installer version
readonly VER="1.6.58" # Installer version
readonly LIVE="liveuser" # Live session user
readonly MNT="/mnt/install" # Install mountpoint
readonly ERR="/tmp/errlog" # Built-in error log
@ -26,24 +20,15 @@ readonly EFI="/sys/firmware/efi/efivars"
readonly LIB="/usr/share/archlabs/installer/lib"
readonly TRN="/usr/share/archlabs/installer/lang"
# hardware check
readonly VM="$(dmesg | grep -i "hypervisor")"
# create a regex string of all usb devices on the system
for dev in $(lsblk -lno NAME,TRAN | awk '/usb/ {print $1}'); do
USB_DEVS="${dev}$([[ $USB_DEVS ]] && echo -n "|$USB_DEVS")"
done
# determine which device was used for booting to ignore later during partition select
readonly IGNORE_DEV="$(lsblk -lno NAME,TYPE,TRAN,MOUNTPOINT |
awk "/$USB_DEVS/"' && /\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')"
readonly SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE,TRAN |
awk '/disk/ && !'"/$IGNORE_DEV/"' {print "/dev/" $1 " " $2}')"
readonly LOCALES="$(awk '/\.UTF-8/ {gsub(/# .*|#/, ""); if($1) print $1 " -"}' /etc/locale.gen)"
readonly SYS_MEM=$(grep 'MemTotal' /proc/meminfo | awk '{print int($2 / 1024)}')
readonly DEV_COUNT="$(wc -l <<< "$SYS_DEVS")"
readonly KBD="$(find /usr/share/kbd/keymaps -name '*.map.gz')"
readonly CONSOLE_MAPS="$(awk '{gsub(/\.map\.gz|.*\//, ""); print $1 " -"}' <<< "$KBD" | sort -r)"
readonly LOCALES="$(awk '/\.UTF-8/ {gsub(/# .*|#/, ""); if($1) print $1 " -"}' /etc/locale.gen)"
readonly CONSOLE_MAPS="$(awk '{gsub(/\.map\.gz|.*\//, ""); print $1 " -"}' <<< "$KBD")"
readonly SYS_MEM=$(grep 'MemTotal' /proc/meminfo | awk '{print int($2 / 1024)}')
readonly SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ && !'"/$IGNORE_DEV/"' {print "/dev/" $1 " " $2}')"
readonly IGNORE_DEV="$(lsblk -lno NAME,MOUNTPOINT | awk '/\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')"
readonly DEV_COUNT="$(wc -l <<< "$SYS_DEVS")"
# create associative array for SUBZONES[zone], value is: 'sub-zone country_code'
declare -Ag SUBZONES
@ -73,24 +58,18 @@ tz Swahili ke Swahili bw Tswana ph Filipino id Indonesian my Malay tm Turkmen bt
lv Latvian md Moldavian mao Maori by Belarusian me Montenegrin mk Macedonian kh Khmer
az Azerbaijani"
declare -Agr BOOT_MNTS=(
declare -Agr BMNTS=(
[UEFI-grub]="/boot/efi" [UEFI-systemd-boot]="/boot" [BIOS-grub]="/boot"
[BIOS-syslinux]="/boot" [UEFI-syslinux]="/boot"
)
# static list of bootloaders & boot partition mountpoints stored as the system type (BIOS or UEFI)
declare -Agr BOOTLOADERS=([BIOS]="grub ${BOOT_MNTS[BIOS-grub]} syslinux ${BOOT_MNTS[BIOS-syslinux]}"
[UEFI]="grub ${BOOT_MNTS[UEFI-grub]} systemd-boot ${BOOT_MNTS[UEFI-systemd-boot]} syslinux ${BOOT_MNTS[UEFI-syslinux]}"
declare -Agr BOOTLDRS=([BIOS]="grub ${BMNTS[BIOS-grub]} syslinux ${BMNTS[BIOS-syslinux]}"
[UEFI]="grub ${BMNTS[UEFI-grub]} systemd-boot ${BMNTS[UEFI-systemd-boot]} syslinux ${BMNTS[UEFI-syslinux]}"
)
# static mkfs commands for each filesystem offered
declare -Agr FS_CMDS=(
[ext2]="mkfs.ext2 -q" [ext3]="mkfs.ext3 -q" [ext4]="mkfs.ext4 -q"
[f2fs]="mkfs.f2fs" [jfs]="mkfs.jfs -q" [xfs]="mkfs.xfs -f" [nilfs2]="mkfs.nilfs2 -q"
[ntfs]="mkfs.ntfs -q" [reiserfs]="mkfs.reiserfs -q" [vfat]="mkfs.vfat -F32"
)
# static filesystem mount options
declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]=""
[ext4]="dealloc - off discard - off nofail - off noacl - off relatime - off noatime - off nobarrier - off nodelalloc - off"
[jfs]="discard - off errors=continue - off errors=panic - off nointegrity - off"
@ -101,64 +80,40 @@ declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]=""
)
# }
luks_variable_init() {
declare -g LUKS=0
declare -g LVM=0
declare -g VOL_GROUP_MB=0
declare -g LUKS_NAME="cryptroot"
declare -g LUKS_PART=""
declare -g LUKS_PASS=""
declare -g LUKS_UUID=""
declare -g LUKS_DEV=""
declare -g MKINIT_HOOKS="shutdown"
declare -g SEPERATE_BOOT=0
}
initialize_variables() {
# Modified during runtime and are all globally accessible
# This is called once when the script is started, and again if/when an error occurs
# Some may never be used, depending on the system and choices made
init_variables() {
declare -g BT="$DIST Installer - (x86_64) - Version $VER"
declare -g ROOT_PART=""
declare -g BOOT_DEVICE=""
declare -g BOOT_PART=""
declare -g BOOTLOADER=""
declare -g BOOTLDR=""
declare -g EXTRA_MNT=""
declare -g EXTRA_MNTS=""
declare -g SWAP="none"
declare -g SWAP_SIZE="${SYS_MEM}M"
declare -g KERNEL="linux"
declare -g NEWUSER=""
declare -g USER_PASS=""
declare -g ROOT_PASS=""
declare -g LOGIN_WM=""
declare -g LOGIN_TYPE=""
declare -g INSTALL_WMS=""
declare -g KERNEL="linux"
declare -g WM_PACKAGES=""
declare -g EXTRA_PACKAGES=""
declare -g REMOVE_PKGS=""
declare -g CURRENT_MENU=""
declare -g MENU_HIGHLIGHT
declare -g EDITOR_CHOICE=""
declare -g MKINIT_HOOKS="shutdown"
declare -g MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate"
# boolean checks
declare -g IS_64BIT=false
declare -g AUTOLOGIN=false
declare -g CONFIG_DONE=false
declare -g IS_64BIT=false
declare -g SEPERATE_BOOT=false
# Commands used to install each bootloader.
# NOTE: syslinux and grub in particular can/will change during runtime
declare -Ag BOOT_CMDS=(
declare -Ag BCMDS=(
[syslinux]="syslinux-install_update -iam"
[grub]="grub-install --recheck --force"
[systemd-boot]="bootctl --path=${BOOT_MNTS[UEFI-systemd-boot]} install"
[systemd-boot]="bootctl --path=${BMNTS[UEFI-systemd-boot]} install"
)
# files able to be reviewed when finishing install
# item index [9] can change depending on which bootloader is selected
declare -Ag EDIT_FILES=(
[2]="/etc/X11/xorg.conf.d/00-keyboard.conf /etc/vconsole.conf /etc/default/keyboard"
declare -Ag FILES=(
[2]="/etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard /etc/vconsole.conf"
[3]="/etc/locale.conf /etc/default/locale"
[4]="/etc/hostname /etc/hosts"
[5]="/etc/sudoers"
@ -177,9 +132,61 @@ source_file() {
}
######################################################################
## System Setup Functions ##
## Setup ##
######################################################################
user_setup() {
tput cnorm
local values
values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \
--title " $_UserTitle " --insecure --mixedform "$_UserBody" 27 75 10 \
"$_Username" 1 1 "" 1 $((${#_Username} + 2)) 71 0 0 \
"$_Password" 2 1 "" 2 $((${#_Password} + 2)) 71 0 1 \
"$_Password2" 3 1 "" 3 $((${#_Password2} + 2)) 71 0 1 \
"$_RootBody" 6 1 "" 6 $((${#_RootBody} + 1)) 71 0 2 \
"$_Password" 8 1 "" 8 $((${#_Password} + 2)) 71 0 1 \
"$_Password2" 9 1 "" 9 $((${#_Password2} + 2)) 71 0 1)"
[[ $? != 0 || $values == "" ]] && return 1
local user
user="$(awk -F'~' '{print $1}' <<< "$values")"
local pass pass2
pass="$(awk -F'~' '{print $2}' <<< "$values")"
pass2="$(awk -F'~' '{print $3}' <<< "$values")"
local rpass rpass2
rpass="$(awk -F'~' '{print $5}' <<< "$values")"
rpass2="$(awk -F'~' '{print $6}' <<< "$values")"
# both root passwords are empty, so use the user passwords instead
[[ $rpass == "" && $rpass2 == "" ]] && { rpass="$pass"; rpass2="$pass2"; }
# make sure a username was entered and that the passwords match
if [[ ${#user} -eq 0 || $user =~ \ |\' || $user =~ [^a-z0-9\ ] || $pass == "" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then
if [[ $pass == "" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then
# password was left empty or doesn't match
if [[ $pass == "" ]]; then
msgbox "$_ErrTitle" "\nUser $_Password CANNOT be left empty.\n$_TryAgain"
elif [[ "$rpass" != "$rpass2" ]]; then
msgbox "$_ErrTitle" "$_RootPassErr\n$_TryAgain"
else
msgbox "$_ErrTitle" "$_UserPassErr\n$_TryAgain"
fi
else # bad username
msgbox "$_UserErrTitle" "$_UserErrBody"
user=""
fi
# recursively loop back unless the user cancels
user_setup || return 1
else
NEWUSER="$user"
USER_PASS="$pass"
ROOT_PASS="$rpass"
fi
return 0
}
select_language() {
tput civis
local lang
@ -272,58 +279,6 @@ setup_hostname() {
[[ $? != 0 || $HOSTNAME == "" ]] && return 1 || return 0
}
user_setup() {
tput cnorm
local values
values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \
--title " $_UserTitle " --insecure --mixedform "$_UserBody" 27 75 10 \
"$_Username" 1 1 "" 1 $((${#_Username} + 2)) 71 0 0 \
"$_Password" 2 1 "" 2 $((${#_Password} + 2)) 71 0 1 \
"$_Password2" 3 1 "" 3 $((${#_Password2} + 2)) 71 0 1 \
"$_RootBody" 6 1 "" 6 $((${#_RootBody} + 1)) 71 0 2 \
"$_Password" 8 1 "" 8 $((${#_Password} + 2)) 71 0 1 \
"$_Password2" 9 1 "" 9 $((${#_Password2} + 2)) 71 0 1)"
[[ $? != 0 || $values == "" ]] && return 1
local user
user="$(awk -F'~' '{print $1}' <<< "$values")"
local pass pass2
pass="$(awk -F'~' '{print $2}' <<< "$values")"
pass2="$(awk -F'~' '{print $3}' <<< "$values")"
local rpass rpass2
rpass="$(awk -F'~' '{print $5}' <<< "$values")"
rpass2="$(awk -F'~' '{print $6}' <<< "$values")"
# both root passwords are empty, so use the user passwords instead
[[ $rpass == "" && $rpass2 == "" ]] && { rpass="$pass"; rpass2="$pass2"; }
# make sure a username was entered and that the passwords match
if [[ ${#user} -eq 0 || $user =~ \ |\' || $user =~ [^a-z0-9\ ] || $pass == "" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then
if [[ $pass == "" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then
# password was left empty or doesn't match
if [[ $pass == "" ]]; then
msgbox "$_ErrTitle" "\nUser $_Password CANNOT be left empty.\n$_TryAgain"
elif [[ "$rpass" != "$rpass2" ]]; then
msgbox "$_ErrTitle" "$_RootPassErr\n$_TryAgain"
else
msgbox "$_ErrTitle" "$_UserPassErr\n$_TryAgain"
fi
else # bad username
msgbox "$_UserErrTitle" "$_UserErrBody"
user=""
fi
# recursively loop back unless the user cancels
user_setup || return 1
else
NEWUSER="$user"
USER_PASS="$pass"
ROOT_PASS="$rpass"
fi
return 0
}
window_manager() {
LOGIN_WM=""
LOGIN_TYPE=""
@ -342,11 +297,39 @@ window_manager() {
INSTALL_WMS="${INSTALL_WMS:-openbox}"
WM_NUM=$(awk '{print NF}' <<< "$INSTALL_WMS")
# packages needed for the selected window manager
for wm in $INSTALL_WMS; do
WM_LOGIN_CHOICES="${WM_LOGIN_CHOICES}$wm - "
case $wm in
openbox) WM_PACKAGES="$WM_PACKAGES $wm obconf archlabs-obkey archlabs-kickshaw tint2 conky" ;;
bspwm) WM_PACKAGES="$WM_PACKAGES $wm sxhkd" ;;
i3-gaps) WM_PACKAGES="$WM_PACKAGES $wm i3status perl-anyevent-i3" ;;
gnome) WM_PACKAGES="$WM_PACKAGES $wm gnome-extra" ;;
cinnamon) WM_PACKAGES="$WM_PACKAGES $wm" ;;
xfce4) WM_PACKAGES="$WM_PACKAGES $wm xfce4-goodies xfce4-pulseaudio-plugin" ;;
esac
done
if [[ $INSTALL_WMS =~ (openbox|bspwm|i3-gaps) ]]; then
WM_PACKAGES="$WM_PACKAGES termite thunar archlabs-polybar archlabs-screenlock archlabs-skippy-xd archlabs-oblogout lxappearance"
elif [[ $INSTALL_WMS =~ (xfce4) ]]; then
WM_PACKAGES="$WM_PACKAGES archlabs-oblogout archlabs-screenlock"
fi
EXTRA_PACKAGES="$WM_PACKAGES"
# add lightdm packages if chosen
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
EXTRA_PACKAGES="$EXTRA_PACKAGES lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings accountsservice"
fi
# if dwm is not the only WM chosen offer lightdm
if yesno "$_WMLogin" "$_LoginTypeBody\n" "xinit" "lightdm"; then
LOGIN_TYPE='lightdm'
else
LOGIN_TYPE='xinit'
FILES[11]="/home/$NEWUSER/.xinitrc"
else
LOGIN_TYPE='lightdm'
FILES[11]="/etc/lightdm/lightdm.conf $MNT/etc/lightdm/lightdm-gtk-greeter.conf"
fi
if yesno "$_WMLogin" "$_AutoLoginBody\n"; then
@ -375,7 +358,8 @@ window_manager() {
}
extra_packages() {
EXTRA_PACKAGES="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
local pkgs
pkgs="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
--title " $_WMChoice " --checklist "$_WMChoiceBody\n" 0 0 20 \
"firefox" "A popular open-source graphical web browser from Mozilla" off \
"chromium" "an open-source graphical web browser based on the Blink rendering engine" off \
@ -448,9 +432,9 @@ extra_packages() {
"ttf-fira-code" "Monospaced font with programming ligatures" off \
"noto-fonts-cjk" "Google Noto CJK fonts (Chinese, Japanese, Korean)" off \
"noto-fonts noto-fonts-emoji" "Google Noto fonts and emoji" off)"
[[ $? != 0 ]] && return 1
[[ $EXTRA_PACKAGES =~ kdenlive ]] && EXTRA_PACKAGES="$EXTRA_PACKAGES kdebase-runtime dvdauthor frei0r-plugins breeze breeze-gtk"
[[ $pkgs =~ kdenlive ]] && pkgs="$pkgs kdebase-runtime dvdauthor frei0r-plugins breeze breeze-gtk"
EXTRA_PACKAGES="$pkgs $EXTRA_PACKAGES"
return 0
}
@ -497,9 +481,57 @@ mirrorlist_cmd() {
}
######################################################################
## Main Menu Functions ##
## Menus ##
######################################################################
display_selection() {
local msg="Below are the configuration and setup values used during install
Root Partition: $ROOT_PART
Boot Partition: $BOOT_PART
Bootloader: $BOOTLDR
Boot Mount: ${BMNTS[$SYS-$BOOTLDR]}
Swap: $SWAP
Extra: $EXTRA_MNTS
LUKS: $LUKS
LVM: $LVM
New User: $NEWUSER
Autologin: $AUTOLOGIN
Login Type: $LOGIN_TYPE
Login Session: $LOGIN_WM
Hostname: $HOSTNAME
Locale: $LOCALE
Keymap: $KEYMAP
Timezone: $ZONE/$SUBZONE
Kernel: $KERNEL
Sessions: $INSTALL_WMS
Mirrors: $MIRROR_CMD
Packages: $EXTRA_PACKAGES"
msgbox "Install Info" "\n$msg\n"
return 0
}
configure_install() {
# whether to use a custom mirror sorting command later
setup_hostname || return 1
setup_locale || return 1
setup_timezone || return 1
mirrorlist_cmd || return 1
user_setup || return 1
window_manager || return 1
choose_kernel
extra_packages || return 1
CONFIG_DONE=true
return 0
}
edit_configs() {
if [[ $CURRENT_MENU != "edit" ]]; then
MENU_HIGHLIGHT=1
@ -512,13 +544,14 @@ edit_configs() {
MENU_HIGHLIGHT=$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_EditTitle " --default-item $MENU_HIGHLIGHT --menu "$_EditBody" 0 0 0 \
"1" "$_Done" "2" "keyboard" "3" "language + locale" "4" "hostname" "5" "sudoers" \
"6" "mkinitcpio.conf" "7" "fstab" "8" "crypttab" "9" "$BOOTLOADER" "10" "pacman.conf")
"6" "mkinitcpio.conf" "7" "fstab" "8" "crypttab" "9" "$BOOTLDR" "10" "pacman.conf" \
"11" "$LOGIN_TYPE")
if [[ $MENU_HIGHLIGHT == "" || $MENU_HIGHLIGHT == 1 ]]; then
wrap_up "$_InstFinBody" 'Exit & Reboot' 'Go Back' 'reboot'
else
local existing_files=""
for f in $(echo "${EDIT_FILES[$MENU_HIGHLIGHT]}"); do
for f in $(echo "${FILES[$MENU_HIGHLIGHT]}"); do
[[ -e ${MNT}$f ]] && existing_files="$existing_files ${MNT}$f"
done
@ -536,20 +569,6 @@ edit_configs() {
edit_configs
}
configure_install() {
# whether to use a custom mirror sorting command later
setup_hostname || return 1
setup_locale || return 1
setup_timezone || return 1
user_setup || return 1
mirrorlist_cmd || return 1
window_manager || return 1
extra_packages || return 1
choose_kernel
CONFIG_DONE=true
return 0
}
main() {
local retval
@ -563,12 +582,13 @@ main() {
tput civis
MENU_HIGHLIGHT=$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepTitle " --default-item $MENU_HIGHLIGHT --menu "$_PrepBody" 0 0 0 \
"1" "$_PrepShowDev" "2" "$_PrepParts" "3" "$_PrepLUKS" "4" "$_PrepLVM" \
"5" "$_PrepMount" "6" "$_PrepConfig" "7" "$_PrepInstall" "8" "$_Done")
"1" "$_PrepShowDev" "2" "$_PrepParts" "3" "$_PrepLUKS" "4" "$_PrepLVM" \
"5" "$_PrepMount" "6" "$_PrepConfig" "7" "Check Selections" "8" "$_PrepInstall" \
"9" "$_Done")
# if trying to install the system, make sure the partitions are mounted
# and that the needed config variables and user variables have been set up
if [[ $MENU_HIGHLIGHT && $MENU_HIGHLIGHT -eq 7 ]]; then
if [[ $MENU_HIGHLIGHT && $MENU_HIGHLIGHT -eq 8 ]]; then
check_install_ready
retval=$?
[[ $retval -gt 0 ]] && { MENU_HIGHLIGHT=$retval; return 1; }
@ -581,36 +601,27 @@ main() {
4) lvm_menu || MENU_HIGHLIGHT=1 ;;
5) mount_main || MENU_HIGHLIGHT=1 ;;
6) configure_install ;;
7) install_main && edit_configs ;;
7) display_selection ;;
8) install_main && edit_configs ;;
*) wrap_up "$_CloseInstBody" 'Exit' 'Back' 'exit'
esac
}
######################################################################
## Execution ##
######################################################################
# source the library files before anything else to get access to functions
for file in utils.sh mount.sh partition.sh bootloader.sh package.sh lvm.sh luks.sh install.sh; do
source_file $LIB/$file
for file in utils mount partition bootloader lvm luks install; do
source_file $LIB/$file.sh
done
# trap ctrl-c and call sigint() to properly exit, without this
# exiting via Ctrl-c can leave the terminal in a messed up state
trap sigint INT
trap sigint INT # trap Ctrl-C and call sigint() to properly exit
for arg in "$@"; do
[[ $arg == "--debug" || $arg == "-d" ]] && debug # from $LIB/utils.sh
[[ $arg == "--debug" || $arg == "-d" ]] && debug
done
initialize_variables
luks_variable_init
init_variables
select_language
setup_keymap
check_requirements
identify_system
msgbox "$_WelTitle $DIST Installer" "$_WelBody"
while true; do