Add menu function to simplify things

This commit is contained in:
natemaia 2018-11-11 00:17:42 -08:00
parent b122c92e2e
commit fdd77684a0
7 changed files with 62 additions and 71 deletions

View File

@ -9,12 +9,12 @@
# set -n
# shellcheck disable=2154,2034
# shellcheck disable=2154,2034,2153
# globals {
# immutable values
readonly VER="1.7.15" # Installer version
readonly VER="1.7.17" # Installer version
readonly DIST="ArchLabs" # Linux distributor
readonly MNT="/mnt/install" # Install mountpoint
readonly ERR="/tmp/errlog" # Built-in error log
@ -53,8 +53,8 @@ declare -g MKINIT_HOOKS="shutdown"
select_language() {
tput civis
local lang
lang=$(dialog --cr-wrap --stdout --backtitle "$BT" --title " Select Language " --menu \
"\nLanguage - sprache - taal - språk - lingua - idioma - nyelv - língua\n" 0 0 0 \
local title="\nLanguage - sprache - taal - språk - lingua - idioma - nyelv - língua\n"
lang=$(menubox "Select Language" "$title" 0 0 0 \
"1" "English (en_**)" "2" "Español (es_ES)" \
"3" "Português [Brasil] (pt_BR)" "4" "Português (pt_PT)" \
"5" "Français (fr_FR)" "6" "Russkiy (ru_RU)" \
@ -62,7 +62,6 @@ select_language() {
"9" "Magyar (hu_HU)" "10" "Chinese (zh_CN)")
local srcdir="/usr/share/archlabs/installer/lang"
src $srcdir/english.trans
FONT="ter-i16n"
@ -81,7 +80,6 @@ select_language() {
esac
sed -i "s/#en_US.UTF-8/en_US.UTF-8/" /etc/locale.gen
if [[ $LOC != "en_US.UTF-8" ]]; then
sed -i "s/#${LOC}/${LOC}/" /etc/locale.gen
locale-gen >/dev/null 2>&1
@ -159,8 +157,7 @@ user="$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$values" |
select_keymap() {
tput civis
if ! KEYMAP="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepLayout " --menu "$_XMapBody" 20 70 12 \
if ! KEYMAP="$(menubox "$_PrepLayout" "$_XMapBody" 20 70 12 \
'us' 'English' 'cm' 'English' 'gb' 'English' 'au' 'English' 'gh' 'English' \
'za' 'English' 'ng' 'English' 'ca' 'French' 'cd' 'French' 'gn' 'French' \
'tg' 'French' 'fr' 'French' 'de' 'German' 'at' 'German' 'ch' 'German' \
@ -185,11 +182,10 @@ select_keymap() {
fi
# when a matching console map is not available open a selection dialog
# shellcheck disable=SC2153
if [[ $CMAPS == *"$KEYMAP"* ]]; then
CMAP="$KEYMAP"
else
if ! CMAP="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_CMapTitle " --menu "$_CMapBody" 20 70 12 $CMAPS)"; then
if ! CMAP="$(menubox "$_CMapTitle" "$_CMapBody" 20 70 12 $CMAPS)"; then
return 1
fi
fi
@ -211,15 +207,13 @@ select_timezone() {
done
tput civis
if ! ZONE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_TimeZTitle " --menu "$_TimeZBody" 20 70 10 \
if ! ZONE="$(menubox "$_TimeZTitle" "$_TimeZBody" 20 70 10 \
'America' '-' 'Australia' '-' 'Asia' '-' 'Atlantic' '-' 'Africa' '-' \
'Europe' '-' 'Indian' '-' 'Pacific' '-' 'Arctic' '-' 'Antarctica' '-')"; then
return 1
fi
if ! SUBZONE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_TimeZTitle " --menu "$_TimeSubZBody" 20 70 12 ${SUBZONES[$ZONE]})"; then
if ! SUBZONE="$(menubox "$_TimeZTitle" "$_TimeSubZBody" 20 70 12 ${SUBZONES[$ZONE]})"; then
return 1
fi
@ -272,8 +266,7 @@ select_wm_or_de() {
if [[ $WM_NUM -eq 1 ]]; then
LOGIN_WM="$INSTALL_WMS"
else
if ! LOGIN_WM="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
--title " $_WMLogin " --menu "$_WMLoginBody" 0 0 0 $LOGIN_CHOICES)"; then
if ! LOGIN_WM="$(menubox "$_WMLogin" "$_WMLoginBody" 0 0 0 $LOGIN_CHOICES)"; then
return 1
fi
fi
@ -298,8 +291,7 @@ select_wm_or_de() {
}
select_login_method() {
if ! LOGIN_TYPE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_WMLogin " --menu "$_LoginTypeBody" 0 0 0 \
if ! LOGIN_TYPE="$(menubox "$_WMLogin" "$_LoginTypeBody" 0 0 0 \
"xinit" "Console login without a display manager" \
"lightdm" "Lightweight display manager with a gtk greeter")"; then
return 1
@ -505,24 +497,21 @@ configure_system_settings() {
fi
tput civis
# shellcheck disable=SC2153
if ! LOCALE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_ConfLocale " --menu "$_LocaleBody" 25 70 20 $LOCALES)"; then
if ! LOCALE="$(menubox "$_ConfLocale" "$_LocaleBody" 25 70 20 $LOCALES)"; then
return 1
fi
select_timezone || return 1
user_creation || return 1
if ! MYSHELL="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_ShellTitle " --menu "$_ShellBody" 0 0 0 '/bin/zsh' '-' '/bin/bash' '-')"; then
tput civis
if ! MYSHELL="$(menubox "$_ShellTitle" "$_ShellBody" 0 0 0 '/bin/zsh' '-' '/bin/bash' '-')"; then
return 1
fi
tput civis
if [[ $HAS_NETWORK == true ]]; then
if ! KERNEL="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_KernelTitle " --menu "$_KernelBody" 0 0 0 'linux' '-' 'linux-lts' '-')"; then
if ! KERNEL="$(menubox "$_KernelTitle" "$_KernelBody" 0 0 0 'linux' '-' 'linux-lts' '-')"; then
return 1
fi
@ -606,8 +595,8 @@ main() {
# 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 [[ $SELECTED ]]; then
if [[ $SELECTED -eq 8 ]]; then
icheck || return 1
if [[ $SELECTED -eq 8 || $SELECTED -eq 6 ]]; then
{ [[ $SELECTED -eq 8 ]] && icheck 1 || icheck; } || return 1
elif [[ ($SELECTED -eq 2 || $SELECTED -eq 5) && $WARN != true ]]; then
msgbox "$_PrepTitle" "$_WarnMount" && WARN=true
fi

View File

@ -194,7 +194,7 @@ EOF
fi
# automatic startx for login shells
[[ $MYSHELL == '/bin/bash' ]] && local loginrc=".bash_profile" || local loginrc=".zprofile"
[[ $MYSHELL == '/bin/bash' ]] && local loginrc=".profile" || local loginrc=".zprofile"
EDIT_FILES[11]+="/home/$NEWUSER/$loginrc"
cat >> $MNT/home/$NEWUSER/$loginrc << EOF
@ -202,7 +202,7 @@ EOF
# sourced by $(basename $MYSHELL) when used as a login shell
# automatically run startx when logging in on tty1
if [ -n "\$DISPLAY" ] && [ \$XDG_VTNR -eq 1 ]; then
if [ -z "\$DISPLAY" ] && [ \$XDG_VTNR -eq 1 ]; then
exec startx -- vt1 >/dev/null 2>&1
fi
EOF

View File

@ -19,7 +19,7 @@ declare -g LUKS_NAME="cryptroot"
luks_open() {
LUKS_PART=""
modprobe -a dm-mod dm_crypt
unmount_install_partitions
umount_dir $MNT
find_partitions 'part|crypt|lvm' || return 1
tput civis
@ -28,7 +28,7 @@ luks_open() {
infobox "$_LuksOpen" "${_OnlyOne}: $LUKS_PART\n" 1
else
tput civis
if ! LUKS_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_LuksOpen " --menu "$_LuksMenuBody" 0 0 0 $PARTS)"; then
if ! LUKS_PART="$(menubox "$_LuksOpen" "$_LuksMenuBody" 0 0 0 $PARTS)"; then
return 1
fi
fi
@ -90,7 +90,7 @@ luks_pass() {
luks_setup() {
LUKS_PART=""
modprobe -a dm-mod dm_crypt
unmount_install_partitions
umount_dir $MNT
if [[ ! $ROOT_PART || $LVM ]]; then
find_partitions 'part|lvm' || return 1
@ -101,7 +101,7 @@ luks_setup() {
infobox "$_LuksEncrypt" "${_OnlyOne}: $LUKS_PART\n" 1
else
tput civis
if ! LUKS_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_LuksEncrypt " --menu "$_LuksEncryptBody" 0 0 0 $PARTS)"; then
if ! LUKS_PART="$(menubox "$_LuksEncrypt" "$_LuksEncryptBody" 0 0 0 $PARTS)"; then
return 1
fi
fi
@ -161,8 +161,7 @@ luks_show() {
luks_menu() {
tput civis
local choice
choice="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PrepLUKS " \
--menu "${_LuksMenuBody}${_LuksMenuBody2}${_LuksMenuBody3}" 0 0 0 \
choice="$(menubox "$_PrepLUKS" "${_LuksMenuBody}${_LuksMenuBody2}${_LuksMenuBody3}" 0 0 0 \
"$_LuksEncrypt" "cryptsetup -q luksFormat" \
"$_LuksOpen" "cryptsetup open --type luks" \
"$_LuksEncryptAdv" "cryptsetup -q -s -c luksFormat" \

View File

@ -43,7 +43,7 @@ lvm_show_vg() {
fi
tput civis
if ! DEL_VG="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PrepLVM " --menu "$_LvmSelVGBody" 18 70 10 $VOL_GROUP_LIST)"; then
if ! DEL_VG="$(menubox "$_PrepLVM" "$_LvmSelVGBody" 18 70 10 $VOL_GROUP_LIST)"; then
return 1
fi
return 0
@ -208,7 +208,7 @@ lvm_create() {
VOLUME_GROUP=""
GROUP_PARTS=""
VOL_GROUP_MB=0
unmount_install_partitions
umount_dir $MNT
if [[ $LUKS && $LUKS_NAME ]]; then
GROUP_PARTS="/dev/mapper/$LUKS_NAME"
@ -264,8 +264,7 @@ lvm_menu() {
tput civis
local choice
choice="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepLVM " --menu "$_LvmMenu" 0 0 0 \
choice="$(menubox "$_PrepLVM" "$_LvmMenu" 0 0 0 \
"$_LvmCreateVG" "vgcreate -f, lvcreate -L -n" \
"$_LvmDelVG" "vgremove -f" \
"$_LvMDelAll" "lvrmeove, vgremove, pvremove -f" \

View File

@ -17,7 +17,7 @@ readonly CMAPS="$(find /usr/share/kbd/keymaps -name '*.map.gz' | awk '{gsub(/\.m
mount_install_partitions() {
# prepare partition list PARTS for dialog
lvm_detect
unmount_install_partitions
umount_dir $MNT
find_partitions 'part|lvm|crypt' || return 1
# remove boot partition from dialog list if we auto partitioned one
@ -43,8 +43,8 @@ mount_install_partitions() {
select_swap() {
# Ask user to select partition or create swapfile
tput civis
if ! SWAP_PART="$(dialog --backtitle "$BT" --cr-wrap --stdout --title " $_SelSwpSetup " \
--menu "$_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
@ -88,8 +88,7 @@ select_mountpoint() {
select_boot_setup() {
# choose bootloader and mountpoint (if needed)
tput civis
if ! BOOTLDR="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepMount " --menu "$_MntBootBody" 0 0 0 ${BOOTLDRS[$SYS]})"; then
if ! BOOTLDR="$(menubox "$_PrepMount" "$_MntBootBody" 0 0 0 ${BOOTLDRS[$SYS]})"; then
return 1
fi
@ -103,8 +102,7 @@ select_boot_setup() {
elif [[ $BOOTLDR == 'syslinux' ]]; then
if [[ $SYS == 'BIOS' ]]; then
FILES[9]="/boot/syslinux/syslinux.cfg"
if ! BCMDS[$BOOTLDR]="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_InstSysTitle " --menu "$_InstSysBody" 0 0 0 \
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
@ -157,14 +155,13 @@ select_mount_opts() {
select_filesystem() {
local part="$1"
local cur_fs str
local fs cur_fs str title
cur_fs="$(lsblk -lno FSTYPE $part)"
str="$([[ $cur_fs && $part != "$ROOT_PART" ]] && printf "\nExisting Filesystem: %s" "$cur_fs")"
tput civis
local fs
fs="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_FSTitle: $part " \
--menu "\nSelect which filesystem you want to use for $part\n\nPartition Name: ${part}${str}$_FSBody" 0 0 0 \
title="\nSelect which filesystem you want to use for $part\n\nPartition Name: "
fs="$(menubox "$_FSTitle: $part" "${title}${part}${str}$_FSBody" 0 0 0 \
$([[ $cur_fs && $part != "$ROOT_PART" ]] && printf "%s" "$_Skip -") \
"ext4" "${FS_CMDS[ext4]}" "ext3" "${FS_CMDS[ext3]}" \
"ext2" "${FS_CMDS[ext2]}" "vfat" "${FS_CMDS[vfat]}" \
@ -187,8 +184,7 @@ select_efi_partition() {
BOOT_PART="$(awk 'NF > 0 {print $1}' <<< "$PARTS")"
infobox "$_PrepMount" "$_OnlyOne for EFI: $BOOT_PART\n" 1
else
if ! BOOT_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepMount " --menu "$_SelUefiBody" 0 0 0 $PARTS)"; then
if ! BOOT_PART="$(menubox "$_PrepMount" "$_SelUefiBody" 0 0 0 $PARTS)"; then
return 1
fi
fi
@ -205,14 +201,12 @@ select_efi_partition() {
select_boot_partition() {
tput civis
if ! BOOT_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PrepMount " \
--menu "$_SelBiosBody" 0 0 0 "$_Skip" "-" $PARTS)" || [[ $BOOT_PART == "$_Skip" ]]; then
if ! BOOT_PART="$(menubox "$_PrepMount" "$_SelBiosBody" 0 0 0 "$_Skip" "-" $PARTS)" || [[ $BOOT_PART == "$_Skip" ]]; then
BOOT_PART=""
else
if grep -q 'ext[34]' <<< "$(fsck -N "$BOOT_PART")"; then
local msg="$_FormBiosBody $BOOT_PART $_FormUefiBody2"
yesno "$_PrepMount" "$msg" "Format $BOOT_PART" "Skip Formatting" "no" &&
format "$BOOT_PART" "ext4"
yesno "$_PrepMount" "$msg" "Format $BOOT_PART" "Skip Formatting" "no" && format "$BOOT_PART" "ext4"
else
format "$BOOT_PART" "ext4"
fi
@ -236,8 +230,7 @@ select_root_partition() {
infobox "$_PrepMount" "$_OnlyOne for root (/): $ROOT_PART\n" 1
elif [[ ! $ROOT_PART || $LVM ]]; then
tput civis
if ! ROOT_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" \
--title " $_PrepMount " --menu "$_SelRootBody" 0 0 0 $PARTS)"; then
if ! ROOT_PART="$(menubox "$_PrepMount" "$_SelRootBody" 0 0 0 $PARTS)"; then
return 1
fi
else
@ -254,8 +247,7 @@ select_extra_partitions() {
while (( COUNT > 0 )); do
tput civis
local part
if ! part="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PrepMount " \
--menu "$_ExtPartBody" 0 0 0 "$_Done" "-" $PARTS)" || [[ $part == "$_Done" ]]; then
if ! part="$(menubox "$_PrepMount " "$_ExtPartBody" 0 0 0 "$_Done" "-" $PARTS)" || [[ $part == "$_Done" ]]; then
break
fi

View File

@ -41,8 +41,7 @@ partition() {
tput civis
local choice
if ! choice="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PartTitle " \
--menu "$_PartBody" 0 0 0 "$_PartShowTree" "-" "$_PartAuto" "-" \
if ! choice="$(menubox "$_PartTitle" "$_PartBody" 0 0 0 "$_PartShowTree" "-" "$_PartAuto" "-" \
$({ [[ $DISPLAY ]] && hash gparted >/dev/null 2>&1; } && printf "gparted -") \
"cfdisk" "-" "parted" "-" "$_PartWipe" "-")"; then
return 1
@ -103,7 +102,7 @@ device_tree() {
select_device() {
local dev
local msg
[[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || unmount_install_partitions
[[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || umount_dir $MNT
if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then
DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")"
@ -111,8 +110,7 @@ select_device() {
infobox "$_DevSelTitle" "$msg $DEVICE\n" 1
elif (( DEV_COUNT > 1 )); then
tput civis
if ! DEVICE="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_DevSelTitle " \
--menu "${msg}$_DevSelBody" 0 0 0 $SYS_DEVS)"; then
if ! DEVICE="$(menubox "$_DevSelTitle " "${msg}$_DevSelBody" 0 0 0 $SYS_DEVS)"; then
return 1
fi
elif [[ $DEV_COUNT -lt 1 && $1 != 'boot' ]]; then

View File

@ -34,7 +34,7 @@ die() {
tput cnorm
if [[ -d $MNT ]] && cd; then
fuser -km $MNT
unmount_install_partitions
umount_dir $MNT
if [[ $exitcode -eq 127 ]]; then
fuser -km /run/archiso/bootmnt
@ -55,6 +55,19 @@ msgbox() {
dialog --cr-wrap --backtitle "$BT" --title " $1 " --msgbox "$2\n" 0 0
}
menubox() {
local title="$1"
local body="$2"
local h=$3
local w=$4
local n=$5
shift 5
if ! response="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $title " --menu "$body" $h $w $n "$@")"; then
return 1
fi
printf "%s\n" "$response"
}
oneshot() {
[[ -e /tmp/.ai_$1 || ! $(type $1) ]] && return 0
$1 || return 1
@ -64,8 +77,7 @@ oneshot() {
getinput() {
local answer
if ! answer="$(dialog --cr-wrap --max-input 63 --stdout --no-cancel \
--backtitle "$BT" --title " $1 " --inputbox "$2" 0 0 "$3")" || [[ $answer == '' ]]; then
if ! answer="$(dialog --cr-wrap --max-input 63 --stdout --no-cancel --backtitle "$BT" --title " $1 " --inputbox "$2" 0 0 "$3")" || [[ $answer == '' ]]; then
return 1
fi
printf "%s" "$answer"
@ -188,7 +200,9 @@ echeck() {
icheck() {
[[ $(lsblk -o MOUNTPOINT) =~ $MNT ]] || { msgbox "$_ErrTitle" "$_ErrNoMount"; export SELECTED=4; return 1; }
[[ $CONFIG_DONE == true ]] || { msgbox "$_ErrTitle" "$_ErrNoConfig"; export SELECTED=5; return 1; }
if [[ $# -eq 1 ]]; then
[[ $CONFIG_DONE == true ]] || { msgbox "$_ErrTitle" "$_ErrNoConfig"; export SELECTED=5; return 1; }
fi
return 0
}
@ -221,8 +235,8 @@ debug() {
export DEBUG=true
}
unmount_install_partitions() {
umount_dir() {
swapoff -a
[[ -d $MNT ]] && umount -R $MNT >/dev/null 2>&1
[[ -d $1 ]] && umount -R $1 >/dev/null 2>&1
return 0
}