From ad8af90d436420962403288ee9e53231e84fbc02 Mon Sep 17 00:00:00 2001 From: natemaia Date: Sat, 20 Oct 2018 03:20:19 -0700 Subject: [PATCH] Update/overhaul mirror_cmd() function to not rely on reflector --- src/archlabs-installer | 104 ++++++++++++++++++++++------------------- src/lib/boot.sh | 30 ++++++------ src/lib/install.sh | 34 +++++++++----- src/lib/luks.sh | 8 ++-- src/lib/lvm.sh | 2 + src/lib/mount.sh | 30 ++++++------ src/lib/utils.sh | 14 ++++-- 7 files changed, 128 insertions(+), 94 deletions(-) diff --git a/src/archlabs-installer b/src/archlabs-installer index b7953c9..913ec54 100755 --- a/src/archlabs-installer +++ b/src/archlabs-installer @@ -12,7 +12,7 @@ # immutable variables { readonly DIST="ArchLabs" # Linux distributor -readonly VER="1.6.77" # Installer version +readonly VER="1.6.78" # Installer version readonly LIVE="liveuser" # Live session user readonly MNT="/mnt/install" # Install mountpoint readonly ERR="/tmp/errlog" # Built-in error log @@ -22,10 +22,9 @@ readonly RUN="/run/archiso/bootmnt/arch/boot" readonly SALT="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" 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 CONSOLE_MAPS="$(find /usr/share/kbd/keymaps -name '*.map.gz' | awk '{gsub(/\.map\.gz|.*\//, ""); print $1 " -"}')" +readonly SYS_MEM=$(grep 'MemTotal' /proc/meminfo | awk '{print int($2 / 1024)"M"}') readonly IGNORE_DEV="$(lsblk -lno NAME,MOUNTPOINT | awk '/\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')" if [[ $IGNORE_DEV ]]; then @@ -104,7 +103,7 @@ init_variables() { declare -g EXTRA_MNT="" declare -g EXTRA_MNTS="" declare -g SWAP="none" - declare -g SWAP_SIZE="${SYS_MEM}M" + declare -g SWAP_SIZE="$SYS_MEM" declare -g NEWUSER="" declare -g USER_PASS="" declare -g ROOT_PASS="" @@ -115,7 +114,6 @@ init_variables() { 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" declare -g IS_64BIT=false declare -g AUTOLOGIN=false @@ -142,13 +140,10 @@ init_variables() { } source_file() { - if ! . $1 2>/dev/null; then - echo -e "\nFailed to source library file $1"; die 1 - fi - return 0 + . $1 2>/dev/null || { printf "\nFailed to source library file %s" "$1"; die 1; } } -user_setup() { +user_creation() { tput cnorm local values values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \ @@ -204,7 +199,7 @@ user_setup() { user="" fi # recursively loop back unless the user cancels - user_setup || return 1 + user_creation || return 1 else NEWUSER="$user" USER_PASS="$pass" @@ -228,17 +223,17 @@ select_language() { FONT="ter-i16n" case $lang in - 1) LOC="en_US.UTF-8" ;; - 2) source_file $TRN/spanish.trans && LOC="es_ES.UTF-8" ;; - 3) source_file $TRN/p_brasil.trans && LOC="pt_BR.UTF-8" ;; - 4) source_file $TRN/portuguese.trans && LOC="pt_PT.UTF-8" ;; - 5) source_file $TRN/french.trans && LOC="fr_FR.UTF-8" ;; - 6) source_file $TRN/russian.trans && LOC="ru_RU.UTF-8" FONT="LatKaCyrHeb-16" ;; - 7) source_file $TRN/italian.trans && LOC="it_IT.UTF-8" ;; - 8) source_file $TRN/dutch.trans && LOC="nl_NL.UTF-8" ;; - 9) source_file $TRN/hungarian.trans && LOC="hu_HU.UTF-8" FONT="lat2-16" ;; - 10) source_file $TRN/chinese.trans && LOC="zh_CN.UTF-8" ;; - *) die 0 + 1) LOC="en_US.UTF-8" ;; + 2) source_file $TRN/spanish.trans && LOC="es_ES.UTF-8" ;; + 3) source_file $TRN/p_brasil.trans && LOC="pt_BR.UTF-8" ;; + 4) source_file $TRN/portuguese.trans && LOC="pt_PT.UTF-8" ;; + 5) source_file $TRN/french.trans && LOC="fr_FR.UTF-8" ;; + 6) source_file $TRN/russian.trans && LOC="ru_RU.UTF-8" FONT="LatKaCyrHeb-16" ;; + 7) source_file $TRN/italian.trans && LOC="it_IT.UTF-8" ;; + 8) source_file $TRN/dutch.trans && LOC="nl_NL.UTF-8" ;; + 9) source_file $TRN/hungarian.trans && LOC="hu_HU.UTF-8" FONT="lat2-16" ;; + 10) source_file $TRN/chinese.trans && LOC="zh_CN.UTF-8" ;; + *) die 0 esac sed -i "s/#en_US.UTF-8/en_US.UTF-8/" /etc/locale.gen @@ -447,40 +442,53 @@ extra_packages() { pkgs="$pkgs qt5ct qt5-styleplugins" fi - EXTRA_PACKAGES="$EXTRA_PACKAGES$([[ $pkgs ]] && echo -n " $pkgs")" + EXTRA_PACKAGES="$EXTRA_PACKAGES$([[ $pkgs ]] && printf " %s" "$pkgs")" return 0 } mirrorlist_cmd() { - MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate" - yesno "$_MirrorTitle" "$_MirrorSetup" "Automatic" "Custom" && return 0 + local key="5f29642060ab983b31fdf4c2935d8c56" + local ip="$(curl -s "http://api.ipstack.com/check&fields=ip&?access_key=${key}" | + val_from_json 'ip')" - infobox "$_MirrorTitle" "\nGathering mirror countries..\n" 0 - local countries - countries="$(reflector --list-countries | awk 'NF > 1 {print $1 " -"}')" + if hash reflector >/dev/null 2>&1; then + MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate" + yesno "$_MirrorTitle" "$_MirrorSetup" "Automatic" "Custom" && return 0 - if [[ $countries != "" ]]; then - tput civis - local country - country="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \ - --title " $_MirrorTitle " --menu "$_MirrorCountry" 22 70 10 $countries)" - MIRROR_CMD="reflector --country $country --score 80 --latest 40 --fastest 10 --sort rate" - fi + local c="$(curl -s "http://api.ipstack.com/${ip}?access_key=${key}&fields=country_name" | + val_from_json 'country_name')" + if [[ $c != "" ]]; then + MIRROR_CMD="reflector --country $c --score 80 --latest 40 --fastest 10 --sort rate" + fi - local ref=" --score n Limit the list to the n servers with the highest score. + tput cnorm + MIRROR_CMD="$(dialog --cr-wrap --no-cancel --stdout --backtitle "$BT" \ + --title " $_MirrorTitle " --inputbox "$_MirrorCmd\n + --score n Limit the list to the n servers with the highest score. --latest n Limit the list to the n most recently synchronized servers. --fastest n Return the n fastest mirrors that meet the other criteria. --sort {age,rate,country,score,delay} - 'age': Last server synchronization; - 'rate': Download rate; - 'country': Server location; - 'score': MirrorStatus score; - 'delay': MirrorStatus delay." + 'age': Last server synchronization; + 'rate': Download rate; + 'country': Server location; + 'score': MirrorStatus score; + 'delay': MirrorStatus delay.\n" 0 0 "$MIRROR_CMD")" + else + local c="$(curl -s "http://api.ipstack.com/${ip}?access_key=${key}&fields=country_code" | + val_from_json 'country_code')" - tput cnorm - MIRROR_CMD="$(dialog --cr-wrap --no-cancel --stdout --backtitle "$BT" \ - --title " $_MirrorTitle " --inputbox "$_MirrorCmd\n\n$ref\n" 0 0 "$cmd")" + local w="https://www.archlinux.org/mirrorlist" + if [[ $c != "" ]]; then + if [[ $c =~ (CA|US) ]]; then + MIRROR_CMD="curl -s '$w/?country=US&country=CA&protocol=https&use_mirror_status=on'" + else + MIRROR_CMD="curl -s '$w/?country=${c}&protocol=https&use_mirror_status=on'" + fi + else + MIRROR_CMD="curl -s '$w/?country=US&country=CA&country=NZ&country=GB&country=AU&protocol=https&use_mirror_status=on'" + fi + fi return 0 } @@ -531,11 +539,11 @@ configure_install() { setup_timezone || return 1 mirrorlist_cmd || return 1 - user_setup || return 1 + user_creation || return 1 window_manager || return 1 - local msg="\nUse the current Linux kernel or the LTS kernel?\n" - yesno 'Choose Kernel' "$msg" 'Current' 'LTS' && KERNEL='linux' || KERNEL='linux-lts' + yesno 'Choose Kernel' "\nUse the current kernel or the LTS kernel?\n" 'Current' 'LTS' && + KERNEL='linux' || KERNEL='linux-lts' extra_packages || return 1 CONFIG_DONE=true diff --git a/src/lib/boot.sh b/src/lib/boot.sh index 04eb7ed..1689fb5 100644 --- a/src/lib/boot.sh +++ b/src/lib/boot.sh @@ -6,6 +6,8 @@ # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised +# set -n + uefi_boot_fallback() { # some UEFI firmware requires a directory in the ESP and a generic bootx64.efi # see: https://wiki.archlinux.org/index.php/GRUB#UEFI @@ -53,21 +55,21 @@ prep_for_systemd-boot() { [[ $ROOT_PART =~ /dev/mapper ]] || ROOT_PART_ID="PART$ROOT_PART_ID" # create the boot entry configs - mkdir -p $MNT/boot/loader/entries - cat > $MNT/boot/loader/loader.conf << EOF + mkdir -p ${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/loader/entries + cat > ${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/loader/loader.conf << EOF default $DIST timeout 5 editor no EOF - cat > $MNT/boot/loader/entries/${DIST}.conf << EOF + cat > ${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/loader/entries/${DIST}.conf << EOF title $DIST Linux -linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && echo -en "\ninitrd /$UCODE") +linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE") initrd /initramfs-$KERNEL.img -options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && echo -n "$LUKS_DEV")rw +options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw EOF # add pacman hook to update the bootloader when systemd receives an update - mkdir -p $MNT/pacman.d/hooks - cat > $MNT/pacman.d/hooks/systemd-boot.hook << EOF + mkdir -p $MNT/etc/pacman.d/hooks + cat > $MNT/etc/pacman.d/hooks/systemd-boot.hook << EOF [Trigger] Type = Package Operation = Upgrade @@ -85,11 +87,11 @@ EOF prep_for_syslinux() { if [[ $SYS == 'UEFI' ]]; then - local cfgdir="$MNT/boot/EFI/syslinux" + local cfgdir="${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/EFI/syslinux" local cfgsrcdir="/usr/lib/syslinux/efi32/" [[ $IS_64BIT == true ]] && cfgsrcdir="/usr/lib/syslinux/efi64/" else - local cfgdir="$MNT/boot/syslinux" + local cfgdir="$MNT${BOOT_MNTS[$SYS-$BOOTLDR]}/syslinux" local cfgsrcdir="/usr/lib/syslinux/bios/" fi @@ -106,16 +108,16 @@ DEFAULT $DIST LABEL $DIST MENU LABEL $DIST Linux LINUX ../vmlinuz-$KERNEL -APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && echo -n "$LUKS_DEV ")rw +APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw INITRD ../initramfs-$KERNEL.img -$([[ $UCODE ]] && echo -en "\nINITRD ../$UCODE") +$([[ $UCODE ]] && printf "\nINITRD %s" "../$UCODE") LABEL ${DIST}fallback MENU LABEL $DIST Linux Fallback LINUX ../vmlinuz-$KERNEL -APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && echo -n "$LUKS_DEV ")rw +APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw INITRD ../initramfs-$KERNEL-fallback.img -$([[ $UCODE ]] && echo -en "\nINITRD ../$UCODE") +$([[ $UCODE ]] && printf "\nINITRD %s" "../$UCODE") EOF return 0 } @@ -123,7 +125,7 @@ EOF install_bootloader() { # not an LVM we can use the UUID for booting otherwise use the partition label if ! [[ $ROOT_PART =~ /dev/mapper ]]; then - ROOT_PART_ID="UUID=$(blkid -s PARTUUID $ROOT_PART | sed 's/.*=//g; s/"//g')" + ROOT_PART_ID="UUID=$(blkid -s PARTUUID -o value $ROOT_PART)" else ROOT_PART_ID="$ROOT_PART" fi diff --git a/src/lib/install.sh b/src/lib/install.sh index d8e6497..7439788 100644 --- a/src/lib/install.sh +++ b/src/lib/install.sh @@ -6,8 +6,13 @@ # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised +# set -n + install_main() { - clear && tput cnorm + # function calls prefixed with 'oneshot' will only ever be run once + # otherwise the main function can be called repeatedly + clear + tput cnorm # unpack the file system oneshot install_base @@ -18,8 +23,14 @@ install_main() { [[ -f $MNT/swapfile ]] && sed -i "s~${MNT}~~" $MNT/etc/fstab # update the mirrorlist.. MUST be done before updating or it may be slow - $MIRROR_CMD --verbose --save $MNT/etc/pacman.d/mirrorlist || - reflector --score 100 -l 50 -f 10 --sort rate --verbose --save $MNT/etc/pacman.d/mirrorlist + printf "%s\n\n" "Sorting the mirrorlist" + if hash reflector >/dev/null 2>&1; then + $MIRROR_CMD --save $MNT/etc/pacman.d/mirrorlist || + reflector --score 100 -l 50 -f 10 --sort rate --save $MNT/etc/pacman.d/mirrorlist + else + { eval $MIRROR_CMD || curl -s 'https://www.archlinux.org/mirrorlist/all/'; } | + sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 10 - >$MNT/etc/pacman.d/mirrorlist + fi # MUST be before bootloader and mkinitcpio oneshot package_operations @@ -27,24 +38,25 @@ install_main() { # set up user login oneshot login_manager - # MUST be done after installing the packages + # mkinitcpio and bootloader install should only be done after installing the packages + # and updating the mirrorlist, otherwise the chosen kernel may not be fully set up run_mkinitcpio install_bootloader + # hwclock setup, falls back to setting --directisa if the default fails chroot_cmd "hwclock --systohc --utc" || chroot_cmd "hwclock --systohc --utc --directisa" - oneshot create_user # create the user last to avoid referencing multiple $HOME locations + # create the user last to avoid referencing multiple $HOME locations for liveuser/newuser + oneshot create_user return 0 } install_base() { - echo -e "\nUnpacking base file system --- Total: ~ 2.8G\n\n" + printf "\nUnpacking base file system --- Total: ~ 2.8G\n\n" rsync -ah --info=progress2 /run/archiso/sfs/airootfs/ $MNT/ # remove archiso init files and clean up install files - rm -rf $MNT/etc/sudoers.d/g_wheel - rm -f $MNT/etc/mkinitcpio-archiso.conf - rm -f $MNT/etc/polkit-1/rules.d/49-nopasswd_global.rules + rm -rf $MNT/etc/{sudoers.d/g_wheel,mkinitcpio-archiso.conf,polkit-1/rules.d/49-nopasswd_global.rules} find $MNT/usr/lib/initcpio -name 'archiso*' -type f -exec rm '{}' \; # cleanup system permissions @@ -106,7 +118,7 @@ KEYMAP=$CONSOLE_MAP FONT=$FONT EOF # set the hostname - echo "$HOSTNAME" > $MNT/etc/hostname + printf "%s\n" "$HOSTNAME" > $MNT/etc/hostname cat > $MNT/etc/hosts << EOF 127.0.0.1 localhost 127.0.1.1 $HOSTNAME @@ -148,7 +160,7 @@ run_mkinitcpio() { # new hooks needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM (( LVM == 1 )) && add="lvm2" - (( LUKS == 1 )) && add="encrypt$([[ $add ]] && echo -n " $add")" + (( LUKS == 1 )) && add="encrypt$([[ $add ]] && printf " %s" "$add")" sed -i "s/block filesystems/block ${add} filesystems ${MKINIT_HOOKS}/g" $MNT/etc/mkinitcpio.conf chroot_cmd "mkinitcpio -p $KERNEL" 2>$ERR diff --git a/src/lib/luks.sh b/src/lib/luks.sh index 9d20f07..398ca2a 100644 --- a/src/lib/luks.sh +++ b/src/lib/luks.sh @@ -6,6 +6,8 @@ # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised +# set -n + declare -g LUKS=0 declare -g LUKS_DEV="" declare -g LUKS_PART="" @@ -150,9 +152,7 @@ luks_keycmd() { luks_show() { tput civis sleep 0.5 - echo -e "$_LuksEncryptSucc" > /tmp/.devlist - lsblk -o NAME,TYPE,FSTYPE,SIZE $LUKS_PART >> /tmp/.devlist - dialog --cr-wrap --backtitle "$BT" --title " $_LuksEncrypt " --textbox /tmp/.devlist 0 0 + msgbox "$_LuksEncrypt" "${_LuksEncryptSucc}\n$(lsblk $LUKS_PART -o NAME,MODEL,TYPE,FSTYPE,SIZE)" } luks_menu() { @@ -182,7 +182,7 @@ luks_keyfile() { if [[ ! -e $MNT/crypto_keyfile.bin ]]; then infobox "$_LuksKeyFileTitle" "$_LuksKeyFileCreate" 0 - echo -e "$_LuksKeyFileCreate" + printf "$_LuksKeyFileCreate" local n n="$(lsblk -lno NAME,UUID,TYPE | awk "/$LUKS_UUID/"' && /part|crypt|lvm/ {print $1}')" diff --git a/src/lib/lvm.sh b/src/lib/lvm.sh index 4f71b5c..33f14d6 100644 --- a/src/lib/lvm.sh +++ b/src/lib/lvm.sh @@ -6,6 +6,8 @@ # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised +# set -n + declare -g LVM=0 declare -g VOL_GROUP_MB=0 declare -g GROUP_PARTS=0 diff --git a/src/lib/mount.sh b/src/lib/mount.sh index 6ab6131..bdf3f45 100644 --- a/src/lib/mount.sh +++ b/src/lib/mount.sh @@ -6,6 +6,8 @@ # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised +# set -n + ######################################################## ## Partition functions ## ######################################################## @@ -232,7 +234,7 @@ select_device() { if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")" - msg="\nOnly one device available$([[ $1 == 'boot' ]] && echo -n " for grub bootloader"):" + msg="\nOnly one device available$([[ $1 == 'boot' ]] && printf " for grub bootloader"):" infobox "$_DevSelTitle" "$msg $DEVICE\n" 1 elif (( DEV_COUNT > 1 )); then tput civis @@ -240,8 +242,7 @@ select_device() { --menu "${msg}$_DevSelBody" 0 0 0 $SYS_DEVS)" [[ $? != 0 || $DEVICE == "" ]] && return 1 else - msg="\nNo available devices for installation to use$([[ $1 == 'boot' ]] && - echo -n " for grub bootloader")." + msg="\nNo available devices for installation to use$([[ $1 == 'boot' ]] && printf " for grub bootloader")." msgbox "$_ErrTitle" "$msg\n$_Exit" die 1 fi @@ -264,10 +265,11 @@ edit_partitions() { local choice choice="$(dialog --cr-wrap --stdout --backtitle "$BT" \ --title " $_PartTitle " --menu "$_PartBody" 0 0 0 "$_PartAuto" "-" \ - $( ([[ $DISPLAY ]] && hash gparted >/dev/null 2>&1) && echo -n "gparted -") "cfdisk" "-"\ - "parted" "-" "$_PartWipe" "-")" + $( ([[ $DISPLAY ]] && hash gparted >/dev/null 2>&1) && printf "gparted -") \ + "cfdisk" "-" "parted" "-" "$_PartWipe" "-")" [[ $? != 0 || $choice == "" ]] && return 1 - clear; tput cnorm + clear + tput cnorm if [[ $choice != "$_PartWipe" && $choice != "$_PartAuto" ]]; then $choice $device @@ -325,17 +327,17 @@ select_swap() { # Ask user to select partition or create swapfile tput civis SWAP="$(dialog --backtitle "$BT" --cr-wrap --stdout --title " $_SelSwpSetup " \ - --menu "$_SelSwpBody" 0 0 0 "$_SelSwpNone" "-" "$_SelSwpFile" "${SYS_MEM}M" $PARTS)" + --menu "$_SelSwpBody" 0 0 0 "$_SelSwpNone" "-" "$_SelSwpFile" "$SYS_MEM" $PARTS)" [[ $? != 0 || $SWAP == "$_SelSwpNone" ]] && return 0 if [[ $SWAP == "$_SelSwpFile" ]]; then tput cnorm - SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "${SYS_MEM}M")" + SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "$SYS_MEM")" [[ $? != 0 || $SWAP_SIZE == "" ]] && return 1 while ! [[ ${SWAP_SIZE:0:1} =~ [1-9] && ${SWAP_SIZE: -1} =~ (M|G) ]]; do msgbox "$_SelSwpSetup Error" "\n$_SelSwpErr $SWAP_SIZE\n" - SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "${SYS_MEM}M")" + SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "$SYS_MEM")" [[ $? != 0 || $SWAP_SIZE == "" ]] && { break; return 1; } done @@ -415,8 +417,8 @@ select_filesystem() { local fs fs="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_FSTitle: $part " \ --menu "\nPartition: ${part}$([[ $cur_fs != "" ]] && - echo -en "\nCurrent: ${cur_fs}")\n$_FSBody" 0 0 0 \ - $([[ $cur_fs != "" ]] && echo -n "$_Skip -") \ + printf "\nCurrent: %s" "$cur_fs")\n$_FSBody" 0 0 0 \ + $([[ $cur_fs != "" ]] && printf "%s -" "$_Skip") \ "ext4" "${FS_CMDS[ext4]}" "ext3" "${FS_CMDS[ext3]}" \ "ext2" "${FS_CMDS[ext2]}" "vfat" "${FS_CMDS[vfat]}" \ "ntfs" "${FS_CMDS[ntfs]}" "f2fs" "${FS_CMDS[f2fs]}" \ @@ -481,7 +483,9 @@ select_root_partition() { decr_count "$LUKS_PART" elif (( LVM == 1 )); then (( LUKS == 1 )) && decr_count "$LUKS_PART" - for part in $(echo "$GROUP_PARTS"); do decr_count "$part"; done + for part in $(echo "$GROUP_PARTS"); do + decr_count "$part" + done ROOT_PART="" fi @@ -494,7 +498,7 @@ select_root_partition() { --title " $_PrepMount " --menu "$_SelRootBody" 0 0 0 $PARTS)" [[ $? != 0 || $ROOT_PART == "" ]] && return 1 else - local msg="\nUsing $([[ $LUKS -eq 1 ]] && echo -n "encrypted ")root partition:" + local msg="\nUsing $([[ $LUKS -eq 1 ]] && printf "encrypted ")root partition:" infobox "$_PrepMount" "$msg $ROOT_PART\n" 1 fi diff --git a/src/lib/utils.sh b/src/lib/utils.sh index 0733456..33993d1 100644 --- a/src/lib/utils.sh +++ b/src/lib/utils.sh @@ -6,10 +6,16 @@ # this file is not meant to be run directly # sourcing this file in a non bash shell is not advised +# set -n + chroot_cmd() { arch-chroot $MNT /bin/bash -c "$1" } +val_from_json() { + python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])" +} + identify_system() { if grep -qi 'apple' /sys/class/dmi/id/sys_vendor; then modprobe -r -q efivars @@ -53,9 +59,9 @@ check_for_errors() { err="$(sed 's/[^[:print:]]//g; s/\[[0-9\;:]*\?m//g; s/==> //g; s/] ERROR:/]\nERROR:/g' "$ERR")" [[ $err != "" ]] && msgbox "$_ErrTitle" "$msg\n\nWith the following error message:\n\n$err" - msg="$([[ $err == "" ]] && echo -n "$msg")\n$_ErrChoice" + msg="$([[ $err == "" ]] && printf "%s" "$msg")\n$_ErrChoice" if [[ -e /tmp/debug-log && $TERM == 'linux' ]]; then - msg="$([[ $err == "" ]] && echo -n "$msg")\n$_ErrChoiceConsole" + msg="$([[ $err == "" ]] && printf "%s" "$msg")\n$_ErrChoiceConsole" yesno "$_ErrTitle" "$msg" "Exit & Open Log" "Ignore & Continue" && { less /tmp/debug-log; die 0; } else yesno "$_ErrTitle" "$msg" "Exit & Shutdown" "Ignore & Continue" && die 'shutdown -h now' @@ -89,7 +95,7 @@ getinput() { answer="$(dialog --cr-wrap --max-input 63 --stdout --no-cancel \ --backtitle "$BT" --title " $1 " --inputbox "$2" 0 0 "$3")" [[ $? != 0 || $answer == "" ]] && return 1 - echo "$answer" + printf "$answer" } msgbox() { @@ -133,7 +139,7 @@ die() { } sigint() { - echo -e "\n** CTRL-C caught" + printf "\n** CTRL-C caught" die 1 }