Split the large amount of varaible setup to a lib file

This commit is contained in:
natemaia
2018-09-01 12:16:12 -07:00
parent e948933780
commit 432e82f651
3 changed files with 110 additions and 148 deletions

View File

@ -12,23 +12,27 @@
# immutable variables {
readonly DIST="ArchLabs" # Linux distributor
readonly VER="1.6.67" # Installer version
readonly VER="1.6.69" # Installer version
readonly LIVE="liveuser" # Live session user
readonly MNT="/mnt/install" # Install mountpoint
readonly ERR="/tmp/errlog" # Built-in error log
readonly EFI="/sys/firmware/efi/efivars"
readonly LIB="/usr/share/archlabs/installer/lib"
readonly TRN="/usr/share/archlabs/installer/lang"
readonly RUN="/run/archiso/bootmnt/arch/boot"
readonly VM="$(dmesg | grep -i "hypervisor")"
readonly KBD="$(find /usr/share/kbd/keymaps -name '*.map.gz')"
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 IGNORE_DEV="$(lsblk -lno NAME,MOUNTPOINT | awk '/\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')"
if [[ $IGNORE_DEV ]]; then
readonly SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ && !'"/$IGNORE_DEV/"' {print "/dev/" $1 " " $2}')"
else
@ -43,11 +47,12 @@ elif [[ $(grep 'AuthenticAMD' /proc/cpuinfo) ]]; then
readonly UCODE="amd-ucode.img"
fi
# create associative array for SUBZONES[zone], value is: 'sub-zone country_code'
declare -Ag SUBZONES
# create associative array for SUBZONES[zone]
declare -A SUBZONES
for zone in America Australia Asia Atlantic Africa Europe Indian Pacific Arctic Antarctica; do
SUBZONES[$zone]="$(awk "/$zone\// {gsub(/$zone\//, \"\"); print \$3 \" \"\$1}" /usr/share/zoneinfo/zone.tab)"
done
readonly SUBZONES # make it read only
if [[ $DISPLAY && $TERM != 'linux' ]]; then
@ -71,19 +76,22 @@ 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 BMNTS=(
declare -Ar BMNTS=(
[UEFI-grub]="/boot/efi" [UEFI-systemd-boot]="/boot" [BIOS-grub]="/boot"
[BIOS-syslinux]="/boot" [UEFI-syslinux]="/boot"
)
declare -Agr BOOTLDRS=([BIOS]="grub ${BMNTS[BIOS-grub]} syslinux ${BMNTS[BIOS-syslinux]}"
declare -Ar 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]}"
)
declare -Agr FS_CMDS=(
declare -Ar 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"
)
declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]=""
declare -Ar 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"
[reiserfs]="acl - off nolog - off notail - off replayonly - off user_xattr - off"
@ -91,41 +99,43 @@ declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]=""
[nilfs2]="discard - off nobarrier - off errors=continue - off errors=panic - off order=relaxed - off order=strict - off norecovery - off"
[f2fs]="data_flush - off disable_roll_forward - off disable_ext_identify - off discard - off fastboot - off flush_merge - off inline_xattr - off inline_data - off inline_dentry - off no_heap - off noacl - off nobarrier - off noextent_cache - off noinline_data - off norecovery - off"
)
# }
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 BOOTLDR=""
declare -g EXTRA_MNT=""
declare -g EXTRA_MNTS=""
declare -g SWAP="none"
declare -g SWAP_SIZE="${SYS_MEM}M"
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 MKINIT_HOOKS="shutdown"
declare -g MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate"
BT="$DIST Installer - (x86_64) - Version $VER"
ROOT_PART=""
BOOT_DEVICE=""
BOOT_PART=""
BOOTLDR=""
EXTRA_MNT=""
EXTRA_MNTS=""
SWAP="none"
SWAP_SIZE="${SYS_MEM}M"
NEWUSER=""
USER_PASS=""
ROOT_PASS=""
LOGIN_WM=""
LOGIN_TYPE=""
INSTALL_WMS=""
KERNEL="linux"
WM_PACKAGES=""
EXTRA_PACKAGES=""
MKINIT_HOOKS="shutdown"
MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate"
declare -g IS_64BIT=false
declare -g AUTOLOGIN=false
declare -g CONFIG_DONE=false
declare -g SEPERATE_BOOT=false
IS_64BIT=false
AUTOLOGIN=false
CONFIG_DONE=false
SEPERATE_BOOT=false
declare -Ag BCMDS=(
declare -A BCMDS=(
[syslinux]="syslinux-install_update -iam"
[grub]="grub-install --recheck --force"
[systemd-boot]="bootctl --path=${BMNTS[UEFI-systemd-boot]} install"
[systemd-boot]="bootctl --path=/boot install"
)
declare -Ag FILES=(
declare -A 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"
@ -139,15 +149,9 @@ init_variables() {
}
source_file() {
. $1 2>/dev/null && return 0
echo -e "\nFailed to source library file $1"
die 1
. $1 2>/dev/null && return 0 || { echo -e "\nFailed to source library file $1"; die 1; }
}
######################################################################
## Setup ##
######################################################################
user_setup() {
tput cnorm
@ -212,7 +216,7 @@ select_language() {
"9" "Magyar (hu_HU)" "10" "Chinese (zh_CN)")
source_file $TRN/english.trans
declare -g FONT="ter-i16n"
FONT="ter-i16n"
case $lang in
1) LOC="en_US.UTF-8" ;;
@ -241,7 +245,6 @@ select_language() {
setup_keymap() {
tput civis
declare -g KEYMAP
KEYMAP="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepLayout " --menu "$_XMapBody" 20 70 12 $KEYMAPS)"
[[ $? != 0 || $KEYMAP == "" ]] && return 1
@ -266,13 +269,11 @@ setup_keymap() {
setup_timezone() {
tput civis
declare -g ZONE
ZONE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_TimeZTitle " --menu "$_TimeZBody" 20 70 10 America - Australia - \
Asia - Atlantic - Africa - Europe - Indian - Pacific - Arctic - Antarctica -)"
[[ $? != 0 || $ZONE == "" ]] && return 1
declare -g SUBZONE
SUBZONE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_TimeZTitle " --menu "$_TimeSubZBody" 20 70 12 ${SUBZONES[$ZONE]})"
[[ $? != 0 || $SUBZONE == "" ]] && return 1
@ -471,13 +472,10 @@ mirrorlist_cmd() {
return 0
}
######################################################################
## Menus ##
######################################################################
display_selection() {
local msg="Configuration values used for install
Root Partition: $ROOT_PART
Boot Partition: $BOOT_PART
@ -510,12 +508,10 @@ Packages: $EXTRA_PACKAGES"
configure_install() {
tput cnorm
declare -g HOSTNAME
HOSTNAME="$(getinput "$_ConfHost" "$_HostNameBody" "${DIST,,}")"
[[ $? != 0 || $HOSTNAME == "" ]] && return 1
tput civis
declare -g LOCALE
LOCALE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_ConfLocale " --menu "$_LocaleBody" 25 70 20 $LOCALES)"
[[ $? != 0 || $LOCALE == "" ]] && return 1
@ -525,11 +521,8 @@ configure_install() {
user_setup || return 1
window_manager || return 1
if yesno 'Choose Kernel' "\nUse the current Linux kernel or the LTS kernel?\n" 'Current' 'LTS'; then
KERNEL='linux'
else
KERNEL='linux-lts'
fi
local msg="\nUse the current Linux kernel or the LTS kernel?\n"
yesno 'Choose Kernel' "$msg" 'Current' 'LTS' && KERNEL='linux' || KERNEL='linux-lts'
extra_packages || return 1
CONFIG_DONE=true
@ -541,7 +534,7 @@ edit_configs() {
MENU_HIGHLIGHT=1
CURRENT_MENU="edit"
elif (( MENU_HIGHLIGHT < 10 )); then
((MENU_HIGHLIGHT++))
(( MENU_HIGHLIGHT++ ))
fi
tput civis
@ -550,8 +543,9 @@ edit_configs() {
"1" "$_Done" "2" "keyboard" "3" "language + locale" "4" "hostname" "5" "sudoers" \
"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'
wrap_up "$_InstFinBody" 'Reboot' 'Back' 'reboot'
else
local existing_files=""
for f in $(echo "${FILES[$MENU_HIGHLIGHT]}"); do
@ -559,11 +553,7 @@ edit_configs() {
done
if [[ $existing_files != "" ]]; then
if [[ $DISPLAY && $TERM != 'linux' ]] && hash geany >/dev/null 2>&1; then
geany -i $existing_files
else
vim -O $existing_files
fi
vim -O $existing_files
else
msgbox "$_ErrTitle" "$_NoFileErr"
fi
@ -606,15 +596,16 @@ main() {
esac
}
for file in utils mount boot lvm luks install; do
source_file $LIB/$file.sh
for file in /usr/share/archlabs/installer/lib/?*.sh; do
source_file $file
done
trap sigint INT # trap Ctrl-C and call sigint() to properly exit
# trap Ctrl-C to properly exit
trap sigint INT
for arg in "$@"; do
[[ $arg == "--debug" || $arg == "-d" ]] && debug
done
for arg in $@; do case $arg in
--debug|-d) debug ;;
esac done
init_variables
select_language