From 89c95254eda4308383d8010f7742fe5f2296878c Mon Sep 17 00:00:00 2001 From: natemaia Date: Thu, 25 Oct 2018 20:31:30 -0700 Subject: [PATCH] More cleanup and fixes, rename a large amount of functions for brevity --- README.md | 35 +++--- lang/english.trans | 16 +-- src/archlabs-installer | 243 +++++++++++++++++++++-------------------- src/lib/boot.sh | 14 +-- src/lib/install.sh | 75 +++++++------ src/lib/luks.sh | 28 ++--- src/lib/lvm.sh | 16 +-- src/lib/mount.sh | 68 +++++++----- src/lib/utils.sh | 40 ++++--- 9 files changed, 283 insertions(+), 252 deletions(-) diff --git a/README.md b/README.md index c0a8fd8..d435904 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,25 @@ # ArchLabs Installer #### Features -+ Support for LUKS and/or LVM. -+ Simple & easy to follow configuration. -+ Automatic partitioning for whole devices. -+ Translations for 10 different languages. -+ Built-in error detection and capturing. -+ No input halts during install, setup is done first. -+ Written entirely in Bash making it easily hackable. +- Simple, easy to follow configuration. +- Automatic partitioning for whole devices. +- Translations for different languages. +- No input halts during install. +- Support for LUKS and/or LVM. +- Built-in error detection. +- Written entirely in Bash #### Requirements -+ `rsync` used to unpack the squashfs root. -+ `dialog` for all user input/output. -+ `vim` for editing files post install. -+ `parted` for auto and manual partition creation. -+ `wipe` for the secure wipe option. -+ Standard `awk` `sed` `grep` `uniq` `sort` `find` `ping` `mkfs` `lsblk`. -+ `arch-chroot` used to perform operations in the chroot. -+ `chpasswd` to set root and user passwords. -+ Network connection is needed to install packages and update the system. -+ `pacman` used to update the system and install/remove packages. *(with network connection)* -+ `reflector` for sorting the mirrorlist. *(with network connection)* +- `rsync` for unpacking the squashfs. +- `dialog` for all user input/output. +- `vim` for editing files post install. +- `parted` for partition creation. +- `wipe` for the secure wipe. +- `awk` `sed` `grep` `uniq` `sort` `find` `ping` `mkfs` `lsblk` `curl`. +- `arch-chroot` to perform operations in a chroot. +- `chpasswd` to set root and user passwords. +- `openssl` to encrypt passwords. +- Network connection is needed to install packages and update the system. #### Manual Installation - curl diff --git a/lang/english.trans b/lang/english.trans index 399da56..bf0557f 100644 --- a/lang/english.trans +++ b/lang/english.trans @@ -16,7 +16,7 @@ _Name="Name:" # Welcome _WelTitle="Welcome to" -_WelBody="This will unpack and setup $DIST on your system\n\nMenu Navigation:\n\nSelect items by pressing the option number or using the arrow keys.\n\nSwitch between buttons using [Tab] or the arrow keys.\n\nLong lists can be navigated using [Page Up] and [Page Down], or by pressing the first letter of the desired option.\n\nUse [Space] to (de)select options and [Enter] to confirm.\n" +_WelBody="This will unpack and help you setup $DIST on your system\n\nMenu Navigation:\n\n - Select items by pressing the option number or using the arrow keys.\n\n - Use [Space] to (de)select options and [Enter] to confirm.\n\n - Switch between buttons using [Tab] or the arrow keys.\n\n - Long lists can be navigated using [Page Up] and [Page Down], or by pressing the highlighted letter of the desired option.\n" # Requirements _NotRoot="\nThe installer must be run as root or using sudo.\n" @@ -25,7 +25,7 @@ _NoNetwork="\nThe installer should be run with an active network connection.\n" # Preparation Menu _PrepTitle="Prepare System" -_PrepBody="\nFollow the below steps in order.\n\nTo begin install there must be a root partition mounted first, UEFI requires\na seperate boot partition, once mounted configure the system settings before beginning the install." +_PrepBody="\nFollow the below steps in order.\n\nBefore beginning the install, a root (/) partition must be mounted (UEFI also requires a boot partition) and the system settings must be configured." _PrepLayout="Keyboard Layout" _PrepShowDev="Device Tree" _PrepParts="Edit Partitions" @@ -59,7 +59,7 @@ _TimeSubZBody="\nSelect the nearest city to your location from the list below." _TimeZQ="\nSet time zone as:" # bootloader -_MntBootBody="\nSelect bootloader and boot partition mountpoint.\n\nGrub is recommended, especially for multiboot." +_MntBootBody="\nSelect bootloader and boot partition mountpoint (if any)." _InstSysTitle="Install Syslinux" _InstSysBody="\nInstall syslinux to the master boot record (MBR) or to root (/)?" @@ -111,7 +111,7 @@ _DevSelTitle="Select Device" _DevSelBody="\nSelect a device from the list below.\n\nDevices (/dev) are the available drives on the system. /sda, /sdb ..." # Extra Partitions -_ExtPartBody="\nSelect any additional partitions you want to mount, otherwise select '$_Done' to finish the mounting step.\n\nAfter choosing a partition you will be asked to enter the mountpoint." +_ExtPartBody="\nYou can now select additional partitions you want mounted, once choosed you will be asked to enter where you want it mounted.\n\nSelect '$_Done' to finish the mounting step and return to the main menu." _ExtPartBody1="\nWhere do you want the partition mounted?\n\nEnsure the name begins with a forward slash (/).\nSome examples include:" # Auto partition @@ -133,22 +133,22 @@ _InstSysBody="\nInstall syslinux to the Master Boot Record (MBR) or to root (/)? # File System _FSTitle="Choose Filesystem" -_FSBody="\nRecommended: ext4\n\nNOTE: Some aren't usable for root (/) or boot (/boot) partitions." +_FSBody="\nDefault Filesystem: ext4\n\nNOTE: Not all filesystems are usable for root (/) or boot (/boot) partitions." _SelRootBody="\nSelect root (/) partition.\n\nThis is the partition where $DIST will be installed." _SelBiosBody="\nDo you want to use a seperate boot partition? (required for LUKS)\n\nThis partition is where the bootloader will be installed.\n" _SelSwpFile="Swapfile" _SelSwpSetup="Swap Setup" -_SelSwpBody="\nSelect SWAP partition/file, or none. If using a swapfile, it will be initially set the same size as your RAM." +_SelSwpBody="\nSelect whether to use a swap partition, swapfile, or none.\n\nWhen selecting swapfile the size will be filled in to the size of your system memory, however this can be changed to suit your needs." _SelSwpNone="None" _SelSwpErr="Swap Setup Error: Must be 1(M|G) or greater, and can only contain whole numbers\n\nSize Entered:" _SelSwpSize="\nEnter the size to use for swap.\n\nMust be greater than 1, end in either M or G, and contain only whole numbers." -_SelUefiBody="\nSelect the system EFI boot partition.\n\nThis is a special partition used for booting newer UEFI systems. Usually the first partition on the drive, less than 512M, and formatted as vfat/fat32." +_SelUefiBody="\nSelect the system EFI boot partition.\n\nThis is a special partition used for booting modern UEFI systems. It's usually the first partition on the drive, less than 512M, and formatted as vfat/fat32." _FormUefiBody="IMPORTANT:\n\nThe EFI partition" _FormBiosBody="IMPORTANT:\n\nThe boot partition" -_FormUefiBody2="is already correctly formatted.\n\nDo you want to reformat it?\n" +_FormUefiBody2="is already correctly formatted.\n\nFor a clean install, previously existing partitions should be formatted, however this removes ALL data/bootloaders on the partition so choose carefully.\n\nDo you want to reformat the partition?\n" # LUKS / DM-Crypt / Encryption _LuksMenuBody="\nDevices and volumes encrypted using dm_crypt cannot be accessed or seen without being first unlocked." diff --git a/src/archlabs-installer b/src/archlabs-installer index 58c6e53..07ca786 100755 --- a/src/archlabs-installer +++ b/src/archlabs-installer @@ -1,18 +1,18 @@ #!/usr/bin/bash -# vim:ft=sh:fdm=marker:fmr={,} +# vim: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 +# Some ideas and code has been taken from other installers # AIF, Cnichi, Calamares, The Arch Wiki.. Credit where credit is due # set -n -# immutable variables { +# immutable { readonly DIST="ArchLabs" # Linux distributor -readonly VER="1.6.88" # Installer version +readonly VER="1.6.94" # Installer version readonly LIVE="liveuser" # Live session user readonly MNT="/mnt/install" # Install mountpoint readonly ERR="/tmp/errlog" # Built-in error log @@ -26,14 +26,6 @@ readonly SYS_MEM=$(grep 'MemTotal' /proc/meminfo | awk '{print int($2 / 1024)"M" readonly LOCALES="$(awk '/\.UTF-8/ {gsub(/# .*|#/, ""); if($1) print $1 " -"}' /etc/locale.gen)" readonly CONSOLE_MAPS="$(find /usr/share/kbd/keymaps -name '*.map.gz' | awk '{gsub(/\.map\.gz|.*\//, ""); print $1 " -"}')" -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 - readonly SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ {print "/dev/" $1 " " $2}')" -fi -readonly DEV_COUNT="$(wc -l <<< "$SYS_DEVS")" - if grep -q 'GenuineIntel' /proc/cpuinfo; then readonly UCODE="intel-ucode.img" elif grep -q 'AuthenticAMD' /proc/cpuinfo; then @@ -54,25 +46,26 @@ if [[ $DISPLAY && $TERM != 'linux' ]]; then fi # static string of keymap codes and respective language -readonly KEYMAPS="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 -es Spanish latam Spanish br Portuguese pt Portuguese ma Arabic sy Arabic ara Arabic -ua Ukrainian cz Czech ru Russian sk Slovak nl Dutch it Italian hu Hungarian cn Chinese -tw Taiwanese vn Vietnamese kr Korean jp Japanese th Thai la Lao pl Polish se Swedish -is Icelandic fi Finnish dk Danish be Belgian in Indian al Albanian am Armenian bd Bangla -ba Bosnian bg Bulgarian dz Berber mm Burmese hr Croatian gr Greek il Hebrew ir Persian iq Iraqi -af Afghani fo Faroese ge Georgian ee Estonian kg Kyrgyz kz Kazakh lt Lithuanian mt Maltese -mn Mongolian no Norwegian ro Romanian rs Serbian si Slovenian tj Tajik lk Sinhala tr Turkish -uz Uzbek ie Irish pk Urdu mv Dhivehi epo Esperanto np Nepali et Amharic sn Wolof ml Bambara -tz Swahili ke Swahili bw Tswana ph Filipino id Indonesian my Malay tm Turkmen bt Dzongkha -lv Latvian md Moldavian mao Maori by Belarusian me Montenegrin mk Macedonian kh Khmer az Azerbaijani" +readonly KEYMAPS="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 es Spanish +latam Spanish br Portuguese pt Portuguese ma Arabic sy Arabic ara Arabic ua Ukrainian cz Czech +ru Russian sk Slovak nl Dutch it Italian hu Hungarian cn Chinese tw Taiwanese vn Vietnamese +kr Korean jp Japanese th Thai la Lao pl Polish se Swedish is Icelandic fi Finnish dk Danish +be Belgian in Indian al Albanian am Armenian bd Bangla ba Bosnian bg Bulgarian dz Berber +mm Burmese hr Croatian gr Greek il Hebrew ir Persian iq Iraqi af Afghani fo Faroese ge Georgian +ee Estonian kg Kyrgyz kz Kazakh lt Lithuanian mt Maltese mn Mongolian no Norwegian ro Romanian +rs Serbian si Slovenian tj Tajik lk Sinhala tr Turkish uz Uzbek ie Irish pk Urdu mv Dhivehi +epo Esperanto np Nepali et Amharic sn Wolof ml Bambara tz Swahili ke Swahili bw Tswana +ph Filipino id Indonesian my Malay tm Turkmen bt Dzongkha lv Latvian md Moldavian mao Maori +by Belarusian me Montenegrin mk Macedonian kh Khmer az Azerbaijani" declare -Agr 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 -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]}" ) @@ -93,7 +86,7 @@ declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]="" # } -init_variables() { +init() { declare -g BT="$DIST Installer - (x86_64) - Version $VER" declare -g ROOT_PART="" declare -g BOOT_DEVICE="" @@ -136,14 +129,22 @@ init_variables() { [8]="/etc/crypttab" [9]="/etc/default/grub" [10]="/etc/pacman.conf" + [11]="" ) } -source_file() { - . "$1" || { printf "\nFailed to source library file %s" "$1"; die 1; } +devices() { + IGNORE_DEV="$(lsblk -lno NAME,MOUNTPOINT | awk '/\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')" + if [[ $IGNORE_DEV ]]; then + SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ && !'"/$IGNORE_DEV/"' {print "/dev/" $1 " " $2}')" + else + SYS_DEVS="$(lsblk -lno NAME,SIZE,TYPE | awk '/disk/ {print "/dev/" $1 " " $2}')" + fi + DEV_COUNT="$(wc -l <<< "$SYS_DEVS")" + declare -gr SYS_DEVS IGNORE_DEV DEV_COUNT } -user_creation() { +user() { tput cnorm local values values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \ @@ -176,16 +177,16 @@ user_creation() { rpass2="$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$values" | awk -F'~' '{print $6}' | openssl enc -pbkdf2 -a -salt -pass pass:$SALT)" - # due to the encryption the string while encrypted will not be empty + # due to encrypting the string, when empty, once encrypted it wont be empty local empty empty="$(openssl enc -pbkdf2 -a -salt -pass pass:$SALT <<< "")" # both root passwords are empty, so use the user passwords instead - [[ $rpass == "" && $rpass2 == "" ]] && { rpass="$pass"; rpass2="$pass2"; } + [[ $rpass == "$empty" && $rpass2 == "$empty" ]] && { 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 == "$empty" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then - if [[ $pass == "" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then + if [[ ${#user} -eq 0 || $user =~ \ |\' || $user =~ [^a-z0-9] || $pass == "$empty" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then + if [[ $pass == "$empty" || "$pass" != "$pass2" || "$rpass" != "$rpass2" ]]; then # password was left empty or doesn't match if [[ $pass == "$empty" ]]; then msgbox "$_ErrTitle" "\nUser password CANNOT be left empty.\n$_TryAgain" @@ -199,7 +200,7 @@ user_creation() { user="" fi # recursively loop back unless the user cancels - user_creation || return 1 + user || return 1 else NEWUSER="$user" USER_PASS="$pass" @@ -208,7 +209,7 @@ user_creation() { return 0 } -select_language() { +language() { tput civis local lang lang=$(dialog --cr-wrap --stdout --backtitle "$BT" --title " Select Language " --menu \ @@ -219,20 +220,20 @@ select_language() { "7" "Italiano (it_IT)" "8" "Nederlands (nl_NL)" \ "9" "Magyar (hu_HU)" "10" "Chinese (zh_CN)") - source_file $TRN/english.trans + src $TRN/english.trans 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" ;; + 2) src $TRN/spanish.trans && LOC="es_ES.UTF-8" ;; + 3) src $TRN/p_brasil.trans && LOC="pt_BR.UTF-8" ;; + 4) src $TRN/portuguese.trans && LOC="pt_PT.UTF-8" ;; + 5) src $TRN/french.trans && LOC="fr_FR.UTF-8" ;; + 6) src $TRN/russian.trans && LOC="ru_RU.UTF-8" FONT="LatKaCyrHeb-16" ;; + 7) src $TRN/italian.trans && LOC="it_IT.UTF-8" ;; + 8) src $TRN/dutch.trans && LOC="nl_NL.UTF-8" ;; + 9) src $TRN/hungarian.trans && LOC="hu_HU.UTF-8" FONT="lat2-16" ;; + 10) src $TRN/chinese.trans && LOC="zh_CN.UTF-8" ;; *) die 0 esac @@ -247,7 +248,7 @@ select_language() { return 0 } -setup_keymap() { +keymap() { tput civis KEYMAP="$(dialog --cr-wrap --stdout --backtitle "$BT" \ --title " $_PrepLayout " --menu "$_XMapBody" 20 70 12 $KEYMAPS)" @@ -270,7 +271,7 @@ setup_keymap() { return 0 } -setup_timezone() { +timezone() { tput civis ZONE="$(dialog --cr-wrap --stdout --backtitle "$BT" \ --title " $_TimeZTitle " --menu "$_TimeZBody" 20 70 10 America - Australia - \ @@ -281,10 +282,10 @@ setup_timezone() { --title " $_TimeZTitle " --menu "$_TimeSubZBody" 20 70 12 ${SUBZONES[$ZONE]})" [[ $? != 0 || $SUBZONE == "" ]] && return 1 - yesno "$_TimeZTitle" "$_TimeZQ $ZONE/$SUBZONE?\n" && return 0 || setup_timezone + yesno "$_TimeZTitle" "$_TimeZQ $ZONE/$SUBZONE?\n" && return 0 || timezone } -window_manager() { +sessions() { INSTALL_WMS="$(dialog --cr-wrap --stdout --backtitle "$BT" \ --title " $_WMChoice " --checklist "$_WMChoiceBody\n" 0 0 0 \ "openbox" "A lightweight, powerful, and highly configurable stacking window manager" off \ @@ -296,23 +297,24 @@ window_manager() { "xfce4" "A lightweight and modular desktop environment based on GTK+ 2 and 3" off)" [[ $? != 0 || $INSTALL_WMS == "" ]] && return 1 WM_NUM=$(awk '{print NF}' <<< "$INSTALL_WMS") + WM_PACKAGES="$INSTALL_WMS" - # packages needed for the selected window manager + # packages needed for the selected WM/DE for wm in $INSTALL_WMS; do LOGIN_CHOICES="${LOGIN_CHOICES}$wm - " case $wm in - cinnamon) WM_PACKAGES+=" $wm" ;; - bspwm) WM_PACKAGES+=" $wm sxhkd" ;; - gnome) WM_PACKAGES+=" $wm gnome-extra" ;; - i3-gaps) WM_PACKAGES+=" $wm i3status perl-anyevent-i3" ;; - xfce4) WM_PACKAGES+=" $wm xfce4-goodies xfce4-pulseaudio-plugin" ;; - openbox) WM_PACKAGES+=" $wm obconf archlabs-obkey archlabs-kickshaw archlabs-skippy-xd tint2 conky jgmenu" ;; + cinnamon) : ;; # none + bspwm) WM_PACKAGES+=" sxhkd" ;; + gnome) WM_PACKAGES+=" gnome-extra" ;; + i3-gaps) WM_PACKAGES+=" i3status perl-anyevent-i3" ;; + xfce4) WM_PACKAGES+=" xfce4-goodies xfce4-pulseaudio-plugin" ;; + openbox) WM_PACKAGES+=" obconf archlabs-obkey archlabs-kickshaw archlabs-skippy-xd tint2 conky jgmenu" ;; esac done if [[ $INSTALL_WMS =~ (openbox|bspwm|i3-gaps) ]]; then - WM_PACKAGES+=" archlabs-polybar jsoncpp libmpdclient archlabs-screenlock archlabs-oblogout" - WM_PACKAGES+=" archlabs-paranoid lxappearance rofi termite thunar" + WM_PACKAGES+=" archlabs-polybar archlabs-paranoid archlabs-screenlock archlabs-oblogout" + WM_PACKAGES+=" rofi termite thunar lxappearance libmpdclient jsoncpp" elif [[ $INSTALL_WMS =~ (xfce4) ]]; then WM_PACKAGES+=" archlabs-oblogout archlabs-screenlock archlabs-paranoid" fi @@ -333,7 +335,7 @@ window_manager() { else LOGIN_TYPE='lightdm' WM_PACKAGES+=" lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings accountsservice" - FILES[11]="/etc/lightdm/lightdm.conf $MNT/etc/lightdm/lightdm-gtk-greeter.conf" + FILES[11]="/etc/lightdm/lightdm.conf /etc/lightdm/lightdm-gtk-greeter.conf" fi EXTRA_PACKAGES="$WM_PACKAGES" @@ -351,7 +353,7 @@ window_manager() { return 0 } -extra_packages() { +packages() { local pkgs pkgs="$(dialog --cr-wrap --stdout --backtitle "$BT" \ --title " $_ExtraPackages " --checklist "$_ExtraPackagesBody\n" 0 0 30 \ @@ -436,30 +438,26 @@ extra_packages() { [[ $pkgs =~ noto-fonts ]] && pkgs+=" noto-fonts-emoji" [[ $pkgs =~ cairo-dock ]] && pkgs+=" cairo-dock-plug-ins" [[ $pkgs =~ kdenlive ]] && pkgs+=" kdebase-runtime dvdauthor frei0r-plugins breeze breeze-gtk" - if [[ $INSTALL_WMS =~ dwm ]] && ! [[ $pkgs =~ ttf-hack ]]; then - pkgs+=" ttf-hack" - fi - if [[ $pkgs =~ (qutebrowser|qbittorrent|kdenlive|vlc) ]] && ! [[ $pkgs =~ qt5ct ]]; then - pkgs+=" qt5ct qt5-styleplugins" - fi + ([[ $INSTALL_WMS =~ dwm ]] && ! [[ $pkgs =~ ttf-hack ]]) && pkgs+=" ttf-hack" + ([[ $pkgs =~ (qutebrowser|qbittorrent|kdenlive|vlc) ]] && ! [[ $pkgs =~ qt5ct ]]) && pkgs+=" qt5ct qt5-styleplugins" - EXTRA_PACKAGES="$EXTRA_PACKAGES$([[ $pkgs ]] && printf " %s" "$pkgs")" + EXTRA_PACKAGES+="$pkgs" return 0 } -mirrorlist_cmd() { +mirrors() { local key="5f29642060ab983b31fdf4c2935d8c56" local ip="$(curl -s "http://api.ipstack.com/check&fields=ip&?access_key=${key}" | - val_from_json 'ip')" + json 'ip')" if hash reflector >/dev/null 2>&1; then - MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate" + MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate --verbose" yesno "$_MirrorTitle" "$_MirrorSetup" "Automatic" "Custom" && return 0 local c="$(curl -s "http://api.ipstack.com/${ip}?access_key=${key}&fields=country_name" | - val_from_json 'country_name')" + json 'country_name')" if [[ $c != "" ]]; then - MIRROR_CMD="reflector --country $c --score 80 --latest 40 --fastest 10 --sort rate" + MIRROR_CMD="reflector --country $c --score 80 --latest 40 --fastest 10 --sort rate --verbose" fi tput cnorm @@ -477,7 +475,7 @@ mirrorlist_cmd() { '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')" + json 'country_code')" local w="https://www.archlinux.org/mirrorlist" if [[ $c != "" ]]; then @@ -493,37 +491,37 @@ mirrorlist_cmd() { return 0 } -display_selection() { +display() { msgbox "$_PrepTitle" "\nConfiguration values used for install\n\n -Root: $ROOT_PART -Boot: $BOOT_PART -Swap: $SWAP -Extra: ${EXTRA_MNTS:-None} +Root: $ROOT_PART +Boot: $BOOT_PART +Swap: $SWAP +Extra: ${EXTRA_MNTS:-None} -LVM: $LVM -LUKS: $LUKS +LVM: $LVM +LUKS: $LUKS Bootloader: $BOOTLDR Boot Mount: ${BMNTS[$SYS-$BOOTLDR]} Boot Command: ${BCMDS[$BOOTLDR]} -New User: $NEWUSER -Login: $LOGIN_WM -Autologin: $AUTOLOGIN -Login Type: $LOGIN_TYPE +User: $NEWUSER +Hostname: $HOSTNAME +Locale: $LOCALE +Keymap: $KEYMAP +Timezone: $ZONE/$SUBZONE -Hostname: $HOSTNAME -Locale: $LOCALE -Keymap: $KEYMAP -Timezone: $ZONE/$SUBZONE +Autologin: $AUTOLOGIN +Login: $LOGIN_WM +Login Type: $LOGIN_TYPE -Kernel: $KERNEL -Sessions: $INSTALL_WMS -Mirrors: $MIRROR_CMD -Packages: $EXTRA_PACKAGES\n" +Sessions: $INSTALL_WMS +Kernel: $KERNEL +Mirrors: $MIRROR_CMD +Packages: $EXTRA_PACKAGES\n" } -configure_install() { +configure() { tput cnorm HOSTNAME="$(getinput "$_ConfHost" "$_HostNameBody" "${DIST,,}")" [[ $? != 0 || $HOSTNAME == "" ]] && return 1 @@ -533,22 +531,22 @@ configure_install() { --title " $_ConfLocale " --menu "$_LocaleBody" 25 70 20 $LOCALES)" [[ $? != 0 || $LOCALE == "" ]] && return 1 - setup_timezone || return 1 - mirrorlist_cmd || return 1 - user_creation || return 1 - window_manager || return 1 + timezone || return 1 + mirrors || return 1 + user || return 1 + sessions || return 1 yesno 'Choose Kernel' "\nUse the current kernel or the LTS kernel?\n" 'Current' 'LTS' && KERNEL='linux' || KERNEL='linux-lts' - extra_packages || return 1 + packages || return 1 CONFIG_DONE=true return 0 } -edit_configs() { +configs() { if [[ $CURRENT_MENU != "edit" ]]; then SELECTED=1 CURRENT_MENU="edit" - elif (( SELECTED < 10 )); then + elif (( SELECTED < 11 )); then (( SELECTED++ )) fi @@ -557,7 +555,7 @@ edit_configs() { --title " $_EditTitle " --default-item $SELECTED --menu "$_EditBody" 0 0 0 \ "1" "Exit & Reboot" "2" "Keyboard" "3" "Locale" "4" "Hostname" "5" "Sudoers" \ "6" "Mkinitcpio.conf" "7" "Fstab" "8" "Crypttab" "9" "${BOOTLDR^}" "10" "Pacman.conf" \ - "11" "$LOGIN_TYPE") + "11" "${LOGIN_TYPE^}") if [[ ! $SELECTED || $SELECTED -eq 1 ]]; then wrap_up "$_InstFinBody" 'Reboot' 'Back' 'reboot' @@ -568,14 +566,14 @@ edit_configs() { done [[ ! $existing_files ]] && msgbox "$_ErrTitle" "$_NoFileErr" || vim -O $existing_files fi - edit_configs + configs } main() { if [[ $CURRENT_MENU != "main" ]]; then SELECTED=1 CURRENT_MENU="main" - elif (( SELECTED < 8 )); then + elif (( SELECTED < 9 )); then ((SELECTED++)) # increment the highlighted menu item fi @@ -590,7 +588,7 @@ main() { # and that the needed config variables and user variables have been set up if [[ $SELECTED ]]; then if [[ $SELECTED -eq 8 ]]; then - check_install_ready || return 1 + icheck || return 1 elif [[ ($SELECTED -eq 2 || $SELECTED -eq 5) && $WARN != true ]]; then msgbox "$_PrepTitle" "$_WarnMount" WARN=true @@ -598,23 +596,27 @@ main() { fi case $SELECTED in - 1) show_devices ;; - 2) edit_partitions ;; - 3) luks_menu || SELECTED=1 ;; - 4) lvm_menu || SELECTED=1 ;; - 5) mount_main || SELECTED=1 ;; - 6) configure_install ;; - 7) display_selection ;; - 8) install_main && edit_configs ;; + 1) device_tree ;; + 2) partition || SELECTED=1 ;; + 3) luks_menu || SELECTED=2 ;; + 4) lvm_menu || SELECTED=3 ;; + 5) mountp || SELECTED=4 ;; + 6) configure || SELECTED=5 ;; + 7) display ;; + 8) install || SELECTED=7 ;; *) wrap_up "$_CloseInstBody" 'Exit' 'Back' 'exit' esac } # must be done first -init_variables +init -for file in /usr/share/archlabs/installer/lib/?*.sh; do - source_file "$file" +# declares system device list +devices + +# source all the lib files +for i in /usr/share/archlabs/installer/lib/?*.sh; do + . "$i" || { printf "\nFailed to source library file %s\n" "$i"; die 1; } done # trap Ctrl-C to properly exit @@ -624,10 +626,13 @@ for arg in $@; do case $arg in --debug|-d) debug ;; esac done -select_language -setup_keymap -check_requirements -identify_system +# initial choices/prep +language +keymap +checks +sysid + +# welcome message msgbox "$_WelTitle $DIST Installer" "$_WelBody" while true; do diff --git a/src/lib/boot.sh b/src/lib/boot.sh index 66ab524..454090f 100644 --- a/src/lib/boot.sh +++ b/src/lib/boot.sh @@ -55,13 +55,13 @@ prep_for_systemd-boot() { [[ $ROOT_PART =~ /dev/mapper ]] || ROOT_PART_ID="PART$ROOT_PART_ID" # create the boot entry configs - mkdir -p ${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/loader/entries - cat > ${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/loader/loader.conf << EOF + mkdir -p ${MNT}${BMNTS[$SYS-$BOOTLDR]}/loader/entries + cat > ${MNT}${BMNTS[$SYS-$BOOTLDR]}/loader/loader.conf << EOF default $DIST timeout 5 editor no EOF - cat > ${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/loader/entries/${DIST}.conf << EOF + cat > ${MNT}${BMNTS[$SYS-$BOOTLDR]}/loader/entries/${DIST}.conf << EOF title $DIST Linux linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE") initrd /initramfs-$KERNEL.img @@ -87,11 +87,11 @@ EOF prep_for_syslinux() { if [[ $SYS == 'UEFI' ]]; then - local cfgdir="${MNT}${BOOT_MNTS[$SYS-$BOOTLDR]}/EFI/syslinux" + local cfgdir="${MNT}${BMNTS[$SYS-$BOOTLDR]}/EFI/syslinux" local cfgsrcdir="/usr/lib/syslinux/efi32/" [[ $IS_64BIT == true ]] && cfgsrcdir="/usr/lib/syslinux/efi64/" else - local cfgdir="$MNT${BOOT_MNTS[$SYS-$BOOTLDR]}/syslinux" + local cfgdir="$MNT${BMNTS[$SYS-$BOOTLDR]}/syslinux" local cfgsrcdir="/usr/lib/syslinux/bios/" fi @@ -138,8 +138,8 @@ install_bootloader() { prep_for_$BOOTLDR # install/setup the bootloader by running the BCMD (boot command) - chroot_cmd "${BCMDS[$BOOTLDR]}" 2>$ERR - check_for_errors "${BCMDS[$BOOTLDR]}" + chrun "${BCMDS[$BOOTLDR]}" # 2>$ERR + echeck "${BCMDS[$BOOTLDR]}" # copy efi stub to generic catch all [[ $SYS == 'UEFI' && $BOOTLDR =~ (grub|syslinux) ]] && uefi_boot_fallback diff --git a/src/lib/install.sh b/src/lib/install.sh index cc712e6..fe8b9f9 100644 --- a/src/lib/install.sh +++ b/src/lib/install.sh @@ -8,29 +8,21 @@ # set -n -install_main() { +install() { # function calls prefixed with 'oneshot' will only ever be run once # otherwise the main function can be called repeatedly - clear - tput cnorm + clear; tput cnorm # unpack the file system oneshot install_base # generate /etc/fstab and touch it up if we used a swapfile - genfstab -U $MNT > $MNT/etc/fstab 2>$ERR - check_for_errors "genfstab -U $MNT > $MNT/etc/fstab" + genfstab -U $MNT > $MNT/etc/fstab # 2>$ERR + echeck "genfstab -U $MNT > $MNT/etc/fstab" [[ -f $MNT/swapfile ]] && sed -i "s~${MNT}~~" $MNT/etc/fstab # update the mirrorlist.. MUST be done before updating or it may be slow - 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 + oneshot mirrorlist_sort # MUST be before bootloader and mkinitcpio oneshot package_operations @@ -44,11 +36,26 @@ install_main() { install_bootloader # hwclock setup, falls back to setting --directisa if the default fails - chroot_cmd "hwclock --systohc --utc" || chroot_cmd "hwclock --systohc --utc --directisa" + chrun "hwclock --systohc --utc" || chrun "hwclock --systohc --utc --directisa" # create the user last to avoid referencing multiple $HOME locations for liveuser/newuser oneshot create_user - return 0 + + # drop off the user at the config editing menu + configs +} + +mirrorlist_sort() { + printf "%s\n\n" "Sorting the mirrorlist" + if hash reflector >/dev/null 2>&1; then + $MIRROR_CMD --save $MNT/etc/pacman.d/mirrorlist --verbose || + reflector --score 100 -l 50 -f 10 \ + --sort rate --verbose --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 } install_base() { @@ -95,8 +102,8 @@ EOF LANG=$LOCALE EOF sed -i "s/#en_US.UTF-8/en_US.UTF-8/g; s/#${LOCALE}/${LOCALE}/g" $MNT/etc/locale.gen - chroot_cmd "locale-gen" 2>/dev/null - chroot_cmd "ln -sf /usr/share/zoneinfo/$ZONE/$SUBZONE /etc/localtime" 2>/dev/null + chrun "locale-gen" 2>/dev/null + chrun "ln -sf /usr/share/zoneinfo/$ZONE/$SUBZONE /etc/localtime" 2>/dev/null # set the keymaps cat > $MNT/etc/X11/xorg.conf.d/00-keyboard.conf <$ERR - check_for_errors "mkinitcpio -p $KERNEL" + chrun "mkinitcpio -p $KERNEL" # 2>$ERR + echeck "mkinitcpio -p $KERNEL" } package_operations() { @@ -195,6 +202,10 @@ package_operations() { fi fi + if [[ $UCODE == 'amd-ucode.img' ]]; then + inpkg+=" amd-ucode" + fi + # for only gnome or cinnamon we don't need the xfce provided stuff [[ $INSTALL_WMS =~ (gnome|cinnamon) ]] && rmpkg+=" $(pacman -Qssq 'xfce4*' 2>/dev/null)" @@ -209,10 +220,10 @@ package_operations() { fi # iputils, base-devel, and git are all needed and should always be installed separately - chroot_cmd "pacman -Syyu --noconfirm" - chroot_cmd "pacman -S iputils git --noconfirm; pacman -S base-devel --needed --noconfirm" - chroot_cmd "pacman -S $inpkg --needed --noconfirm" - chroot_cmd "pacman -Rs $rmpkg --noconfirm" + chrun "pacman -Syyu --noconfirm" + chrun "pacman -S iputils git --noconfirm; pacman -S base-devel --needed --noconfirm" + chrun "pacman -S $inpkg --needed --noconfirm" + chrun "pacman -Rs $rmpkg --noconfirm" # for neovim copy the default vimrc and colorscheme to ~/.config/nvim if [[ $EXTRA_PACKAGES =~ neovim ]]; then @@ -226,7 +237,7 @@ package_operations() { mkdir -pv $MNT/home/$LIVE/suckless for i in dwm dmenu st; do p="/home/$LIVE/suckless/$i" - chroot_cmd "git clone https://bitbucket.org/natemaia/$i $p && { cd $p; rm -f $p/config.h 2>/dev/null; make clean install && make clean; }" + chrun "git clone https://bitbucket.org/natemaia/$i $p && { cd $p; rm -f $p/config.h 2>/dev/null; make clean install && make clean; }" done fi } @@ -238,7 +249,7 @@ login_manager() { for f in $MNT/home/$LIVE/.{xinitrc,zprofile}; do awk '{if($0 && $0 !~ "^#") print "# "$0; else print $0}' $f > $f done - chroot_cmd 'systemctl enable lightdm.service && systemctl set-default graphical.target' + chrun 'systemctl enable lightdm.service && systemctl set-default graphical.target' cat > $MNT/etc/lightdm/lightdm-gtk-greeter.conf << EOF # LightDM GTK+ Configuration @@ -252,7 +263,7 @@ font-name=DejaVu Sans Mono 11 position=30%,end 50%,end EOF if [[ $AUTOLOGIN == true ]]; then - chroot_cmd "groupadd -r nopasswdlogin && usermod -aG nopasswdlogin $NEWUSER" + chrun "groupadd -r nopasswdlogin && usermod -aG nopasswdlogin $NEWUSER" sed -i '/#%PAM-1.0/ a auth sufficient pam_succeed_if.so user ingroup nopasswdlogin' $MNT/etc/pam.d/lightdm sed -i "/#autologin-session=/ c autologin-session=${LOGIN_WM}" $MNT/etc/lightdm/lightdm.conf sed -i "/#autologin-user=/ c autologin-user=${NEWUSER}" $MNT/etc/lightdm/lightdm.conf @@ -264,7 +275,7 @@ EOF elif grep -q 'exec sudo archlabs-installer' $MNT/home/$LIVE/.zprofile; then sed -i 's|exec sudo archlabs-installer|exec startx -- vt1 >/dev/null 2>&1|' $MNT/home/$LIVE/.zprofile else - cat > ~/test << EOF + cat > $MNT/home/$LIVE/.zprofile << EOF if [[ ! \$DISPLAY && \$XDG_VTNR -eq 1 ]]; then exec startx -- vt1 >/dev/null 2>&1 fi diff --git a/src/lib/luks.sh b/src/lib/luks.sh index 398ca2a..1229038 100644 --- a/src/lib/luks.sh +++ b/src/lib/luks.sh @@ -18,7 +18,7 @@ declare -g LUKS_NAME="cryptroot" luks_open() { LUKS_PART="" modprobe -a dm-mod dm_crypt - unmount_partitions + unmountp find_partitions 'part|crypt|lvm' || return 1 tput civis @@ -36,8 +36,8 @@ luks_open() { luks_pass "$_LuksOpen" "$LUKS_NAME" || return 1 infobox "$_LuksOpen" "$_LuksWaitBody $LUKS_NAME $_LuksWaitBody2 $LUKS_PART\n" 0 - cryptsetup open --type luks $LUKS_PART "$LUKS_NAME" <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" 2>$ERR - check_for_errors "cryptsetup open --type luks $LUKS_PART $LUKS_NAME" + cryptsetup open --type luks $LUKS_PART "$LUKS_NAME" <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" # 2>$ERR + echeck "cryptsetup open --type luks $LUKS_PART $LUKS_NAME" LUKS=1 luks_show @@ -88,7 +88,7 @@ luks_pass() { luks_setup() { LUKS_PART="" modprobe -a dm-mod dm_crypt - unmount_partitions + unmountp if [[ $ROOT_PART == "" || $LVM -eq 1 ]]; then find_partitions 'part|lvm' || return 1 @@ -117,11 +117,11 @@ luks_default() { luks_setup || return 1 infobox "$_LuksEncrypt" "$_LuksWaitBody $LUKS_NAME $_LuksWaitBody2 $LUKS_PART\n" 0 - cryptsetup -q luksFormat $LUKS_PART <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" 2>$ERR - check_for_errors "cryptsetup -q luksFormat $LUKS_PART" + cryptsetup -q luksFormat $LUKS_PART <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" # 2>$ERR + echeck "cryptsetup -q luksFormat $LUKS_PART" - cryptsetup open $LUKS_PART "$LUKS_NAME" <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" 2>$ERR - check_for_errors "cryptsetup open $LUKS_PART $LUKS_NAME" + cryptsetup open $LUKS_PART "$LUKS_NAME" <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" # 2>$ERR + echeck "cryptsetup open $LUKS_PART $LUKS_NAME" LUKS=1 luks_show @@ -137,11 +137,11 @@ luks_keycmd() { infobox "$_LuksEncryptAdv" "$_LuksWaitBody $LUKS_NAME $_LuksWaitBody2 $LUKS_PART\n" 0 - cryptsetup -q $cipher luksFormat $LUKS_PART <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" 2>$ERR - check_for_errors "cryptsetup -q $cipher luksFormat $LUKS_PART" + cryptsetup -q $cipher luksFormat $LUKS_PART <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" # 2>$ERR + echeck "cryptsetup -q $cipher luksFormat $LUKS_PART" - cryptsetup open $LUKS_PART "$LUKS_NAME" <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" 2>$ERR - check_for_errors "cryptsetup open $LUKS_PART $LUKS_NAME" + cryptsetup open $LUKS_PART "$LUKS_NAME" <<< "$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")" # 2>$ERR + echeck "cryptsetup open $LUKS_PART $LUKS_NAME" luks_show return 0 @@ -191,8 +191,8 @@ luks_keyfile() { mkkey="$mkkey && chmod 000 /crypto_keyfile.bin" mkkey="$mkkey && cryptsetup luksAddKey /dev/$n /crypto_keyfile.bin <<< '$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$LUKS_PASS")'" - chroot_cmd "$mkkey" - sed -i 's/FILES=()/FILES=(\/crypto_keyfile.bin)/g' $MNT/etc/mkinitcpio.conf 2>$ERR + chrun "$mkkey" + sed -i 's/FILES=()/FILES=(\/crypto_keyfile.bin)/g' $MNT/etc/mkinitcpio.conf # 2>$ERR fi return 0 diff --git a/src/lib/lvm.sh b/src/lib/lvm.sh index 33f14d6..f63ee0e 100644 --- a/src/lib/lvm.sh +++ b/src/lib/lvm.sh @@ -21,7 +21,7 @@ lvm_detect() { infobox "$_PrepLVM" "$_LvmDetBody" 0 modprobe dm-mod 2>$ERR - check_for_errors 'modprobe dm-mod' + echeck 'modprobe dm-mod' vgscan >/dev/null 2>&1 vgchange -ay >/dev/null 2>&1 @@ -140,8 +140,8 @@ lvm_extra_lvs() { get_lv_size || { break; return 1; } # create it - lvcreate -L "$VOLUME_SIZE" "$VOLUME_GROUP" -n "$VOLUME_NAME" 2>$ERR - check_for_errors "lvcreate -L $VOLUME_SIZE $VOLUME_GROUP -n $VOLUME_NAME" + lvcreate -L "$VOLUME_SIZE" "$VOLUME_GROUP" -n "$VOLUME_NAME" # 2>$ERR + echeck "lvcreate -L $VOLUME_SIZE $VOLUME_GROUP -n $VOLUME_NAME" msgbox "$_LvmCreateVG (LV:$VOL_COUNT)" "$_Done LV $VOLUME_NAME ($VOLUME_SIZE) $_LvmPvDoneBody2." ((VOL_COUNT--)) # decrement the number of volumes chosen after each loop @@ -184,8 +184,8 @@ lvm_create_group() { # create it infobox "$_LvmCreateVG" "$_LvmPvActBody1 $VOLUME_GROUP\n" 0 - vgcreate -f "$VOLUME_GROUP" "$GROUP_PARTS" >/dev/null 2>$ERR - check_for_errors "vgcreate -f $VOLUME_GROUP $GROUP_PARTS" + vgcreate -f "$VOLUME_GROUP" "$GROUP_PARTS" >/dev/null # 2>$ERR + echeck "vgcreate -f $VOLUME_GROUP $GROUP_PARTS" # get volume size size and transform size to MB if size is given in GB GROUP_SIZE=$(vgdisplay "$VOLUME_GROUP" | awk '/VG Size/ {print int($3)}') @@ -202,7 +202,7 @@ lvm_create() { VOLUME_GROUP="" GROUP_PARTS="" VOL_GROUP_MB=0 - unmount_partitions + unmountp if [[ $LUKS -eq 1 && $LUKS_NAME != "" ]]; then GROUP_PARTS="/dev/mapper/$LUKS_NAME" @@ -217,8 +217,8 @@ lvm_create() { # last or only logical volume lvm_volume_name "$_LvmLvNameBody1 $_LvmLvNameBody2 (${VOL_GROUP_MB}MB)" || return 1 - lvcreate -l +100%FREE "$VOLUME_GROUP" -n "$VOLUME_NAME" 2>$ERR - check_for_errors "lvcreate -l +100%FREE $VOLUME_GROUP -n $VOLUME_NAME" + lvcreate -l +100%FREE "$VOLUME_GROUP" -n "$VOLUME_NAME" # 2>$ERR + echeck "lvcreate -l +100%FREE $VOLUME_GROUP -n $VOLUME_NAME" LVM=1 diff --git a/src/lib/mount.sh b/src/lib/mount.sh index f9fa124..572812c 100644 --- a/src/lib/mount.sh +++ b/src/lib/mount.sh @@ -15,7 +15,7 @@ format() { infobox "$_FSTitle" "\nFormatting: $1\n\nCommand: ${FS_CMDS[$2]}\n" 0 ${FS_CMDS[$2]} $1 >/dev/null 2>$ERR - check_for_errors "${FS_CMDS[$2]} $1" + echeck "${FS_CMDS[$2]} $1" } decr_count() { @@ -30,15 +30,15 @@ decr_count() { enable_swap() { if [[ $1 == "$MNT/swapfile" ]]; then - fallocate -l $SWAP_SIZE $1 2>$ERR - check_for_errors "fallocate -l $SWAP_SIZE $1" - chmod 600 $1 2>$ERR - check_for_errors "chmod 600 $1" + fallocate -l $SWAP_SIZE $1 # 2>$ERR + echeck "fallocate -l $SWAP_SIZE $1" + chmod 600 $1 # 2>$ERR + echeck "chmod 600 $1" fi - mkswap $1 >/dev/null 2>$ERR - check_for_errors "mkswap $1" - swapon $1 >/dev/null 2>$ERR - check_for_errors "swapon $1" + mkswap $1 >/dev/null # 2>$ERR + echeck "mkswap $1" + swapon $1 >/dev/null # 2>$ERR + echeck "swapon $1" return 0 } @@ -50,11 +50,11 @@ mount_partition() { mkdir -p "$mount" if [[ ${FS_OPTS[$fs]} != "" && $part != "$BOOT_PART" ]] && select_mount_opts "$part" "$fs"; then - mount -o $MNT_OPTS $part "$mount" 2>$ERR - check_for_errors "mount -o $MNT_OPTS $part $mount" + mount -o $MNT_OPTS $part "$mount" # 2>$ERR + echeck "mount -o $MNT_OPTS $part $mount" else - mount $part "$mount" 2>$ERR - check_for_errors "mount $part $mount" + mount $part "$mount" # 2>$ERR + echeck "mount $part $mount" fi confirm_mount $part "$mount" || return 1 @@ -213,7 +213,7 @@ setup_boot_device() { return 0 } -show_devices() { +device_tree() { tput civis local msg if [[ $IGNORE_DEV != "" ]]; then @@ -229,7 +229,7 @@ show_devices() { select_device() { local dev local msg - [[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || unmount_partitions + [[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || unmountp if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")" @@ -249,11 +249,10 @@ select_device() { # if the device selected was for grub bootloader, set the BOOT_DEVICE # this is needed because grub uses the base device for BIOS, not the partition [[ $1 == 'boot' ]] && BOOT_DEVICE="$DEVICE" - return 0 } -edit_partitions() { +partition() { local device if [[ $# -eq 0 ]]; then select_device 'root' || return 1 @@ -272,17 +271,16 @@ edit_partitions() { tput civis if [[ $choice != "$_PartWipe" && $choice != "$_PartAuto" && $choice != "$_PartShowTree" ]]; then - clear; tput cnorm - $choice $device + clear; tput cnorm; $choice $device elif [[ $choice == "$_PartShowTree" ]]; then msgbox "$_PrepShowDev" "\n$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT "$device")\n" - edit_partitions $device + partition $device elif [[ $choice == "$_PartWipe" ]]; then yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2" && wipe -Ifrev $device - edit_partitions $device + partition $device else # if auto_partition fails we need to re-initialize the variables, just to be sure - auto_partition $device || { initialize_variables; return 1; } + auto_partition $device || { init; return 1; } fi } @@ -290,10 +288,10 @@ edit_partitions() { ## Mount functions ## ######################################################## -mount_main() { +mountp() { # prepare partition list PARTS for dialog lvm_detect - unmount_partitions + unmountp find_partitions 'part|lvm|crypt' || return 1 # remove boot partition from dialog list if we auto partitioned one @@ -324,6 +322,13 @@ mount_main() { return 0 } +unmountp() { + swapoff -a + for i in $(mount | awk "/${MNT//\//\\/}/"' {print $3}' | sort -r); do + umount -r "$i" >/dev/null 2>&1 + done +} + select_swap() { # Ask user to select partition or create swapfile tput civis @@ -352,7 +357,7 @@ select_swap() { } select_boot_setup() { - # choose bootloader and by extension mountpoint (if needed) + # choose bootloader and mountpoint (if needed) tput civis BOOTLDR="$(dialog --cr-wrap --stdout --backtitle "$BT" \ --title " $_PrepMount " --menu "$_MntBootBody" 0 0 0 ${BOOTLDRS[$SYS]})" @@ -398,8 +403,13 @@ select_mount_opts() { local title="${fs^} Mount Options" tput civis - MNT_OPTS="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $title " \ - --checklist "$_MntBody" 0 0 0 ${FS_OPTS[$fs]} | sed 's/ /,/g; $s/,$//')" + if ssd "$part"; then + MNT_OPTS="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $title " --checklist \ + "$_MntBody" 0 0 0 $(sed 's/discard - off/discard - on/' <<< "${FS_OPTS[$fs]}") | sed 's/ /,/g; $s/,$//')" + else + MNT_OPTS="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $title " \ + --checklist "$_MntBody" 0 0 0 ${FS_OPTS[$fs]} | sed 's/ /,/g; $s/,$//')" + fi [[ $? != 0 || $MNT_OPTS == "" ]] && return 1 if ! yesno "$title" "$_MntConfBody $MNT_OPTS\n"; then @@ -416,8 +426,8 @@ select_filesystem() { local fs fs="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_FSTitle: $part " \ - --menu "\nPartition: ${part}$([[ $cur_fs != "" ]] && - printf "\nCurrent: %s" "$cur_fs")\n$_FSBody" 0 0 0 \ + --menu "\nPartition Name: ${part}$([[ $cur_fs ]] && + printf "\nExisting Filesystem: %s" "$cur_fs")$_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]}" \ diff --git a/src/lib/utils.sh b/src/lib/utils.sh index 0f4c79e..9ee0187 100644 --- a/src/lib/utils.sh +++ b/src/lib/utils.sh @@ -8,15 +8,26 @@ # set -n -chroot_cmd() { +chrun() { arch-chroot $MNT /bin/bash -c "$1" } -val_from_json() { +json() { python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])" } -identify_system() { +src() { + . "$1" || { printf "\nFailed to source file %s\n" "$1"; die 1; } +} + +ssd() { + local dev=$1 + dev=${dev#/dev/} + [[ $dev =~ nvme ]] && dev=${dev%p[0-9]*} || dev=${dev%[0-9]*} + [[ $(cat /sys/block/$dev/queue/rotational) -eq 0 ]] || return 1 +} + +sysid() { if grep -qi 'apple' /sys/class/dmi/id/sys_vendor; then modprobe -r -q efivars else @@ -34,21 +45,23 @@ identify_system() { return 0 } -check_requirements() { +checks() { if [[ $(whoami) != "root" ]]; then infobox "$_ErrTitle" "$_NotRoot\n$_Exit" && die 1 elif ! grep -qw 'lm' /proc/cpuinfo; then infobox "$_ErrTitle" "$_Not64Bit\n$_Exit" && die 1 - elif ! (curl -s --head 'https://www.archlinux.org/mirrorlist/all/' | head -n 1 | grep -q '200'); then - ([[ $(systemctl is-active NetworkManager) == "active" ]] && hash nmtui >/dev/null 2>&1) && { tput civis; nmtui; } - if ! (curl -s --head 'https://www.archlinux.org/mirrorlist/all/' | head -n 1 | grep -q '200'); then + elif ! curl -s --head 'https://www.archlinux.org/mirrorlist/all/' | head -n 1 | grep -q '200'; then + if [[ $(systemctl is-active NetworkManager) == "active" ]] && hash nmtui >/dev/null 2>&1; then + tput civis; nmtui + fi + if ! curl -s --head 'https://www.archlinux.org/mirrorlist/all/' | head -n 1 | grep -q '200'; then infobox "$_ErrTitle" "$_NoNetwork\n" fi fi return 0 } -check_for_errors() { +echeck() { # return if the last process exited normally (( $? == 0 )) && return 0 local msg="\nThe command exited abnormally: $1" @@ -70,7 +83,7 @@ check_for_errors() { return 0 } -check_install_ready() { +icheck() { [[ $(lsblk -o MOUNTPOINT) =~ $MNT && $CONFIG_DONE == true ]] && return 0 if ! [[ $(lsblk -o MOUNTPOINT) =~ $MNT ]]; then @@ -83,13 +96,6 @@ check_install_ready() { return 1 } -unmount_partitions() { - swapoff -a - for i in $(mount | awk "/${MNT//\//\\/}/"' {print $3}' | sort -r); do - umount -r "$i" >/dev/null 2>&1 - done -} - getinput() { local answer answer="$(dialog --cr-wrap --max-input 63 --stdout --no-cancel \ @@ -133,7 +139,7 @@ wrap_up() { die() { tput cnorm - unmount_partitions + punmount pgrep -f "$TERM_CMD -e tail" && pkill -f "$TERM_CMD -e tail" [[ $1 =~ [0-9] ]] && exit $1 || $1 }