You've already forked al-installer
Reboot fix, possibly??
This commit is contained in:
@ -9,132 +9,85 @@
|
||||
|
||||
# set -n
|
||||
|
||||
# immutable {
|
||||
# globals {
|
||||
|
||||
readonly DIST="ArchLabs" # Linux distributor
|
||||
readonly VER="1.7.5" # 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 TRN="/usr/share/archlabs/installer/lang"
|
||||
readonly RUN="/run/archiso/bootmnt/arch/boot"
|
||||
# immutable values
|
||||
readonly VER="1.7.9" # Installer version
|
||||
readonly DIST="ArchLabs" # Linux distributor
|
||||
readonly LIVE="liveuser" # Live session user
|
||||
readonly MNT="/mnt/install" # Install mountpoint
|
||||
readonly ERR="/tmp/errlog" # Built-in error log
|
||||
|
||||
readonly VM="$(dmesg | grep -i "hypervisor")"
|
||||
readonly SALT="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
|
||||
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 CMAPS="$(find /usr/share/kbd/keymaps -name '*.map.gz' | awk '{gsub(/\.map\.gz|.*\//, ""); print $1 " -"}')"
|
||||
# mutable values
|
||||
declare -g WARN=false
|
||||
declare -g AUTOLOGIN=false
|
||||
declare -g CONFIG_DONE=false
|
||||
declare -g SEPERATE_BOOT=false
|
||||
|
||||
if grep -q 'GenuineIntel' /proc/cpuinfo; then
|
||||
readonly UCODE="intel-ucode.img"
|
||||
elif grep -q 'AuthenticAMD' /proc/cpuinfo; then
|
||||
readonly UCODE="amd-ucode.img"
|
||||
fi
|
||||
|
||||
# create associative array for SUBZONES[zone]
|
||||
declare -gA 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
|
||||
for t in termite st xterm; do
|
||||
hash $t >/dev/null 2>&1 && { readonly TERM_CMD="$t"; break; }
|
||||
done
|
||||
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 KERNELS="linux - linux-lts -"
|
||||
|
||||
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]}"
|
||||
[UEFI]="grub ${BMNTS[UEFI-grub]} systemd-boot ${BMNTS[UEFI-systemd-boot]} syslinux ${BMNTS[UEFI-syslinux]}"
|
||||
)
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]=""
|
||||
[ext4]="discard - off dealloc - 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"
|
||||
[xfs]="discard - off filestreams - off ikeep - off largeio - off noalign - off nobarrier - off norecovery - off noquota - off wsync - off"
|
||||
[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"
|
||||
)
|
||||
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_PART=""
|
||||
declare -g SWAP_SIZE=""
|
||||
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=""
|
||||
declare -g WM_PACKAGES=""
|
||||
declare -g PACKAGES=""
|
||||
declare -g MKINIT_HOOKS="shutdown"
|
||||
|
||||
# }
|
||||
|
||||
init() {
|
||||
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=""
|
||||
declare -g SWAP_SIZE="$SYS_MEM"
|
||||
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"
|
||||
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 \
|
||||
"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)" \
|
||||
"7" "Italiano (it_IT)" "8" "Nederlands (nl_NL)" \
|
||||
"9" "Magyar (hu_HU)" "10" "Chinese (zh_CN)")
|
||||
|
||||
declare -g WARN=false
|
||||
declare -g AUTOLOGIN=false
|
||||
declare -g CONFIG_DONE=false
|
||||
declare -g SEPERATE_BOOT=false
|
||||
local srcdir="/usr/share/archlabs/installer/lang"
|
||||
|
||||
declare -gA BCMDS=(
|
||||
[syslinux]="syslinux-install_update -iam"
|
||||
[grub]="grub-install --recheck --force"
|
||||
[systemd-boot]="bootctl --path=/boot install"
|
||||
)
|
||||
src $srcdir/english.trans
|
||||
FONT="ter-i16n"
|
||||
|
||||
declare -gA 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"
|
||||
[6]="/etc/mkinitcpio.conf"
|
||||
[7]="/etc/fstab"
|
||||
[8]="/etc/crypttab"
|
||||
[9]="/etc/default/grub"
|
||||
[10]="/etc/pacman.conf"
|
||||
[11]=""
|
||||
)
|
||||
case $lang in
|
||||
1) LOC="en_US.UTF-8" ;;
|
||||
2) src $srcdir/spanish.trans && LOC="es_ES.UTF-8" ;;
|
||||
3) src $srcdir/p_brasil.trans && LOC="pt_BR.UTF-8" ;;
|
||||
4) src $srcdir/portuguese.trans && LOC="pt_PT.UTF-8" ;;
|
||||
5) src $srcdir/french.trans && LOC="fr_FR.UTF-8" ;;
|
||||
6) src $srcdir/russian.trans && LOC="ru_RU.UTF-8" FONT="LatKaCyrHeb-16" ;;
|
||||
7) src $srcdir/italian.trans && LOC="it_IT.UTF-8" ;;
|
||||
8) src $srcdir/dutch.trans && LOC="nl_NL.UTF-8" ;;
|
||||
9) src $srcdir/hungarian.trans && LOC="hu_HU.UTF-8" FONT="lat2-16" ;;
|
||||
10) src $srcdir/chinese.trans && LOC="zh_CN.UTF-8" ;;
|
||||
*) die 0
|
||||
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
|
||||
fi
|
||||
[[ $TERM == 'linux' ]] && setfont $FONT >/dev/null 2>&1
|
||||
export LANG="$LOC"
|
||||
return 0
|
||||
}
|
||||
|
||||
user() {
|
||||
user_creation() {
|
||||
tput cnorm
|
||||
local values
|
||||
values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \
|
||||
@ -199,49 +152,30 @@ user() {
|
||||
return 0
|
||||
}
|
||||
|
||||
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 \
|
||||
"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)" \
|
||||
"7" "Italiano (it_IT)" "8" "Nederlands (nl_NL)" \
|
||||
"9" "Magyar (hu_HU)" "10" "Chinese (zh_CN)")
|
||||
|
||||
src $TRN/english.trans
|
||||
FONT="ter-i16n"
|
||||
|
||||
case $lang in
|
||||
1) LOC="en_US.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
|
||||
|
||||
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
|
||||
fi
|
||||
[[ $TERM == 'linux' ]] && setfont $FONT >/dev/null 2>&1
|
||||
export LANG="$LOC"
|
||||
return 0
|
||||
}
|
||||
|
||||
keymap() {
|
||||
select_keymap() {
|
||||
tput civis
|
||||
KEYMAP="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_PrepLayout " --menu "$_XMapBody" 20 70 12 $KEYMAPS)"
|
||||
--title " $_PrepLayout " --menu "$_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' \
|
||||
'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' 'ro' 'Romanian' \
|
||||
'no' 'Norwegian' 'rs' 'Serbian' 'si' 'Slovenian' 'tj' 'Tajik' 'lk' 'Sinhala' \
|
||||
'tr' 'Turkish' 'uz' 'Uzbek' 'ie' 'Irish' 'pk' 'Urdu' 'mv' 'Dhivehi' \
|
||||
'np' 'Nepali' 'et' 'Amharic' 'sn' 'Wolof' 'ml' 'Bambara' 'tz' 'Swahili' \
|
||||
'ke' 'Swahili' 'bw' 'Tswana' 'ph' 'Filipino' 'my' 'Malay' 'tm' 'Turkmen' \
|
||||
'id' 'Indonesian' 'bt' 'Dzongkha' 'lv' 'Latvian' 'md' 'Moldavian' 'mao' 'Maori' \
|
||||
'by' 'Belarusian' 'az' 'Azerbaijani' 'mk' 'Macedonian' 'kh' 'Khmer' 'epo' 'Esperanto' \
|
||||
'me' 'Montenegrin')"
|
||||
[[ $? != 0 || $KEYMAP == "" ]] && return 1
|
||||
|
||||
# when a matching console map is not available open a selection dialog
|
||||
@ -261,35 +195,30 @@ keymap() {
|
||||
return 0
|
||||
}
|
||||
|
||||
timezone() {
|
||||
select_timezone() {
|
||||
# create associative array for SUBZONES[zone]
|
||||
local f="/usr/share/zoneinfo/zone.tab"
|
||||
declare -A SUBZONES
|
||||
for i in America Australia Asia Atlantic Africa Europe Indian Pacific Arctic Antarctica; do
|
||||
SUBZONES[$i]="$(awk '/'"$i"'\// {gsub(/'"$i"'\//, ""); print $3, $1}' $f)"
|
||||
done
|
||||
|
||||
tput civis
|
||||
ZONE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_TimeZTitle " --menu "$_TimeZBody" 20 70 10 America - Australia - \
|
||||
Asia - Atlantic - Africa - Europe - Indian - Pacific - Arctic - Antarctica -)"
|
||||
--title " $_TimeZTitle " --menu "$_TimeZBody" 20 70 10 \
|
||||
'America' '-' 'Australia' '-' 'Asia' '-' 'Atlantic' '-' 'Africa' '-' \
|
||||
'Europe' '-' 'Indian' '-' 'Pacific' '-' 'Arctic' '-' 'Antarctica' '-')"
|
||||
[[ $? != 0 || $ZONE == "" ]] && return 1
|
||||
|
||||
SUBZONE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_TimeZTitle " --menu "$_TimeSubZBody" 20 70 12 ${SUBZONES[$ZONE]})"
|
||||
[[ $? != 0 || $SUBZONE == "" ]] && return 1
|
||||
|
||||
yesno "$_TimeZTitle" "$_TimeZQ $ZONE/$SUBZONE?\n" && return 0 || timezone
|
||||
yesno "$_TimeZTitle" "$_TimeZQ $ZONE/$SUBZONE?\n" && return 0 || select_timezone
|
||||
}
|
||||
|
||||
choose_dm() {
|
||||
LOGIN_TYPE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_WMLogin " --menu "$_LoginTypeBody" 0 0 0 \
|
||||
"xinit" "Console login without a display manager" \
|
||||
"lightdm" "Lightweight display manager with the gtk greeter")"
|
||||
[[ $? -eq 0 ]] || return 1
|
||||
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
|
||||
WM_PACKAGES+=" lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings accountsservice"
|
||||
FILES[11]="/etc/lightdm/lightdm.conf /etc/lightdm/lightdm-gtk-greeter.conf"
|
||||
else
|
||||
FILES[11]="/home/$NEWUSER/.xinitrc /home/$NEWUSER/.zprofile /home/$NEWUSER/.xprofile"
|
||||
fi
|
||||
}
|
||||
|
||||
sessions() {
|
||||
select_wm_or_de() {
|
||||
tput civis
|
||||
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 \
|
||||
@ -303,7 +232,8 @@ sessions() {
|
||||
[[ $INSTALL_WMS ]] || INSTALL_WMS='openbox'
|
||||
|
||||
WM_NUM=$(awk '{print NF}' <<< "$INSTALL_WMS")
|
||||
WM_PACKAGES="$INSTALL_WMS"
|
||||
WM_PACKAGES="${INSTALL_WMS/dwm/}" # remove dwm as we are compiling from source
|
||||
WM_PACKAGES="${INSTALL_WMS// / }" # substitute all double spaces to single
|
||||
|
||||
# packages needed for the selected WMs/DEs
|
||||
for wm in $INSTALL_WMS; do
|
||||
@ -319,40 +249,59 @@ sessions() {
|
||||
done
|
||||
|
||||
if [[ $INSTALL_WMS =~ (openbox|bspwm|i3-gaps) ]]; then
|
||||
WM_PACKAGES+=" archlabs-polybar archlabs-paranoid archlabs-screenlock archlabs-oblogout"
|
||||
WM_PACKAGES+=" rofi termite thunar lxappearance libmpdclient jsoncpp"
|
||||
WM_PACKAGES+=" rofi termite thunar archlabs-polybar archlabs-paranoid"
|
||||
WM_PACKAGES+=" lxappearance libmpdclient jsoncpp archlabs-screenlock archlabs-oblogout"
|
||||
elif [[ $INSTALL_WMS =~ (xfce4) ]]; then
|
||||
WM_PACKAGES+=" archlabs-oblogout archlabs-screenlock archlabs-paranoid"
|
||||
fi
|
||||
|
||||
# choose how to log in
|
||||
select_login_method || return 1
|
||||
|
||||
# choose which WM/DE to start at login
|
||||
if (( WM_NUM == 1 )); then
|
||||
LOGIN_WM="$INSTALL_WMS"
|
||||
if [[ $LOGIN_TYPE == 'xinit' ]]; then
|
||||
if [[ $WM_NUM -eq 1 ]]; then
|
||||
LOGIN_WM="$INSTALL_WMS"
|
||||
else
|
||||
LOGIN_WM="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
|
||||
--title " $_WMLogin " --menu "$_WMLoginBody" 0 0 0 $LOGIN_CHOICES)"
|
||||
[[ $? -eq 0 ]] || return 1
|
||||
fi
|
||||
|
||||
case $LOGIN_WM in
|
||||
i3-gaps) LOGIN_WM='i3' ;;
|
||||
xfce4) LOGIN_WM='startxfce4' ;;
|
||||
gnome) LOGIN_WM='gnome-session' ;;
|
||||
openbox) LOGIN_WM='openbox-session' ;;
|
||||
cinnamon) LOGIN_WM='cinnamon-session' ;;
|
||||
esac
|
||||
|
||||
# autologin
|
||||
yesno "$_WMLogin" "$_AutoLoginBody\n" && AUTOLOGIN=true || AUTOLOGIN=false
|
||||
else
|
||||
LOGIN_WM="$(dialog --cr-wrap --stdout --no-cancel --backtitle "$BT" \
|
||||
--title " $_WMLogin " --menu "$_WMLoginBody" 0 0 0 $LOGIN_CHOICES)"
|
||||
[[ $? -eq 0 ]] || return 1
|
||||
AUTOLOGIN=false
|
||||
fi
|
||||
|
||||
# choose how to log in
|
||||
choose_dm || return 1
|
||||
|
||||
# add all the packages to the main package list
|
||||
EXTRA_PACKAGES="$WM_PACKAGES"
|
||||
|
||||
# autologin
|
||||
yesno "$_WMLogin" "$_AutoLoginBody\n" && AUTOLOGIN=true || AUTOLOGIN=false
|
||||
case $LOGIN_WM in
|
||||
i3-gaps) LOGIN_WM='i3' ;;
|
||||
xfce4) LOGIN_WM='startxfce4' ;;
|
||||
gnome) LOGIN_WM='gnome-session' ;;
|
||||
openbox) LOGIN_WM='openbox-session' ;;
|
||||
cinnamon) LOGIN_WM='cinnamon-session' ;;
|
||||
esac
|
||||
# add packages to the main package list
|
||||
PACKAGES="$WM_PACKAGES"
|
||||
return 0
|
||||
}
|
||||
|
||||
packages() {
|
||||
select_login_method() {
|
||||
LOGIN_TYPE="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_WMLogin " --menu "$_LoginTypeBody" 0 0 0 \
|
||||
"xinit" "Console login without a display manager" \
|
||||
"lightdm" "Lightweight display manager with the gtk greeter")"
|
||||
[[ $? -eq 0 ]] || return 1
|
||||
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
|
||||
WM_PACKAGES+=" lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings accountsservice"
|
||||
EDIT_FILES[11]="/etc/lightdm/lightdm.conf /etc/lightdm/lightdm-gtk-greeter.conf"
|
||||
else
|
||||
EDIT_FILES[11]="/home/$NEWUSER/.xinitrc /home/$NEWUSER/.zprofile /home/$NEWUSER/.xprofile"
|
||||
fi
|
||||
}
|
||||
|
||||
select_extra_packages() {
|
||||
local pkgs
|
||||
pkgs="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_ExtraPackages " --checklist "$_ExtraPackagesBody\n" 0 0 30 \
|
||||
@ -440,15 +389,18 @@ packages() {
|
||||
([[ $INSTALL_WMS =~ dwm ]] && ! [[ $pkgs =~ ttf-hack ]]) && pkgs+=" ttf-hack"
|
||||
([[ $pkgs =~ (qutebrowser|qbittorrent|kdenlive|vlc) ]] && ! [[ $pkgs =~ qt5ct ]]) && pkgs+=" qt5ct qt5-styleplugins"
|
||||
|
||||
EXTRA_PACKAGES+=" $pkgs"
|
||||
PACKAGES+=" $pkgs" # add chosen packages to the main package list
|
||||
PACKAGES="${PACKAGES/^ /}" # remove leading spaces from the package string
|
||||
return 0
|
||||
}
|
||||
|
||||
mirrors() {
|
||||
select_mirrorlist_command() {
|
||||
local key="5f29642060ab983b31fdf4c2935d8c56"
|
||||
|
||||
if hash reflector >/dev/null 2>&1; then
|
||||
MIRROR_CMD="reflector --score 100 -l 50 -f 10 --sort rate --verbose"
|
||||
yesno "$_MirrorTitle" "$_MirrorSetup" "Automatic" "Custom" && return 0
|
||||
|
||||
local ip="$(json 'ip' "check&?access_key=${key}&fields=ip")"
|
||||
local c="$(json 'country_name' "${ip}?access_key=${key}&fields=country_name")"
|
||||
MIRROR_CMD="reflector --country $c --score 80 --latest 40 --fastest 10 --sort rate --verbose"
|
||||
@ -483,42 +435,57 @@ mirrors() {
|
||||
return 0
|
||||
}
|
||||
|
||||
display() {
|
||||
local cmd mnt
|
||||
display_system_settings() {
|
||||
local cmd mnt pkgs
|
||||
cmd="${BCMDS[$BOOTLDR]}"
|
||||
mnt="${BMNTS[$SYS-$BOOTLDR]}"
|
||||
msgbox "$_PrepTitle" "\nConfiguration values for the current install\n\n
|
||||
Root: ${ROOT_PART:-None}
|
||||
Boot: ${BOOT_PART:-None}
|
||||
Swap: ${SWAP:-None}
|
||||
msgbox "$_PrepTitle" "\n\n---------- PARTITION CONFIGURATION ------------
|
||||
|
||||
Extra: ${EXTRA_MNTS:-None}
|
||||
Hooks: ${MKINIT_HOOKS:-None}
|
||||
Root: ${ROOT_PART:-None}
|
||||
Boot: ${BOOT_PART:-None}
|
||||
|
||||
LVM: ${LVM:-None}
|
||||
LUKS: ${LUKS:-None}
|
||||
Swap: ${SWAP_PART:-None}
|
||||
Size: ${SWAP_SIZE:-None}
|
||||
|
||||
Bootloader: ${BOOTLDR:-None}
|
||||
Boot Mount: ${mnt:-None}
|
||||
Boot Command: ${cmd:-None}
|
||||
Extra: ${EXTRA_MNTS:-None}
|
||||
Hooks: ${MKINIT_HOOKS:-None}
|
||||
|
||||
User: ${NEWUSER:-None}
|
||||
Hostname: ${HOSTNAME:-None}
|
||||
Locale: ${LOCALE:-None}
|
||||
Keymap: ${KEYMAP:-None}
|
||||
Timezone: ${ZONE:-None}/${SUBZONE:-None}
|
||||
LVM: ${LVM:-None}
|
||||
LUKS: ${LUKS:-None}
|
||||
|
||||
Autologin: ${AUTOLOGIN:-None}
|
||||
Login: ${LOGIN_WM:-None}
|
||||
Login Type: ${LOGIN_TYPE:-None}
|
||||
|
||||
Sessions: ${INSTALL_WMS:-None}
|
||||
Kernel: ${KERNEL:-None}
|
||||
Mirrors: ${MIRROR_CMD:-None}
|
||||
Packages: ${EXTRA_PACKAGES:-None}\n"
|
||||
---------- BOOTLOADER CONFIGURATION -----------
|
||||
|
||||
Loader: ${BOOTLDR:-None}
|
||||
Mount: ${mnt:-None}
|
||||
Command: ${cmd:-None}
|
||||
|
||||
|
||||
------------ SYSTEM CONFIGURATION -------------
|
||||
|
||||
User: ${NEWUSER:-None}
|
||||
Locale: ${LOCALE:-None}
|
||||
Keymap: ${KEYMAP:-None}
|
||||
Hostname: ${HOSTNAME:-None}
|
||||
Timezone: ${ZONE:-None}/${SUBZONE:-None}
|
||||
|
||||
|
||||
------------ LOGIN CONFIGURATION --------------
|
||||
|
||||
Session: ${LOGIN_WM:-None}
|
||||
Autologin: ${AUTOLOGIN:-None}
|
||||
Management: ${LOGIN_TYPE:-None}
|
||||
|
||||
|
||||
------------ PACKAGES AND MIRRORS -------------
|
||||
|
||||
Kernel: ${KERNEL:-None}
|
||||
Sessions: ${INSTALL_WMS:-None}
|
||||
Mirrors: ${MIRROR_CMD:-None}
|
||||
Packages: $(printq "${PACKAGES:-None}")\n"
|
||||
}
|
||||
|
||||
configure() {
|
||||
configure_system_settings() {
|
||||
tput cnorm
|
||||
HOSTNAME="$(getinput "$_ConfHost" "$_HostNameBody" "${DIST,,}")"
|
||||
[[ $? != 0 || ! $HOSTNAME ]] && return 1
|
||||
@ -528,21 +495,21 @@ configure() {
|
||||
--title " $_ConfLocale " --menu "$_LocaleBody" 25 70 20 $LOCALES)"
|
||||
[[ $? != 0 || ! $LOCALE ]] && return 1
|
||||
|
||||
timezone || return 1
|
||||
mirrors || return 1
|
||||
user || return 1
|
||||
sessions || return 1
|
||||
select_timezone || return 1
|
||||
select_mirrorlist_command || return 1
|
||||
user_creation || return 1
|
||||
select_wm_or_de || return 1
|
||||
|
||||
tput civis
|
||||
KERNEL="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_KernelTitle " --menu "$_KernelBody" 0 0 0 $KERNELS)"
|
||||
--title " $_KernelTitle " --menu "$_KernelBody" 0 0 0 'linux' '-' 'linux-lts' '-')"
|
||||
[[ $? != 0 || ! $KERNEL ]] && return 1
|
||||
packages || return 1
|
||||
select_extra_packages || return 1
|
||||
CONFIG_DONE=true
|
||||
return 0
|
||||
}
|
||||
|
||||
configs() {
|
||||
edit_system_configs() {
|
||||
if [[ $CURRENT_MENU != "edit" ]]; then
|
||||
SELECTED=1; CURRENT_MENU="edit"
|
||||
elif (( SELECTED < 11 )); then
|
||||
@ -551,19 +518,19 @@ configs() {
|
||||
|
||||
tput civis
|
||||
local exitstr="Exit"
|
||||
[[ $DEBUG != true ]] && exitstr+=" & Reboot"
|
||||
[[ $DEBUG == true ]] && exitstr+=" & Reboot" || exitstr+=" & Reboot"
|
||||
|
||||
SELECTED=$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_EditTitle " --default-item $SELECTED --menu "$_EditBody" 0 0 0 \
|
||||
"1" "$exitstr" "2" "Keyboard" "3" "Locale" "4" "Hostname" "5" "Sudoers" \
|
||||
"6" "Mkinitcpio.conf" "7" "Fstab" "8" "Crypttab" "9" "${BOOTLDR^}" "10" "Pacman.conf" \
|
||||
"11" "${LOGIN_TYPE^}")
|
||||
"1" "$exitstr" "2" "Keyboard" "3" "Locale" "4" "Hostname" \
|
||||
"5" "Sudoers" "6" "Mkinitcpio.conf" "7" "Fstab" "8" "Crypttab" \
|
||||
"9" "${BOOTLDR^}" "10" "Pacman.conf" "11" "${LOGIN_TYPE^}")
|
||||
|
||||
if [[ ! $SELECTED || $SELECTED -eq 1 ]]; then
|
||||
[[ $DEBUG == true ]] && die 0 || die 'reboot'
|
||||
[[ $DEBUG == true ]] && { more /tmp/debug-log; die 0; } || die 'systemctl -i reboot'
|
||||
else
|
||||
local existing_files=""
|
||||
for f in $(echo "${FILES[$SELECTED]}"); do
|
||||
for f in $(echo "${EDIT_FILES[$SELECTED]}"); do
|
||||
[[ -e ${MNT}$f ]] && existing_files+=" ${MNT}$f"
|
||||
done
|
||||
if [[ ! $existing_files ]]; then
|
||||
@ -582,7 +549,7 @@ configs() {
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
configs
|
||||
edit_system_configs
|
||||
}
|
||||
|
||||
main() {
|
||||
@ -615,17 +582,14 @@ main() {
|
||||
2) partition || SELECTED=1 ;;
|
||||
3) luks_menu || SELECTED=2 ;;
|
||||
4) lvm_menu || SELECTED=3 ;;
|
||||
5) mountp || SELECTED=4 ;;
|
||||
6) configure || SELECTED=5 ;;
|
||||
7) display ;;
|
||||
5) mount_install_partitions || SELECTED=4 ;;
|
||||
6) configure_system_settings || SELECTED=5 ;;
|
||||
7) display_system_settings ;;
|
||||
8) install ;;
|
||||
*) yesno "$_CloseInst" "$_CloseInstBody" "Exit" "Back" && die 0
|
||||
esac
|
||||
}
|
||||
|
||||
# must be done first
|
||||
init
|
||||
|
||||
# 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; }
|
||||
@ -640,8 +604,8 @@ esac done
|
||||
|
||||
# initial choices/prep
|
||||
devices
|
||||
language
|
||||
keymap
|
||||
select_language
|
||||
select_keymap
|
||||
checks
|
||||
sysid
|
||||
|
||||
|
@ -8,6 +8,35 @@
|
||||
|
||||
# set -n
|
||||
|
||||
declare -gA BCMDS=(
|
||||
[syslinux]="syslinux-install_update -iam"
|
||||
[grub]="grub-install --recheck --force"
|
||||
[systemd-boot]="bootctl --path=/boot install"
|
||||
)
|
||||
|
||||
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]}"
|
||||
[UEFI]="systemd-boot ${BMNTS[UEFI-systemd-boot]} grub ${BMNTS[UEFI-grub]} syslinux ${BMNTS[UEFI-syslinux]}"
|
||||
)
|
||||
|
||||
declare -gA EDIT_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"
|
||||
[6]="/etc/mkinitcpio.conf"
|
||||
[7]="/etc/fstab"
|
||||
[8]="/etc/crypttab"
|
||||
[9]="/etc/default/grub"
|
||||
[10]="/etc/pacman.conf"
|
||||
[11]="" # login files, left empty, don't know the username yet for /home/USER/FILES
|
||||
)
|
||||
|
||||
prep_for_grub() {
|
||||
local cfg="$MNT/etc/default/grub"
|
||||
sed -i "s/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"${DIST}\"/g;
|
||||
|
@ -8,6 +8,9 @@
|
||||
|
||||
# set -n
|
||||
|
||||
readonly RUN="/run/archiso/bootmnt/arch/boot"
|
||||
readonly VM="$(dmesg | grep -i "hypervisor")"
|
||||
|
||||
install() {
|
||||
# function calls prefixed with 'oneshot' will only ever be run once
|
||||
# otherwise the main function can be called repeatedly
|
||||
@ -27,7 +30,7 @@ install() {
|
||||
# MUST be before bootloader and mkinitcpio
|
||||
oneshot package_operations
|
||||
|
||||
# set up user login
|
||||
# set up user login.. MUST be done after package operation
|
||||
oneshot login_manager
|
||||
|
||||
# mkinitcpio and bootloader install should only be done after installing the packages
|
||||
@ -42,7 +45,7 @@ install() {
|
||||
oneshot create_user
|
||||
|
||||
# drop off the user at the config editing menu
|
||||
configs
|
||||
edit_system_configs
|
||||
}
|
||||
|
||||
install_base() {
|
||||
@ -170,17 +173,17 @@ login_manager() {
|
||||
active-monitor=0
|
||||
default-user-image=/usr/share/icons/ArchLabs-Dark/64x64/places/distributor-logo-archlabs.png
|
||||
background=/usr/share/backgrounds/archlabs/archlabs.jpg
|
||||
theme-name=ArchLabs-dARK
|
||||
theme-name=Adwaita-Dark
|
||||
icon-theme-name=Adwaita
|
||||
font-name=DejaVu Sans Mono 11
|
||||
position=30%,end 50%,end
|
||||
EOF
|
||||
if [[ $AUTOLOGIN == true ]]; then
|
||||
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
|
||||
fi
|
||||
# if [[ $AUTOLOGIN == true ]]; then
|
||||
# chrun "groupadd -r nopasswdlogin && usermod -aG nopasswdlogin $LIVE"
|
||||
# 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
|
||||
# fi
|
||||
else # xinit login
|
||||
sed -i "s/openbox-session/${LOGIN_WM}/g" $MNT/home/$LIVE/.xinitrc
|
||||
if grep -q '#exec' $MNT/home/$LIVE/.zprofile; then
|
||||
@ -231,7 +234,7 @@ mirrorlist_sort() {
|
||||
}
|
||||
|
||||
package_operations() {
|
||||
local inpkg="$EXTRA_PACKAGES" # add the packages chosen during setup
|
||||
local inpkg="$PACKAGES" # add the packages chosen during setup
|
||||
local rmpkg="archlabs-installer" # always remove the installer
|
||||
|
||||
# the LTS kernel uses different packages
|
||||
@ -244,7 +247,6 @@ package_operations() {
|
||||
# if the system is not a VM then remove the guest utils
|
||||
[[ $VM ]] || rmpkg+=" virtualbox-guest-modules-arch virtualbox-guest-utils"
|
||||
fi
|
||||
[[ $UCODE == 'amd-ucode.img' ]] && inpkg+=" amd-ucode"
|
||||
|
||||
# for only gnome or cinnamon we don't need the xfce provided stuff
|
||||
[[ $INSTALL_WMS =~ (gnome|cinnamon) ]] && rmpkg+=" $(pacman -Qssq 'xfce4*' 2>/dev/null)"
|
||||
@ -261,12 +263,12 @@ package_operations() {
|
||||
|
||||
# iputils, base-devel, and git are all needed and should always be installed separately
|
||||
chrun "pacman -Syyu --noconfirm"
|
||||
chrun "pacman -S iputils git --noconfirm; pacman -S base-devel --needed --noconfirm"
|
||||
chrun "pacman -S iputils --noconfirm; pacman -S base-devel git --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
|
||||
if [[ $inpkg =~ neovim ]]; then
|
||||
mkdir -p $MNT/home/$LIVE/.config/nvim
|
||||
cp -f $MNT/home/$LIVE/.vimrc $MNT/home/$LIVE/.config/nvim/init.vim
|
||||
cp -rf $MNT/home/$LIVE/.vim/colors $MNT/home/$LIVE/.config/nvim/colors
|
||||
|
@ -18,7 +18,7 @@ declare -g LUKS_NAME="cryptroot"
|
||||
luks_open() {
|
||||
LUKS_PART=""
|
||||
modprobe -a dm-mod dm_crypt
|
||||
unmountp
|
||||
unmount_install_partitions
|
||||
find_partitions 'part|crypt|lvm' || return 1
|
||||
tput civis
|
||||
|
||||
@ -88,7 +88,7 @@ luks_pass() {
|
||||
luks_setup() {
|
||||
LUKS_PART=""
|
||||
modprobe -a dm-mod dm_crypt
|
||||
unmountp
|
||||
unmount_install_partitions
|
||||
|
||||
if [[ ! $ROOT_PART || $LVM ]]; then
|
||||
find_partitions 'part|lvm' || return 1
|
||||
|
@ -202,7 +202,7 @@ lvm_create() {
|
||||
VOLUME_GROUP=""
|
||||
GROUP_PARTS=""
|
||||
VOL_GROUP_MB=0
|
||||
unmountp
|
||||
unmount_install_partitions
|
||||
|
||||
if [[ $LUKS && $LUKS_NAME ]]; then
|
||||
GROUP_PARTS="/dev/mapper/$LUKS_NAME"
|
||||
|
351
src/lib/mount.sh
351
src/lib/mount.sh
@ -8,296 +8,15 @@
|
||||
|
||||
# set -n
|
||||
|
||||
format() {
|
||||
infobox "$_FSTitle" "\nFormatting: $1\n\nCommand: ${FS_CMDS[$2]}\n" 0
|
||||
${FS_CMDS[$2]} $1 >/dev/null 2>$ERR
|
||||
echeck "${FS_CMDS[$2]} $1"
|
||||
}
|
||||
readonly SYS_MEM="$(awk '/MemTotal/ {print int($2 / 1024)"M"}' /proc/meminfo)"
|
||||
readonly SALT="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)"
|
||||
readonly LOCALES="$(awk '/\.UTF-8/ {gsub(/# .*|#/, ""); if($1) print $1 " -"}' /etc/locale.gen)"
|
||||
readonly CMAPS="$(find /usr/share/kbd/keymaps -name '*.map.gz' | awk '{gsub(/\.map\.gz|.*\//, ""); print $1 " -"}')"
|
||||
|
||||
partition() {
|
||||
local device
|
||||
if [[ $# -eq 0 ]]; then
|
||||
select_device 'root' || return 1
|
||||
device="$DEVICE"
|
||||
else
|
||||
device="$1"
|
||||
fi
|
||||
|
||||
tput civis
|
||||
local choice
|
||||
choice="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PartTitle " \
|
||||
--menu "$_PartBody" 0 0 0 "$_PartShowTree" "-" "$_PartAuto" "-" \
|
||||
$( ([[ $DISPLAY ]] && hash gparted >/dev/null 2>&1) && printf "gparted -") \
|
||||
"cfdisk" "-" "parted" "-" "$_PartWipe" "-")"
|
||||
[[ $? != 0 || $choice == "" ]] && return 1
|
||||
|
||||
tput civis
|
||||
if [[ $choice != "$_PartWipe" && $choice != "$_PartAuto" && $choice != "$_PartShowTree" ]]; then
|
||||
clear; tput cnorm; $choice $device
|
||||
elif [[ $choice == "$_PartShowTree" ]]; then
|
||||
msgbox "$_PrepShowDev" "\n$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT "$device")\n"
|
||||
partition $device
|
||||
elif [[ $choice == "$_PartWipe" ]]; then
|
||||
yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2" && wipe -Ifrev $device
|
||||
partition $device
|
||||
else
|
||||
# if auto_partition fails we need to re-initialize the variables, just to be sure
|
||||
auto_partition $device || { init; return 1; }
|
||||
fi
|
||||
}
|
||||
|
||||
decr_count() {
|
||||
# remove a partition from the dialog list and decrement the number partitions left
|
||||
(( $# == 1 )) || return 1
|
||||
|
||||
local p="$1"
|
||||
PARTS="$(sed "s~${p} [0-9]*[G-M]~~; s~${p} [0-9]*\.[0-9]*[G-M]~~" <<< "$PARTS")"
|
||||
(( COUNT > 0 )) && (( COUNT-- ))
|
||||
return 0
|
||||
}
|
||||
|
||||
enable_swap() {
|
||||
if [[ $1 == "$MNT/swapfile" ]]; then
|
||||
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
|
||||
echeck "mkswap $1"
|
||||
swapon $1 >/dev/null 2>$ERR
|
||||
echeck "swapon $1"
|
||||
return 0
|
||||
}
|
||||
|
||||
device_tree() {
|
||||
tput civis
|
||||
local msg
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
msg="$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk "!/$IGNORE_DEV/"' && /disk|part|lvm|crypt|NAME/ {print $0}')"
|
||||
else
|
||||
msg="$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk '/disk|part|lvm|crypt|NAME/ {print $0}')"
|
||||
fi
|
||||
msgbox "$_PrepShowDev" "$msg"
|
||||
}
|
||||
|
||||
select_device() {
|
||||
local dev
|
||||
local msg
|
||||
[[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || unmountp
|
||||
|
||||
if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then
|
||||
DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")"
|
||||
msg="\nOnly one device available$([[ $1 == 'boot' ]] && printf " for grub bootloader"):"
|
||||
infobox "$_DevSelTitle" "$msg $DEVICE\n" 1
|
||||
elif (( DEV_COUNT > 1 )); then
|
||||
tput civis
|
||||
DEVICE="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_DevSelTitle " \
|
||||
--menu "${msg}$_DevSelBody" 0 0 0 $SYS_DEVS)"
|
||||
[[ $? != 0 || $DEVICE == "" ]] && return 1
|
||||
else
|
||||
msg="\nNo available devices for installation to use$([[ $1 == 'boot' ]] && printf " for grub bootloader")."
|
||||
msgbox "$_ErrTitle" "$msg\n$_Exit"
|
||||
die 1
|
||||
fi
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
confirm_mount() {
|
||||
local part="$1"
|
||||
local mount="$2"
|
||||
local msg="Partition: $part\n"
|
||||
[[ $mount == "$MNT" ]] && msg+="Mountpoint: / (root)" || msg+="Mountpoint: ${mount#$MNT}"
|
||||
|
||||
if [[ $(mount) =~ "$mount" ]]; then
|
||||
infobox "$_MntTitle" "$_MntSucc\n$msg\n" 1 && decr_count "$part"
|
||||
else
|
||||
infobox "$_MntTitle" "$_MntFail\n$msg\n" 1 && return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
check_cryptlvm() {
|
||||
local dev=""
|
||||
local part="$1"
|
||||
local devs="$(lsblk -lno NAME,FSTYPE,TYPE)"
|
||||
|
||||
# Identify if $part is "crypt" (LUKS on LVM, or LUKS alone)
|
||||
if [[ $(lsblk -lno TYPE "$part") =~ 'crypt' ]]; then
|
||||
LUKS=' encrypted'
|
||||
LUKS_NAME="${part#/dev/mapper/}"
|
||||
|
||||
for dev in $(awk '/lvm/ && /crypto_LUKS/ {print "/dev/mapper/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$LUKS_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_DEV="$LUKS_DEV cryptdevice=$dev:$LUKS_NAME"
|
||||
LVM=' logical volume'
|
||||
break
|
||||
fi
|
||||
done
|
||||
for dev in $(awk '/part/ && /crypto_LUKS/ {print "/dev/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$LUKS_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_UUID="$(lsblk -lno UUID,TYPE,FSTYPE "$dev" | awk '/part/ && /crypto_LUKS/ {print $1}')"
|
||||
LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
elif [[ $(lsblk -lno TYPE "$part") =~ 'lvm' ]]; then
|
||||
LVM=' logical volume'
|
||||
VOLUME_NAME="${part#/dev/mapper/}"
|
||||
|
||||
for dev in $(awk '/crypt/ && /lvm2_member/ {print "/dev/mapper/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$VOLUME_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_NAME="$(sed 's~/dev/mapper/~~g' <<< "$dev")"
|
||||
break
|
||||
fi
|
||||
done
|
||||
for dev in $(awk '/part/ && /crypto_LUKS/ {print "/dev/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$LUKS_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_UUID="$(lsblk -lno UUID,TYPE,FSTYPE "$dev" | awk '/part/ && /crypto_LUKS/ {print $1}')"
|
||||
LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
|
||||
LUKS=' encrypted'
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
auto_partition() {
|
||||
local device="$1"
|
||||
local size=$(lsblk -lno SIZE $device | awk 'NR == 1 {
|
||||
if ($1 ~ "G") {
|
||||
sub(/G/, ""); print ($1 * 1000 - 512) / 1000"G"
|
||||
} else {
|
||||
sub(/M/, ""); print ($1 - 512)"M"
|
||||
}}')
|
||||
|
||||
# confirm or bail
|
||||
yesno "$_PrepParts" "$_PartBody1 $device $_PartBody2 ($size)$_PartBody3" || return 0
|
||||
|
||||
local newtable format
|
||||
if [[ $SYS == BIOS ]]; then
|
||||
newtable="msdos"; format="ext4"
|
||||
else
|
||||
newtable="gpt"; format="fat32"
|
||||
fi
|
||||
|
||||
infobox "$_PrepParts" "\nRemoving existing partitions on $device and setting partition table to $newtable\n" 0
|
||||
|
||||
swapoff -a # in case the device was previously used for swap
|
||||
local dev_info="$(parted -s $device print)"
|
||||
|
||||
# walk the partitions on the device in reverse order and delete them
|
||||
for i in $(awk '/^ [1-9][0-9]?/ {print $1}' <<< "$dev_info" | sort -r); do
|
||||
parted -s $device rm $i >/dev/null 2>&1
|
||||
done
|
||||
|
||||
if [[ $(awk '/Table:/ {print $3}' <<< "$dev_info") != "$newtable" ]]; then
|
||||
parted -s $device mklabel $newtable >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
infobox "$_PrepParts" "\nCreating a 512M $format boot partition.\n" 0
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
parted -s $device mkpart primary $format 1MiB 513MiB >/dev/null 2>&1
|
||||
else
|
||||
parted -s $device mkpart ESP $format 1MiB 513MiB >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
sleep 0.1
|
||||
BOOT_DEVICE="$device"
|
||||
BOOT_PART=$(lsblk -lno NAME,TYPE $device | awk 'NR == 2 {print "/dev/"$1}')
|
||||
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
mkfs.ext4 -q $BOOT_PART >/dev/null 2>&1
|
||||
else
|
||||
mkfs.vfat -F32 $BOOT_PART >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
infobox "$_PrepParts" "\nCreating a $size ext4 root partition.\n" 0
|
||||
parted -s $device mkpart primary ext4 513MiB 100% >/dev/null 2>&1
|
||||
sleep 0.1
|
||||
ROOT_PART=$(lsblk -lno NAME,TYPE $device | awk 'NR == 3 {print "/dev/"$1}')
|
||||
mkfs.ext4 -q $ROOT_PART >/dev/null 2>&1
|
||||
|
||||
tput civis; sleep 0.5
|
||||
msgbox "$_PrepParts" "\nAuto partitioning complete.\n\n$(lsblk $device -o NAME,MODEL,TYPE,FSTYPE,SIZE)"
|
||||
}
|
||||
|
||||
mount_partition() {
|
||||
local part="$1"
|
||||
local mountp="${MNT}$2"
|
||||
local fs="$(lsblk -lno FSTYPE $part)"
|
||||
|
||||
mkdir -p "$mountp"
|
||||
|
||||
if [[ ${FS_OPTS[$fs]} != "" && $part != "$BOOT_PART" ]] && select_mount_opts "$part" "$fs"; then
|
||||
mount -o $MNT_OPTS $part "$mountp" 2>$ERR
|
||||
echeck "mount -o $MNT_OPTS $part $mountp"
|
||||
else
|
||||
mount $part "$mountp" 2>$ERR
|
||||
echeck "mount $part $mountp"
|
||||
fi
|
||||
|
||||
confirm_mount $part "$mountp" || return 1
|
||||
check_cryptlvm "$part"
|
||||
return 0
|
||||
}
|
||||
|
||||
find_partitions() {
|
||||
local str="$1"
|
||||
local err=''
|
||||
|
||||
# string of partitions as /TYPE/PART SIZE
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
PARTS="$(lsblk -lno TYPE,NAME,SIZE |
|
||||
awk "/$str/"' && !'"/$IGNORE_DEV/"' {sub(/^part/, "/dev/");
|
||||
sub(/^lvm|^crypt/, "/dev/mapper/"); print $1$2 " " $3}')"
|
||||
else
|
||||
PARTS="$(lsblk -lno TYPE,NAME,SIZE |
|
||||
awk "/$str/"' {sub(/^part/, "/dev/") sub(/^lvm|^crypt/, "/dev/mapper/")
|
||||
print $1$2 " " $3}')"
|
||||
fi
|
||||
|
||||
# number of partitions total
|
||||
COUNT=$(wc -l <<< "$PARTS")
|
||||
|
||||
# ensure we have enough partitions for the system and action type
|
||||
case $str in
|
||||
'part|lvm|crypt') [[ $COUNT -eq 0 || ($SYS == 'UEFI' && $COUNT -lt 2) ]] && err="$_PartErrBody" ;;
|
||||
'part|crypt') (( COUNT == 0 )) && err="$_LvmPartErrBody" ;;
|
||||
'part|lvm') (( COUNT < 2 )) && err="$_LuksPartErrBody" ;;
|
||||
esac
|
||||
|
||||
# if there aren't enough partitions show the error message
|
||||
if [[ $err ]]; then
|
||||
msgbox "$_ErrTitle" "$err"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_boot_device() {
|
||||
[[ $BOOT_PART = /dev/nvme* ]] && BOOT_DEVICE="${BOOT_PART%p[1-9]}" ||
|
||||
BOOT_DEVICE="${BOOT_PART%[1-9]}"
|
||||
BOOT_PART_NUM="${BOOT_PART: -1}"
|
||||
|
||||
parted -s $BOOT_DEVICE set $BOOT_PART_NUM boot on >/dev/null 2>&1
|
||||
if [[ $SYS == 'UEFI' ]]; then
|
||||
parted -s $BOOT_DEVICE set $BOOT_PART_NUM esp on >/dev/null 2>&1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
mountp() {
|
||||
mount_install_partitions() {
|
||||
# prepare partition list PARTS for dialog
|
||||
lvm_detect
|
||||
unmountp
|
||||
unmount_install_partitions
|
||||
find_partitions 'part|lvm|crypt' || return 1
|
||||
|
||||
# remove boot partition from dialog list if we auto partitioned one
|
||||
@ -305,31 +24,22 @@ mountp() {
|
||||
|
||||
select_root_partition || return 1
|
||||
|
||||
if [[ $BOOT_PART == "" ]]; then
|
||||
if [[ $SYS == "UEFI" ]]; then
|
||||
select_efi_partition || { BOOT_PART=""; return 1; }
|
||||
elif (( $COUNT > 0 )); then
|
||||
select_boot_partition || { BOOT_PART=""; return 1; }
|
||||
fi
|
||||
else
|
||||
if [[ $BOOT_PART ]]; then
|
||||
infobox "$_PrepMount" "\nUsing boot partition: $BOOT_PART\n" 1
|
||||
elif [[ $SYS == "UEFI" ]]; then
|
||||
select_efi_partition || { BOOT_PART=""; return 1; }
|
||||
elif (( $COUNT > 0 )); then
|
||||
select_boot_partition || { BOOT_PART=""; return 1; }
|
||||
fi
|
||||
|
||||
select_boot_setup || { BOOTLDR=""; return 1; }
|
||||
|
||||
if [[ $BOOT_PART != "" ]]; then
|
||||
infobox "$_PrepMount" "\nSetting up for the bootloader and mounting the boot partition.\n" 1
|
||||
setup_boot_device
|
||||
mount_partition "$BOOT_PART" "${BMNTS[$SYS-$BOOTLDR]}" || return 1
|
||||
SEPERATE_BOOT=true
|
||||
fi
|
||||
|
||||
select_swap || return 1
|
||||
select_extra_partitions || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
unmountp() {
|
||||
unmount_install_partitions() {
|
||||
swapoff -a
|
||||
for i in $(mount | awk "/${MNT//\//\\/}/"' {print $3}' | sort -r); do
|
||||
umount "$i" >/dev/null 2>&1
|
||||
@ -339,26 +49,27 @@ unmountp() {
|
||||
select_swap() {
|
||||
# Ask user to select partition or create swapfile
|
||||
tput civis
|
||||
SWAP="$(dialog --backtitle "$BT" --cr-wrap --stdout --title " $_SelSwpSetup " \
|
||||
SWAP_PART="$(dialog --backtitle "$BT" --cr-wrap --stdout --title " $_SelSwpSetup " \
|
||||
--menu "$_SelSwpBody" 0 0 0 "$_SelSwpNone" "-" "$_SelSwpFile" "$SYS_MEM" $PARTS)"
|
||||
[[ $? != 0 || $SWAP == "$_SelSwpNone" ]] && { SWAP=""; return 0; }
|
||||
[[ $? != 0 || $SWAP_PART == "$_SelSwpNone" ]] && { SWAP_PART=""; return 0; }
|
||||
|
||||
if [[ $SWAP == "$_SelSwpFile" ]]; then
|
||||
if [[ $SWAP_PART == "$_SelSwpFile" ]]; then
|
||||
tput cnorm
|
||||
SWAP_SIZE="$(getinput "$_SelSwpSetup" "$_SelSwpSize" "$SYS_MEM")"
|
||||
[[ $? != 0 || $SWAP_SIZE == "" ]] && { SWAP=""; return 0; }
|
||||
[[ $? != 0 || ! $SWAP_SIZE ]] && { SWAP_PART=""; SWAP_SIZE=""; return 0; }
|
||||
|
||||
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")"
|
||||
[[ $? != 0 || $SWAP_SIZE == "" ]] && { SWAP=""; break; return 0; }
|
||||
[[ $? != 0 || ! $SWAP_SIZE ]] && { SWAP_PART=""; SWAP_SIZE=""; break; return 0; }
|
||||
done
|
||||
|
||||
enable_swap "$MNT/swapfile"
|
||||
SWAP="/swapfile"
|
||||
SWAP_PART="/swapfile"
|
||||
else
|
||||
enable_swap "$SWAP"
|
||||
decr_count "$SWAP"
|
||||
enable_swap "$SWAP_PART"
|
||||
decr_count "$SWAP_PART"
|
||||
SWAP_SIZE="$(lsblk -lno SIZE $SWAP_PART)"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@ -407,12 +118,20 @@ select_boot_setup() {
|
||||
if [[ $SYS == 'UEFI' ]]; then
|
||||
local ttype="i386-efi"
|
||||
[[ $IS_64BIT == true ]] && ttype='x86_64-efi'
|
||||
BCMDS[grub]="${BCMDS[grub]} --target=$ttype --bootloader-id=$DIST"
|
||||
BCMDS[grub]+=" --target=$ttype --bootloader-id=$DIST"
|
||||
else
|
||||
BCMDS[grub]="${BCMDS[grub]} --target=i386-pc $BOOT_DEVICE"
|
||||
BCMDS[grub]+=" --target=i386-pc $BOOT_DEVICE"
|
||||
fi
|
||||
|
||||
BCMDS[grub]="${BCMDS[grub]} && grub-mkconfig -o /boot/grub/grub.cfg"
|
||||
BCMDS[grub]+=" && grub-mkconfig -o /boot/grub/grub.cfg"
|
||||
fi
|
||||
|
||||
if [[ $BOOT_PART != "" ]]; then
|
||||
infobox "$_PrepMount" "\nSetting up for the bootloader and mounting the boot partition.\n" 1
|
||||
setup_boot_device
|
||||
mount_partition "$BOOT_PART" "${BMNTS[$SYS-$BOOTLDR]}" ||
|
||||
{ src /usr/share/archlabs/installer/lib/boot.sh ; return 1; }
|
||||
SEPERATE_BOOT=true
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@ -446,9 +165,9 @@ select_filesystem() {
|
||||
|
||||
local fs
|
||||
fs="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_FSTitle: $part " \
|
||||
--menu "\nPartition Name: ${part}$([[ $cur_fs ]] &&
|
||||
--menu "\nSelect which filesystem you want to use for $part\n\nPartition Name: ${part}$([[ $cur_fs ]] &&
|
||||
printf "\nExisting Filesystem: %s" "$cur_fs")$_FSBody" 0 0 0 \
|
||||
$([[ $cur_fs != "" ]] && printf "%s -" "$_Skip") \
|
||||
$([[ $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]}" \
|
||||
@ -491,7 +210,7 @@ select_boot_partition() {
|
||||
BOOT_PART="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_PrepMount " --menu "$_SelBiosBody" 0 0 0 "$_Skip" "-" $PARTS)"
|
||||
|
||||
if [[ $BOOT_PART == "$_Skip" || $BOOT_PART == "" ]]; then
|
||||
if [[ $BOOT_PART == "$_Skip" || ! $BOOT_PART ]]; then
|
||||
BOOT_PART=""
|
||||
else
|
||||
if grep -q 'ext[34]' <<< "$(fsck -N "$BOOT_PART")"; then
|
||||
|
310
src/lib/part.sh
Normal file
310
src/lib/part.sh
Normal file
@ -0,0 +1,310 @@
|
||||
#!/usr/bin/bash
|
||||
|
||||
# vim:ft=sh:fdm=marker:fmr={,}
|
||||
|
||||
# archlabs installer library script file
|
||||
# this file is not meant to be run directly
|
||||
# sourcing this file in a non bash shell is not advised
|
||||
|
||||
# set -n
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]=""
|
||||
[ext4]="discard - off dealloc - 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"
|
||||
[xfs]="discard - off filestreams - off ikeep - off largeio - off noalign - off nobarrier - off norecovery - off noquota - off wsync - off"
|
||||
[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"
|
||||
)
|
||||
|
||||
format() {
|
||||
infobox "$_FSTitle" "\nFormatting: $1\n\nCommand: ${FS_CMDS[$2]}\n" 0
|
||||
${FS_CMDS[$2]} $1 >/dev/null 2>$ERR
|
||||
echeck "${FS_CMDS[$2]} $1"
|
||||
}
|
||||
|
||||
partition() {
|
||||
local device
|
||||
if [[ $# -eq 0 ]]; then
|
||||
select_device 'root' || return 1
|
||||
device="$DEVICE"
|
||||
else
|
||||
device="$1"
|
||||
fi
|
||||
|
||||
tput civis
|
||||
local choice
|
||||
choice="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_PartTitle " \
|
||||
--menu "$_PartBody" 0 0 0 "$_PartShowTree" "-" "$_PartAuto" "-" \
|
||||
$( ([[ $DISPLAY ]] && hash gparted >/dev/null 2>&1) && printf "gparted -") \
|
||||
"cfdisk" "-" "parted" "-" "$_PartWipe" "-")"
|
||||
[[ $? != 0 || $choice == "" ]] && return 1
|
||||
|
||||
tput civis
|
||||
if [[ $choice != "$_PartWipe" && $choice != "$_PartAuto" && $choice != "$_PartShowTree" ]]; then
|
||||
clear; tput cnorm; $choice $device
|
||||
elif [[ $choice == "$_PartShowTree" ]]; then
|
||||
msgbox "$_PrepShowDev" "\n$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT "$device")\n"
|
||||
partition $device
|
||||
elif [[ $choice == "$_PartWipe" ]]; then
|
||||
yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2" && wipe -Ifrev $device
|
||||
partition $device
|
||||
else
|
||||
# if auto_partition fails we need to empty the partition variables
|
||||
auto_partition $device || { ROOT_PART=""; BOOT_PART=""; BOOT_DEVICE=""; return 1; }
|
||||
fi
|
||||
}
|
||||
|
||||
decr_count() {
|
||||
# remove a partition from the dialog list and decrement the number partitions left
|
||||
(( $# == 1 )) || return 1
|
||||
|
||||
local p="$1"
|
||||
PARTS="$(sed "s~${p} [0-9]*[G-M]~~; s~${p} [0-9]*\.[0-9]*[G-M]~~" <<< "$PARTS")"
|
||||
(( COUNT > 0 )) && (( COUNT-- ))
|
||||
return 0
|
||||
}
|
||||
|
||||
enable_swap() {
|
||||
if [[ $1 == "$MNT/swapfile" && $SWAP_SIZE ]]; then
|
||||
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
|
||||
echeck "mkswap $1"
|
||||
swapon $1 >/dev/null 2>$ERR
|
||||
echeck "swapon $1"
|
||||
return 0
|
||||
}
|
||||
|
||||
device_tree() {
|
||||
tput civis
|
||||
local msg
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
msg="$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk "!/$IGNORE_DEV/"' && /disk|part|lvm|crypt|NAME/ {print $0}')"
|
||||
else
|
||||
msg="$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk '/disk|part|lvm|crypt|NAME/ {print $0}')"
|
||||
fi
|
||||
msgbox "$_PrepShowDev" "$msg"
|
||||
}
|
||||
|
||||
select_device() {
|
||||
local dev
|
||||
local msg
|
||||
[[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || unmount_install_partitions
|
||||
|
||||
if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then
|
||||
DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")"
|
||||
msg="\nOnly one device available$([[ $1 == 'boot' ]] && printf " for bootloader"):"
|
||||
infobox "$_DevSelTitle" "$msg $DEVICE\n" 1
|
||||
elif (( DEV_COUNT > 1 )); then
|
||||
tput civis
|
||||
DEVICE="$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_DevSelTitle " \
|
||||
--menu "${msg}$_DevSelBody" 0 0 0 $SYS_DEVS)"
|
||||
[[ $? != 0 || $DEVICE == "" ]] && return 1
|
||||
else
|
||||
msg="\nNo available devices to use$([[ $1 == 'boot' ]] && printf " for bootloader")."
|
||||
msgbox "$_ErrTitle" "$msg\n$_Exit"
|
||||
die 1
|
||||
fi
|
||||
|
||||
# if the device selected was for bootloader, set the BOOT_DEVICE
|
||||
[[ $1 == 'boot' ]] && BOOT_DEVICE="$DEVICE"
|
||||
return 0
|
||||
}
|
||||
|
||||
confirm_mount() {
|
||||
local part="$1"
|
||||
local mount="$2"
|
||||
local msg="Partition: $part\n"
|
||||
[[ $mount == "$MNT" ]] && msg+="Mountpoint: / (root)" || msg+="Mountpoint: ${mount#$MNT}"
|
||||
|
||||
if [[ $(mount) =~ "$mount" ]]; then
|
||||
infobox "$_MntTitle" "$_MntSucc\n$msg\n" 1 && decr_count "$part"
|
||||
else
|
||||
infobox "$_MntTitle" "$_MntFail\n$msg\n" 1 && return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
check_cryptlvm() {
|
||||
local dev=""
|
||||
local part="$1"
|
||||
local devs="$(lsblk -lno NAME,FSTYPE,TYPE)"
|
||||
|
||||
# Identify if $part is "crypt" (LUKS on LVM, or LUKS alone)
|
||||
if [[ $(lsblk -lno TYPE "$part") =~ 'crypt' ]]; then
|
||||
LUKS=' encrypted'
|
||||
LUKS_NAME="${part#/dev/mapper/}"
|
||||
|
||||
for dev in $(awk '/lvm/ && /crypto_LUKS/ {print "/dev/mapper/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$LUKS_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_DEV="$LUKS_DEV cryptdevice=$dev:$LUKS_NAME"
|
||||
LVM=' logical volume'
|
||||
break
|
||||
fi
|
||||
done
|
||||
for dev in $(awk '/part/ && /crypto_LUKS/ {print "/dev/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$LUKS_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_UUID="$(lsblk -lno UUID,TYPE,FSTYPE "$dev" | awk '/part/ && /crypto_LUKS/ {print $1}')"
|
||||
LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
elif [[ $(lsblk -lno TYPE "$part") =~ 'lvm' ]]; then
|
||||
LVM=' logical volume'
|
||||
VOLUME_NAME="${part#/dev/mapper/}"
|
||||
|
||||
for dev in $(awk '/crypt/ && /lvm2_member/ {print "/dev/mapper/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$VOLUME_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_NAME="$(sed 's~/dev/mapper/~~g' <<< "$dev")"
|
||||
break
|
||||
fi
|
||||
done
|
||||
for dev in $(awk '/part/ && /crypto_LUKS/ {print "/dev/"$1}' <<< "$devs" | uniq); do
|
||||
if grep -q "$LUKS_NAME" <<< "$(lsblk -lno NAME "$dev")"; then
|
||||
LUKS_UUID="$(lsblk -lno UUID,TYPE,FSTYPE "$dev" | awk '/part/ && /crypto_LUKS/ {print $1}')"
|
||||
LUKS_DEV="$LUKS_DEV cryptdevice=UUID=$LUKS_UUID:$LUKS_NAME"
|
||||
LUKS=' encrypted'
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
auto_partition() {
|
||||
local device="$1"
|
||||
local size=$(lsblk -lno SIZE $device | awk 'NR == 1 {
|
||||
if ($1 ~ "G") {
|
||||
sub(/G/, ""); print ($1 * 1000 - 512) / 1000"G"
|
||||
} else {
|
||||
sub(/M/, ""); print ($1 - 512)"M"
|
||||
}}')
|
||||
|
||||
local msg="$_PartBody2"
|
||||
local newtable="gpt"; local format="fat32";
|
||||
if [[ $SYS == 'BIOS' ]]; then
|
||||
msg="$(sed 's|vfat/fat32|ext4|' <<< "$msg")"
|
||||
newtable="msdos"
|
||||
format="ext4"
|
||||
fi
|
||||
|
||||
# confirm or bail
|
||||
yesno "$_PrepParts" "$_PartBody1 $device $msg ($size)$_PartBody3" || return 0
|
||||
infobox "$_PrepParts" "\nRemoving existing partitions on $device and setting partition table to $newtable\n" 1
|
||||
|
||||
swapoff -a # in case the device was previously used for swap
|
||||
|
||||
local dev_info="$(parted -s $device print)"
|
||||
|
||||
# walk the partitions on the device in reverse order and delete them
|
||||
for i in $(awk '/^ [1-9][0-9]?/ {print $1}' <<< "$dev_info" | sort -r); do
|
||||
parted -s $device rm $i >/dev/null 2>&1
|
||||
done
|
||||
|
||||
if [[ $(awk '/Table:/ {print $3}' <<< "$dev_info") != "$newtable" ]]; then
|
||||
parted -s $device mklabel $newtable >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
infobox "$_PrepParts" "\nCreating a 512M $format boot partition.\n" 1
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
parted -s $device mkpart primary $format 1MiB 513MiB >/dev/null 2>&1
|
||||
else
|
||||
parted -s $device mkpart ESP $format 1MiB 513MiB >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
sleep 0.1
|
||||
BOOT_DEVICE="$device"
|
||||
BOOT_PART=$(lsblk -lno NAME,TYPE $device | awk 'NR == 2 {print "/dev/"$1}')
|
||||
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
mkfs.ext4 -q $BOOT_PART >/dev/null 2>&1
|
||||
else
|
||||
mkfs.vfat -F32 $BOOT_PART >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
infobox "$_PrepParts" "\nCreating a $size ext4 root partition.\n" 0
|
||||
parted -s $device mkpart primary ext4 513MiB 100% >/dev/null 2>&1
|
||||
sleep 0.1
|
||||
ROOT_PART=$(lsblk -lno NAME,TYPE $device | awk 'NR == 3 {print "/dev/"$1}')
|
||||
mkfs.ext4 -q $ROOT_PART >/dev/null 2>&1
|
||||
|
||||
tput civis; sleep 0.5
|
||||
msgbox "$_PrepParts" "\nAuto partitioning complete.\n\n$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE $device)"
|
||||
}
|
||||
|
||||
mount_partition() {
|
||||
local part="$1"
|
||||
local mountp="${MNT}$2"
|
||||
local fs="$(lsblk -lno FSTYPE $part)"
|
||||
|
||||
mkdir -p "$mountp"
|
||||
|
||||
if [[ ${FS_OPTS[$fs]} != "" && $part != "$BOOT_PART" ]] && select_mount_opts "$part" "$fs"; then
|
||||
mount -o $MNT_OPTS $part "$mountp" 2>$ERR
|
||||
echeck "mount -o $MNT_OPTS $part $mountp"
|
||||
else
|
||||
mount $part "$mountp" 2>$ERR
|
||||
echeck "mount $part $mountp"
|
||||
fi
|
||||
|
||||
confirm_mount $part "$mountp" || return 1
|
||||
check_cryptlvm "$part"
|
||||
return 0
|
||||
}
|
||||
|
||||
find_partitions() {
|
||||
local str="$1"
|
||||
local err=''
|
||||
|
||||
# string of partitions as /TYPE/PART SIZE
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
PARTS="$(lsblk -lno TYPE,NAME,SIZE |
|
||||
awk "/$str/"' && !'"/$IGNORE_DEV/"' {sub(/^part/, "/dev/");
|
||||
sub(/^lvm|^crypt/, "/dev/mapper/"); print $1$2 " " $3}')"
|
||||
else
|
||||
PARTS="$(lsblk -lno TYPE,NAME,SIZE |
|
||||
awk "/$str/"' {sub(/^part/, "/dev/") sub(/^lvm|^crypt/, "/dev/mapper/")
|
||||
print $1$2 " " $3}')"
|
||||
fi
|
||||
|
||||
# number of partitions total
|
||||
COUNT=$(wc -l <<< "$PARTS")
|
||||
|
||||
# ensure we have enough partitions for the system and action type
|
||||
case $str in
|
||||
'part|lvm|crypt') [[ $COUNT -eq 0 || ($SYS == 'UEFI' && $COUNT -lt 2) ]] && err="$_PartErrBody" ;;
|
||||
'part|crypt') (( COUNT == 0 )) && err="$_LvmPartErrBody" ;;
|
||||
'part|lvm') (( COUNT < 2 )) && err="$_LuksPartErrBody" ;;
|
||||
esac
|
||||
|
||||
# if there aren't enough partitions show the error message
|
||||
if [[ $err ]]; then
|
||||
msgbox "$_ErrTitle" "$err"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_boot_device() {
|
||||
[[ $BOOT_PART = /dev/nvme* ]] && BOOT_DEVICE="${BOOT_PART%p[1-9]}" ||
|
||||
BOOT_DEVICE="${BOOT_PART%[1-9]}"
|
||||
BOOT_PART_NUM="${BOOT_PART: -1}"
|
||||
|
||||
parted -s $BOOT_DEVICE set $BOOT_PART_NUM boot on >/dev/null 2>&1
|
||||
if [[ $SYS == 'UEFI' ]]; then
|
||||
parted -s $BOOT_DEVICE set $BOOT_PART_NUM esp on >/dev/null 2>&1
|
||||
fi
|
||||
return 0
|
||||
}
|
@ -28,7 +28,8 @@ ssd() {
|
||||
}
|
||||
|
||||
die() {
|
||||
tput cnorm; unmountp; sleep 1
|
||||
tput cnorm
|
||||
unmount_install_partitions
|
||||
pgrep -f "$TERM_CMD -e tail" && pkill -f "$TERM_CMD -e tail"
|
||||
[[ $1 =~ [0-9] ]] && exit $1 || $1
|
||||
}
|
||||
@ -65,6 +66,22 @@ infobox() {
|
||||
sleep ${sec:-2}
|
||||
}
|
||||
|
||||
printq() {
|
||||
local str="$@"
|
||||
if [[ ${#str} -gt $(( ${COLUMNS:-$(tput cols)} / 2 )) ]]; then
|
||||
q=$(awk '{print int(NF / 4)}' <<< "$str")
|
||||
str="$(awk '{
|
||||
pkgs1=pkgs2=pkgs3=pkgs4=""
|
||||
for (i=1;i<'"$q"';i++) { pkgs1=pkgs1" "$i }
|
||||
for (i='"$q"';i<'"$((q * 2))"';i++) { pkgs2=pkgs2" "$i }
|
||||
for (i='"$((q * 2))"';i<'"$((q * 3))"';i++) { pkgs3=pkgs3" "$i }
|
||||
for (i='"$((q * 3))"';i<NF;i++) { pkgs4=pkgs4" "$i }
|
||||
printf "%s\n %s\n %s\n %s", pkgs1, pkgs2, pkgs3, pkgs4
|
||||
}' <<< "$str")"
|
||||
fi
|
||||
printf "%s\n" "$str"
|
||||
}
|
||||
|
||||
devices() {
|
||||
IGNORE_DEV="$(lsblk -lno NAME,MOUNTPOINT | awk '/\/run\/archiso\/bootmnt/ {sub(/[1-9]/, ""); print $1}')"
|
||||
if [[ $IGNORE_DEV ]]; then
|
||||
@ -77,17 +94,25 @@ devices() {
|
||||
}
|
||||
|
||||
sysid() {
|
||||
declare -g IS_64BIT=false
|
||||
local efidir="/sys/firmware/efi"
|
||||
|
||||
if grep -q 'GenuineIntel' /proc/cpuinfo; then
|
||||
declare -g UCODE="intel-ucode.img"
|
||||
elif grep -q 'AuthenticAMD' /proc/cpuinfo; then
|
||||
declare -g UCODE="amd-ucode.img"
|
||||
fi
|
||||
|
||||
if grep -qi 'apple' /sys/class/dmi/id/sys_vendor; then
|
||||
modprobe -r -q efivars
|
||||
else
|
||||
modprobe -q efivarfs
|
||||
fi
|
||||
|
||||
declare -g IS_64BIT=false
|
||||
|
||||
if [[ -d /sys/firmware/efi ]]; then
|
||||
if [[ -d $efidir ]]; then
|
||||
SYS="UEFI"
|
||||
[[ $(cat /sys/firmware/efi/fw_platform_size) == 64 ]] && IS_64BIT=true
|
||||
[[ $(cat $efidir/fw_platform_size) == 64 ]] && IS_64BIT=true
|
||||
grep -q $efidir/efivars <<< "$(mount)" || mount -t efivarfs efivarfs $efidir/efivars
|
||||
else
|
||||
SYS="BIOS"
|
||||
fi
|
||||
@ -124,7 +149,7 @@ echeck() {
|
||||
msg="$([[ $err == "" ]] && printf "%s" "$msg")\n$_ErrChoice"
|
||||
if [[ -e /tmp/debug-log && $TERM == 'linux' ]]; then
|
||||
msg="$([[ $err == "" ]] && printf "%s" "$msg")\n$_ErrChoiceConsole"
|
||||
yesno "$_ErrTitle" "$msg" "Exit & Open Log" "Ignore & Continue" && { less /tmp/debug-log; die 0; }
|
||||
yesno "$_ErrTitle" "$msg" "Exit & Open Log" "Ignore & Continue" && { more /tmp/debug-log; die 0; }
|
||||
else
|
||||
yesno "$_ErrTitle" "$msg" "Exit & Shutdown" "Ignore & Continue" && die 'shutdown -h now'
|
||||
fi
|
||||
@ -138,17 +163,16 @@ icheck() {
|
||||
}
|
||||
|
||||
yesno() {
|
||||
# usage: yesno <title> <text> [<yes_label> <no_label> [<no>]]
|
||||
# three options: one --default-no and custom labels, one just custom labels, and one basic.
|
||||
tput civis
|
||||
if [[ $# -eq 5 && $5 == "no" ]]; then
|
||||
# option for default no using custom labels
|
||||
dialog --cr-wrap --backtitle "$BT" --defaultno --title " $1 " \
|
||||
--yes-label "$3" --no-label "$4" --yesno "$2\n" 0 0
|
||||
elif [[ $# -eq 4 ]]; then
|
||||
# option for custom labels with standard default yes
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $1 " --yes-label "$3" \
|
||||
--no-label "$4" --yesno "$2\n" 0 0
|
||||
else
|
||||
# basic yes no without custom labels and default yes
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $1 " --yesno "$2\n" 0 0
|
||||
fi
|
||||
}
|
||||
@ -158,10 +182,10 @@ debug() {
|
||||
exec 3>| /tmp/debug-log
|
||||
BASH_XTRACEFD=3
|
||||
if [[ $DISPLAY && $TERM != 'linux' ]]; then
|
||||
if [[ $TERM_CMD == 'st' ]]; then
|
||||
$TERM_CMD -e tail -f /tmp/debug-log &
|
||||
if hash 'termite' >/dev/null 2>&1; then
|
||||
termite -e "tail -f /tmp/debug-log" &
|
||||
else
|
||||
$TERM_CMD -e "tail -f /tmp/debug-log" &
|
||||
xterm -e "tail -f /tmp/debug-log" &
|
||||
fi
|
||||
fi
|
||||
DEBUG=true
|
||||
|
Reference in New Issue
Block a user