# giant ugly variable container :P {
-# RAM in the system in MB
+# system RAM in MB
SYS_MEM="$(awk '/MemTotal/ {print int($2 / 1024) "M"}' /proc/meminfo)"
# locales from /etc/locale.gen
LOCALES="$(awk '/\.UTF-8/ {gsub(/# .*|#/, ""); if ($1) {print $1 " - "}}' /etc/locale.gen)"
-# linux console keyboard mappings
+# console keyboard mappings
CMAPS="$(find /usr/share/kbd/keymaps -name '*.map.gz' | awk '{gsub(/\.map\.gz|.*\//, ""); print $1 " - "}' | sort)"
-# terminal size definitions
+# terminal size
[[ $LINES ]] || LINES=$(tput lines)
[[ $COLUMNS ]] || COLUMNS=$(tput cols)
SHL=$((LINES - 20))
# associative arrays
# {
-# commands used to install each bootloader (most get modified during runtime) {
+# commands used to install each bootloader, however most get modified during runtime {
declare -A BCMDS=(
[refind-efi]='refind-install' # minor modification
[grub]='grub-install --recheck --force' # heavily modified
[systemd-boot]='bootctl --path=/boot install' # not modified
) # }
-# executable name for each wm/de {
+# executable name for each wm/de used in ~/.xinitrc {
declare -A WM_SESSIONS=(
[dwm]='dwm'
[i3-gaps]='i3'
[xfce4]='archlabs-skel-xfce4 xfce4-goodies' # see deps of archlabs-skel-xfce4
) # }
-# files that can be edited after install is complete {
+# files offered for editing after install is complete {
declare -A EDIT_FILES=(
[login]='' # login is populated once we know the username and shell
[fstab]='/etc/fstab'
[keyboard]='/etc/X11/xorg.conf.d/00-keyboard.conf /etc/default/keyboard'
) # }
-# mkfs command for filesystem formatting {
+# mkfs command and flags for filesystem formatting {
declare -A FS_CMDS=(
[f2fs]='mkfs.f2fs'
[jfs]='mkfs.jfs -q'
[reiserfs]='mkfs.reiserfs -q'
) # }
-# mount options for each filesystem (if any) {
+# mount options for each filesystem {
declare -A FS_OPTS=(
[vfat]='' # NA
[ntfs]='' # NA
[lightdm]='lightdm lightdm-gtk-greeter lightdm-gtk-greeter-settings accountsservice'
) # }
-# PKG_EXT: if you add a package to $PACKAGES in any dialog {
-# and it uses/requires some additional packages,
-# you can add them here to keep it simple: [package]="extra"
-# duplicates are not added
+# extras installed for user selected packages {
+# if a package requires additional packages that aren't already dependencies
+# they can be added here eg. [package]="extra"
declare -A PKG_EXT=(
[vlc]='qt4'
[mpd]='mpc'
# }
-# text variables
+# dialog text variables
# {
# Basics (somewhat in order)
###############################################################################
# selection menus
+# main is the entry point which calls functions including outside of its block
+# once those functions finished they always are returned here with the
+# exception of install_main(), it exits upon completion
-select_main()
+main()
{
(( SEL < 12 )) && (( SEL++ ))
tput civis
2) part_menu || (( SEL-- )) ;;
3) luks_menu || (( SEL-- )) ;;
4) lvm_menu || (( SEL-- )) ;;
- 5) select_menu || (( SEL-- )) ;;
+ 5) mount_menu || (( SEL-- )) ;;
6) prechecks 0 && { select_boot || (( SEL-- )); } ;;
7) prechecks 1 && { select_mkuser || (( SEL-- )); } ;;
8) prechecks 2 && { select_config || (( SEL-- )); } ;;
}
###############################################################################
-# partition menus
+# partitioning menus
+# non-essential partitioning helpers called by the user when using the optional
+# partition menu and selecting a device to edit
part_menu()
{
msg "Auto Partition" "\nProcess complete.\n\n$(lsblk -o NAME,MODEL,SIZE,TYPE,FSTYPE "$device")\n"
}
+part_shrink()
+{
+ part=""
+ typeset -i size num
+ local device="$1" fs=""
+
+ part_find "${device##*/}[^ ]" || return 1
+ (( COUNT == 1 )) && part="$(awk '{print $1}' <<< "${PARTS[@]}" )"
+
+ if (( COUNT == 1 )) || dlg part menu "Resize" "\nWhich partition on $device do you want to resize?" $PARTS; then
+ fs=$(lsblk -lno FSTYPE "$part")
+ case "$fs" in
+ ext*|ntfs)
+ msg "Resize" "\nGathering device size info.\n" 0
+ num="${part: -1}"
+ end=$(parted -s "$device" unit KiB print | awk '/^\s*'"$num"'/ {print $3}') # part size in KiB
+ devsize=$(parted -s "$device" unit KiB print | awk '/Disk '"${device//\//\\/}"':/ {print $3}') # whole device size in KiB
+ mount "$part" $MNT >/dev/null 2>&1; sleep 0.5
+ min=$(df --output=used --block-size=MiB "$part" | awk 'NR == 2 {print int($1) + 256}')
+ max=$(df --output=avail --block-size=MiB "$part" | awk 'NR == 2 {print int($1)}')
+ umount_dir $MNT
+ tput cnorm
+ if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$min" "$max" $((max / 2)) 2>$ANS; then
+ size=$(< "$ANS")
+ size=$((size * 1024))
+ else
+ return 1
+ fi
+ clear
+ case "$fs" in
+ ntfs)
+ if ntfsresize -fc "$part"; then
+ ntfsresize -ff --size $(( (size * 1024) / 1000 ))k "$part" 2>$ERR # k=10^3 bytes
+ errshow "ntfsresize -f -s $(( (size * 1024) / 1000 ))k $part" || return 1
+ else
+ msg "Resize" "\nThe ntfs partition $part cannot be resized because it is scheduled for a consistency check.\n\nTo do a consistency check in windows open command prompt as admin and run:\n\n\tchkdsk /f /r /x\n"
+ return 1
+ fi
+ ;;
+ *)
+ e2fsck -f "$part"; sleep 0.5
+ resize2fs -f "$part" ${size}K 2>$ERR # K=2^10 bytes
+ errshow "resize2fs -f $part ${size}K" || return 1
+ ;;
+ esac
+ sleep 0.5
+ parted "$device" resizepart "$num" ${size}KiB || return 1
+ (( size++ ))
+ sleep 0.5
+ if [[ $devsize == "$end" ]]; then
+ parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2>$ERR
+ errshow "parted -s $device mkpart primary ext4 ${size}KiB 100%" || return 1
+ else
+ parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2>$ERR
+ errshow "parted -s $device mkpart primary ext4 ${size}KiB ${end}KiB" || return 1
+ fi
+ msg "Resize Complete" "\n$part has been successfully resized to $((size / 1024))M.\n" 1
+ ;;
+ "") msg "No Filesystem" "\nFor unformatted partitions, cfdisk can be used in the partition menu.\n" ;;
+ *) msg "Invalid Filesystem: $fs" "\nResizing only supports ext and ntfs.\n" ;;
+ esac
+ fi
+}
+
+###############################################################################
+# partition management functions
+# these are helpers for use by other functions to do essential setup/teardown
+
part_find()
{
local regexp="$1" err=''
sleep "${delay:-0}"
}
-part_shrink()
-{
- part=""
- typeset -i size num
- local device="$1" fs=""
-
- part_find "${device##*/}[^ ]" || return 1
- (( COUNT == 1 )) && part="$(awk '{print $1}' <<< "${PARTS[@]}" )"
-
- if (( COUNT == 1 )) || dlg part menu "Resize" "\nWhich partition on $device do you want to resize?" $PARTS; then
- fs=$(lsblk -lno FSTYPE "$part")
- case "$fs" in
- ext*|ntfs)
- msg "Resize" "\nGathering device size info.\n" 0
- num="${part: -1}"
- end=$(parted -s "$device" unit KiB print | awk '/^\s*'"$num"'/ {print $3}') # part size in KiB
- devsize=$(parted -s "$device" unit KiB print | awk '/Disk '"${device//\//\\/}"':/ {print $3}') # whole device size in KiB
- mount "$part" $MNT >/dev/null 2>&1; sleep 0.5
- min=$(df --output=used --block-size=MiB "$part" | awk 'NR == 2 {print int($1) + 256}')
- max=$(df --output=avail --block-size=MiB "$part" | awk 'NR == 2 {print int($1)}')
- umount_dir $MNT
- tput cnorm
- if dialog --backtitle "$DIST Installer - $SYS - v$VER" --title " Resize: $part " --rangebox "$_resize" 17 "$COLUMNS" "$min" "$max" $((max / 2)) 2>$ANS; then
- size=$(< "$ANS")
- size=$((size * 1024))
- else
- return 1
- fi
- clear
- case "$fs" in
- ntfs)
- if ntfsresize -fc "$part"; then
- ntfsresize -ff --size $(( (size * 1024) / 1000 ))k "$part" 2>$ERR # k=10^3 bytes
- errshow "ntfsresize -f -s $(( (size * 1024) / 1000 ))k $part" || return 1
- else
- msg "Resize" "\nThe ntfs partition $part cannot be resized because it is scheduled for a consistency check.\n\nTo do a consistency check in windows open command prompt as admin and run:\n\n\tchkdsk /f /r /x\n"
- return 1
- fi
- ;;
- *)
- e2fsck -f "$part"; sleep 0.5
- resize2fs -f "$part" ${size}K 2>$ERR # K=2^10 bytes
- errshow "resize2fs -f $part ${size}K" || return 1
- ;;
- esac
- sleep 0.5
- parted "$device" resizepart "$num" ${size}KiB || return 1
- (( size++ ))
- sleep 0.5
- if [[ $devsize == "$end" ]]; then
- parted -s "$device" mkpart primary ext4 ${size}KiB 100% 2>$ERR
- errshow "parted -s $device mkpart primary ext4 ${size}KiB 100%" || return 1
- else
- parted -s "$device" mkpart primary ext4 ${size}KiB ${end}KiB 2>$ERR
- errshow "parted -s $device mkpart primary ext4 ${size}KiB ${end}KiB" || return 1
- fi
- msg "Resize Complete" "\n$part has been successfully resized to $((size / 1024))M.\n" 1
- ;;
- "") msg "No Filesystem" "\nFor unformatted partitions, cfdisk can be used in the partition menu.\n" ;;
- *) msg "Invalid Filesystem: $fs" "\nResizing only supports ext and ntfs.\n" ;;
- esac
- fi
-}
-
part_device()
{
if [[ $DEV_COUNT -eq 1 && $SYS_DEVS ]]; then
###############################################################################
# mounting menus
+# mount_menu is the entry point which calls all other functions
+# once finished it returns to the main menu: main()
-select_menu()
+mount_menu()
{
msg "Info" "\nGathering device info.\n" 0
is_bg_install || return 0
select_swap || return 1
select_extra_partitions || return 1
- install_background || return 1
+ install_background
return 0
}
###############################################################################
# installation
+# main is the entry point which calls all other install functions, once
+# complete it shows a dialog to edit files on the new system before reboot
install_main()
{
install_base()
{
if [[ $RSYNC_PID || $MIRROR_PID ]]; then
- clear
+ local oldmsg="" msg=""
printf "\nOne or more background install processes are still running, grabbing their output...\n"
- sleep 2
while kill -0 "$RSYNC_PID" 2>/dev/null || kill -0 "$MIRROR_PID" 2>/dev/null; do
- tail -n 1 /tmp/bg_out
- sleep 0.5
+ msg="$(tail -n 1 /tmp/bg_out)"
+ if [[ "$msg" != "$oldmsg" ]]; then
+ printf "\n%s" "$msg"
+ oldmsg="$msg"
+ else
+ printf "."
+ fi
done
trap - EXIT
unset RSYNC_PID MIRROR_PID
- elif hash rsync >/dev/null 2>&1 && [[ -d /run/archiso/sfs/airootfs/etc/skel ]]; then
+ else
rsync -ahv /run/archiso/sfs/airootfs/ $MNT/ 2>$ERR
errshow 1 "rsync -ahv /run/archiso/sfs/airootfs/ $MNT/"
install_mirrorlist "$MNT/etc/pacman.d/mirrorlist"
chrun "pacman -Syyu --noconfirm && pacman -S $BASE_PKGS --needed --noconfirm"
- else
- mkdir -p /etc/pacman.d/mirrorlist
- install_mirrorlist "/etc/pacman.d/mirrorlist"
- pacstrap "$MNT" base $ISO_BASE 2>$ERR
- errshow 1 "pacstrap $MNT base $KERNEL $ISO_BASE"
- mkdir -p "$MNT/etc/pacman.d/mirrorlist"
- cp -f /etc/pacman.d/mirrorlist "$MNT/etc/pacman.d/mirrorlist"
- chrun "pacman -Syyu --noconfirm && pacman -S $BASE_PKGS --needed --noconfirm"
fi
rm -rf $MNT/etc/mkinitcpio-archiso.conf
if [[ $VM ]]; then
find $MNT/etc/X11/xorg.conf.d/ -name '*.conf' -delete
elif lspci | grep ' VGA ' | grep -q 'Intel'; then
- cat > $MNT/etc/X11/xorg.conf.d/20-intel.conf << EOF
-Section "Device"
- Identifier "Intel Graphics"
- Driver "intel"
- Option "TearFree" "true"
-EndSection
-EOF
+ cat > $MNT/etc/X11/xorg.conf.d/20-intel.conf <<- EOF
+ Section "Device"
+ Identifier "Intel Graphics"
+ Driver "intel"
+ Option "TearFree" "true"
+ EndSection
+ EOF
fi
[[ -e /run/archiso/sfs/airootfs && $KERNEL == 'linux' ]] && cp -vf $RUN/x86_64/vmlinuz $MNT/boot/vmlinuz-linux
rm -f $MNT/etc/modprobe/
fi
- cat > $MNT/etc/X11/xorg.conf.d/00-keyboard.conf << EOF
-# Use localectl(1) to instruct systemd-localed to update it.
-Section "InputClass"
- Identifier "system-keyboard"
- MatchIsKeyboard "on"
- Option "XkbLayout" "$KEYMAP"
-EndSection
-EOF
- cat > $MNT/etc/default/keyboard << EOF
-# KEYBOARD CONFIGURATION FILE
-# Consult the keyboard(5) manual page.
-XKBMODEL=""
-XKBLAYOUT="$KEYMAP"
-XKBVARIANT=""
-XKBOPTIONS=""
-BACKSPACE="guess"
-EOF
+ cat > $MNT/etc/X11/xorg.conf.d/00-keyboard.conf <<- EOF
+ # Use localectl(1) to instruct systemd-localed to update it.
+ Section "InputClass"
+ Identifier "system-keyboard"
+ MatchIsKeyboard "on"
+ Option "XkbLayout" "$KEYMAP"
+ EndSection
+ EOF
+
+ cat > $MNT/etc/default/keyboard <<- EOF
+ # KEYBOARD CONFIGURATION FILE
+ # Consult the keyboard(5) manual page.
+ XKBMODEL=""
+ XKBLAYOUT="$KEYMAP"
+ XKBVARIANT=""
+ XKBOPTIONS=""
+ BACKSPACE="guess"
+ EOF
printf "KEYMAP=%s\nFONT=%s\n" "$CMAP" "$FONT" > $MNT/etc/vconsole.conf
echo "$MYHOST" > $MNT/etc/hostname
- cat > $MNT/etc/hosts << EOF
-127.0.0.1 localhost
-127.0.1.1 $MYHOST
-::1 localhost ip6-localhost ip6-loopback
-ff02::1 ip6-allnodes
-ff02::2 ip6-allrouters
-EOF
+ cat > $MNT/etc/hosts <<- EOF
+ 127.0.0.1 localhost
+ 127.0.1.1 $MYHOST
+ ::1 localhost ip6-localhost ip6-loopback
+ ff02::1 ip6-allnodes
+ ff02::2 ip6-allrouters
+ EOF
}
install_boot()
install_user()
{
+ rm -f $MNT/root/.zshrc # remove welcome message from root zshrc
chrun "chpasswd <<< 'root:$ROOT_PASS'" 2>$ERR
errshow 1 "set root password"
- if [[ $MYSHELL != "/usr/bin/zsh" ]]; then
- # root uses zsh by default, change it if something else was chosen
+ if [[ $MYSHELL != "/usr/bin/zsh" ]]; then # root uses zsh by default, change it if something else was chosen
chrun "usermod -s $MYSHELL root" 2>$ERR
errshow 1 "usermod -s $MYSHELL root"
+ # copy the default mkshrc to /root if mksh was picked
[[ $MYSHELL == '/usr/bin/mksh' ]] && cp -fv $MNT/etc/skel/.mkshrc $MNT/root/.mkshrc
fi
chrun "chpasswd <<< '$NEWUSER:$USER_PASS'" 2>$ERR
errshow 1 "set $NEWUSER password"
- if [[ $USER_PKGS == *neovim* && -d $MNT/home/$NEWUSER/.vim ]]; then
+ # if neovim was picked copy vim configs to ~/.config/nvim
+ if [[ $USER_PKGS == *neovim* ]]; then
mkdir -p $MNT/home/$NEWUSER/.config/nvim
cp -fv $MNT/home/$NEWUSER/.vimrc $MNT/home/$NEWUSER/.config/nvim/init.vim
cp -rfv $MNT/home/$NEWUSER/.vim/colors $MNT/home/$NEWUSER/.config/nvim/colors
fi
- [[ $INSTALL_WMS == *dwm* ]] && install_suckless
- [[ $INSTALL_WMS == *awesome* ]] && install_awesome
+ case $INSTALL_WMS in *awesome*) install_awesome ;; *dwm*) install_suckless ;; esac
+
[[ $WM_PKGS == *xfce* ]] && echo 'volumeicon &' >> $MNT/home/$NEWUSER/.xprofile
# remove some commands from ~/.xprofile when using KDE or Gnome as the login session
if [[ $AUTOLOGIN ]]; then
sed -i "s/root/${NEWUSER}/g" $SERVICE/autologin.conf
- cat > "$MNT/home/$NEWUSER/$LOGINRC" <<EOF
-# ~/$LOGINRC
-# sourced by ${MYSHELL##*/} when used as a login shell
+ cat > "$MNT/home/$NEWUSER/$LOGINRC" <<- EOF
+ # ~/$LOGINRC
+ # sourced by ${MYSHELL##*/} when used as a login shell
-# automatically run startx when logging in on tty1
-if [ -z \$DISPLAY ] && [ \$XDG_VTNR -eq 1 ]; then
- exec startx
-fi
-EOF
+ # automatically run startx when logging in on tty1
+ [ -z \$DISPLAY ] && [ \$XDG_VTNR -eq 1 ] && exec startx
+ EOF
else
rm -rf $SERVICE
fi
install_login()
{
SERVICE="$MNT/etc/systemd/system/getty@tty1.service.d"
- sed -i '/printf/d' $MNT/root/.zshrc
install_${LOGIN_TYPE:-xinit}
}
rm -rf "$SERVICE" "$MNT/home/$NEWUSER"/.{xinitrc,profile,zprofile,bash_profile}
chrun 'systemctl set-default graphical.target && systemctl enable lightdm.service' 2>$ERR
errshow 1 "systemctl set-default graphical.target && systemctl enable lightdm.service"
- cat > $MNT/etc/lightdm/lightdm-gtk-greeter.conf << EOF
-# LightDM GTK+ Configuration
+ cat > $MNT/etc/lightdm/lightdm-gtk-greeter.conf <<- EOF
+ # LightDM GTK+ Configuration
-[greeter]
-default-user-image=/usr/share/icons/ArchLabs-Dark/64x64/places/distributor-logo-archlabs.png
-background=/usr/share/backgrounds/archlabs/archlabs.jpg
-theme-name=Adwaita-dark
-icon-theme-name=Adwaita
-font-name=DejaVu Sans Mono 11
-position=30%,end 50%,end
-EOF
+ [greeter]
+ default-user-image=/usr/share/icons/ArchLabs-Dark/64x64/places/distributor-logo-archlabs.png
+ background=/usr/share/backgrounds/archlabs/archlabs.jpg
+ theme-name=Adwaita-dark
+ icon-theme-name=Adwaita
+ font-name=DejaVu Sans Mono 11
+ position=30%,end 50%,end
+ EOF
}
install_awesome()
{
# downloads and sets up @elenapan's awesome WM config hosted on github
-
if chrun "git clone https://github.com/elenapan/archlabs-awesome /home/$NEWUSER/archlabs-awesome"; then
cp -rT "/mnt/home/$NEWUSER/archlabs-awesome" "/mnt/home/$NEWUSER"
cp -rT "/mnt/home/$NEWUSER/archlabs-awesome" /mnt/etc/skel
rm -rf "/home/$NEWUSER/"{.git,archlabs-awesome,screenshots}
- printf "You will need to instal pamac seperately if needed using: 'baph -i pamac-aur'\n"
+ printf "You will need to install pamac separately using: 'baph -i pamac-aur'\n"
sleep 3
else
printf "failed to clone awesome config repo\n"
if hash reflector >/dev/null 2>&1; then
reflector --score 80 -l 40 -f 5 --sort rate --save "$mfile"
elif hash rankmirrors >/dev/null 2>&1; then
- ip_add="$(curl -fsSL "http://api.ipstack.com/check&?access_key=5f29642060ab983b31fdf4c2935d8c56&fields=ip" |
- python -c "import sys, json; print(json.load(sys.stdin)['ip'])")"
- country="$(curl -fsSL "http://api.ipstack.com/${ip_add}?access_key=5f29642060ab983b31fdf4c2935d8c56&fields=country_code" |
- python -c "import sys, json; print(json.load(sys.stdin)['country_code'])")"
+ local key="access_key=5f29642060ab983b31fdf4c2935d8c56"
+ ip_add="$(curl -fsSL "http://api.ipstack.com/check&?$key&fields=ip" | python -c "import sys, json; print(json.load(sys.stdin)['ip'])")"
+ country="$(curl -fsSL "http://api.ipstack.com/$ip_add?$key&fields=country_code" | python -c "import sys, json; print(json.load(sys.stdin)['country_code'])")"
if [[ "$country" ]]; then
if [[ $country =~ (CA|US) ]]; then
+ # use both CA and US mirrors for CA or US countries
mirror="https://www.archlinux.org/mirrorlist/?country=US&country=CA&use_mirror_status=on"
elif [[ $country =~ (AU|NZ) ]]; then
+ # use both AU and NZ mirrors for AU or NZ countries
mirror="https://www.archlinux.org/mirrorlist/?country=AU&country=NZ&use_mirror_status=on"
else
mirror="https://www.archlinux.org/mirrorlist/?country=${country}&use_mirror_status=on"
fi
- else
+ else # no country code so just grab all mirrors, will be a very slow sort but we don't have other options
mirror="https://www.archlinux.org/mirrorlist/?country=all&use_mirror_status=on"
fi
-
curl -fsSL "$mirror" | sed -e 's/^#Server/Server/' -e '/^#/d' | rankmirrors -n 6 - >"$mfile"
fi
install_background()
{
- if [[ -d /run/archiso/sfs/airootfs/etc/skel ]] && grep -qw "$MNT" /proc/mounts && (grep -qw "$MNT/$BOOTDIR" /proc/mounts || [[ $SYS == 'BIOS' && -z $LUKS ]]); then
- yesno "Background Install" "\nBegin install in the background?\n" || return 0
- rsync -a /run/archiso/sfs/airootfs/ $MNT/ &
- RSYNC_PID=$!
- ( install_mirrorlist "$MNT/etc/pacman.d/mirrorlist" && sleep 1 && mkdir -p $MNT/var/lib/pacman && chrun "pacman -Syyu $BASE_PKGS --needed --noconfirm" >> /tmp/bg_out 2>&1 ) &
- MIRROR_PID=$!
- # end the background processes before exiting
- trap "kill $RSYNC_PID $MIRROR_PID 2>/dev/null" EXIT
- fi
- return 0
+ yesno "Background Install" "\nBegin install in the background?\n" || return 0
+
+ rsync -a /run/archiso/sfs/airootfs/ $MNT/ &
+ RSYNC_PID=$!
+
+ mkdir -p $MNT/var/lib/pacman # can help with pacman errors
+ ( install_mirrorlist "$MNT/etc/pacman.d/mirrorlist" && sleep 1 && chrun "pacman -Syyu $BASE_PKGS --needed --noconfirm" >> /tmp/bg_out 2>&1 ) &
+ MIRROR_PID=$!
+
+ # end the background processes before exiting
+ trap "kill $RSYNC_PID $MIRROR_PID 2>/dev/null" EXIT
}
###############################################################################
# bootloader setup
+# prerun_* set up the configs needed before actually running the commands
+# setup_* are run after selecting a bootloader and build the command used later
+# they can also be used for further user input as these run before control is taken away
setup_grub()
{
[[ $SYS == 'UEFI' ]] && { c="$MNT/boot/EFI/syslinux"; s="/usr/lib/syslinux/efi64/"; d=''; }
mkdir -pv "$c" && cp -rfv $s/* "$c/" && cp -f "$RUN/syslinux/splash.png" "$c/"
- cat > "$c/syslinux.cfg" << EOF
-UI vesamenu.c32
-MENU TITLE $DIST Boot Menu
-MENU BACKGROUND splash.png
-TIMEOUT 50
-DEFAULT $DIST
-
-# see: https://www.syslinux.org/wiki/index.php/Comboot/menu.c32
-MENU WIDTH 78
-MENU MARGIN 4
-MENU ROWS 4
-MENU VSHIFT 10
-MENU TIMEOUTROW 13
-MENU TABMSGROW 14
-MENU CMDLINEROW 14
-MENU HELPMSGROW 16
-MENU HELPMSGENDROW 29
-MENU COLOR border 30;44 #40ffffff #a0000000 std
-MENU COLOR title 1;36;44 #9033ccff #a0000000 std
-MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all
-MENU COLOR unsel 37;44 #50ffffff #a0000000 std
-MENU COLOR help 37;40 #c0ffffff #a0000000 std
-MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
-MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
-MENU COLOR msg07 37;40 #90ffffff #a0000000 std
-MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
-
-LABEL $DIST
-MENU LABEL $DIST Linux
-LINUX $d/vmlinuz-$KERNEL
-APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
-INITRD $([[ $UCODE ]] && printf "%s" "$d/$UCODE.img,")$d/initramfs-$KERNEL.img
-
-LABEL ${DIST}fallback
-MENU LABEL $DIST Linux Fallback
-LINUX $d/vmlinuz-$KERNEL
-APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
-INITRD $([[ $UCODE ]] && printf "%s" "$d/$UCODE.img,")$d/initramfs-$KERNEL-fallback.img
-$([[ $SYS == 'BIOS' ]] && printf "\n%s" "# examples of chainloading other bootloaders
-
-#LABEL grub2
-#MENU LABEL Grub2
-#COM32 chain.c32
-#APPEND file=$d/grub/boot.img
-
-#LABEL windows
-#MENU LABEL Windows
-#COM32 chain.c32
-#APPEND hd0 3")
-EOF
+ cat > "$c/syslinux.cfg" <<- EOF
+ UI vesamenu.c32
+ MENU TITLE $DIST Boot Menu
+ MENU BACKGROUND splash.png
+ TIMEOUT 50
+ DEFAULT $DIST
+
+ # see: https://www.syslinux.org/wiki/index.php/Comboot/menu.c32
+ MENU WIDTH 78
+ MENU MARGIN 4
+ MENU ROWS 4
+ MENU VSHIFT 10
+ MENU TIMEOUTROW 13
+ MENU TABMSGROW 14
+ MENU CMDLINEROW 14
+ MENU HELPMSGROW 16
+ MENU HELPMSGENDROW 29
+ MENU COLOR border 30;44 #40ffffff #a0000000 std
+ MENU COLOR title 1;36;44 #9033ccff #a0000000 std
+ MENU COLOR sel 7;37;40 #e0ffffff #20ffffff all
+ MENU COLOR unsel 37;44 #50ffffff #a0000000 std
+ MENU COLOR help 37;40 #c0ffffff #a0000000 std
+ MENU COLOR timeout_msg 37;40 #80ffffff #00000000 std
+ MENU COLOR timeout 1;37;40 #c0ffffff #00000000 std
+ MENU COLOR msg07 37;40 #90ffffff #a0000000 std
+ MENU COLOR tabmsg 31;40 #30ffffff #00000000 std
+
+ LABEL $DIST
+ MENU LABEL $DIST Linux
+ LINUX $d/vmlinuz-$KERNEL
+ APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
+ INITRD $([[ $UCODE ]] && printf "%s" "$d/$UCODE.img,")$d/initramfs-$KERNEL.img
+
+ LABEL ${DIST}fallback
+ MENU LABEL $DIST Linux Fallback
+ LINUX $d/vmlinuz-$KERNEL
+ APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
+ INITRD $([[ $UCODE ]] && printf "%s" "$d/$UCODE.img,")$d/initramfs-$KERNEL-fallback.img
+ EOF
return 0
}
prerun_refind-efi()
{
- cat > $MNT/boot/refind_linux.conf << EOF
-"$DIST Linux" "root=$ROOT_PART_ID $([[ $LUKS_DEV ]] &&
- printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] &&
- printf "initrd=%s " "/$UCODE.img")initrd=/initramfs-$KERNEL.img"
-"$DIST Linux Fallback" "root=$ROOT_PART_ID $([[ $LUKS_DEV ]] &&
- printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] &&
- printf "initrd=%s " "/$UCODE.img")initrd=/initramfs-$KERNEL-fallback.img"
-EOF
+ cat > $MNT/boot/refind_linux.conf <<- EOF
+ "$DIST Linux" "root=$ROOT_PART_ID $([[ $LUKS_DEV ]] &&
+ printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] &&
+ printf "initrd=%s " "/$UCODE.img")initrd=/initramfs-$KERNEL.img"
+ "$DIST Linux Fallback" "root=$ROOT_PART_ID $([[ $LUKS_DEV ]] &&
+ printf "%s " "$LUKS_DEV")rw add_efi_memmap $([[ $UCODE ]] &&
+ printf "initrd=%s " "/$UCODE.img")initrd=/initramfs-$KERNEL-fallback.img"
+ EOF
mkdir -p $MNT/etc/pacman.d/hooks
- cat > $MNT/etc/pacman.d/hooks/refind.hook << EOF
-[Trigger]
-Operation = Upgrade
-Type = Package
-Target = refind-efi
+ cat > $MNT/etc/pacman.d/hooks/refind.hook <<- EOF
+ [Trigger]
+ Operation = Upgrade
+ Type = Package
+ Target = refind-efi
-[Action]
-Description = Updating rEFInd on ESP
-When = PostTransaction
-Exec = /usr/bin/refind-install
-EOF
+ [Action]
+ Description = Updating rEFInd on ESP
+ When = PostTransaction
+ Exec = /usr/bin/refind-install
+ EOF
}
setup_systemd-boot()
prerun_systemd-boot()
{
mkdir -p $MNT/boot/loader/entries
- cat > $MNT/boot/loader/loader.conf << EOF
-default $DIST
-timeout 5
-editor no
-EOF
- cat > $MNT/boot/loader/entries/$DIST.conf << EOF
-title $DIST Linux
-linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img")
-initrd /initramfs-$KERNEL.img
-options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
-EOF
- cat > $MNT/boot/loader/entries/$DIST-fallback.conf << EOF
-title $DIST Linux Fallback
-linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img")
-initrd /initramfs-$KERNEL-fallback.img
-options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
-EOF
+
+ cat > $MNT/boot/loader/loader.conf <<- EOF
+ default $DIST
+ timeout 5
+ editor no
+ EOF
+
+ cat > $MNT/boot/loader/entries/$DIST.conf <<- EOF
+ title $DIST Linux
+ linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img")
+ initrd /initramfs-$KERNEL.img
+ options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
+ EOF
+
+ cat > $MNT/boot/loader/entries/$DIST-fallback.conf <<- EOF
+ title $DIST Linux Fallback
+ linux /vmlinuz-${KERNEL}$([[ $UCODE ]] && printf "\ninitrd %s" "/$UCODE.img")
+ initrd /initramfs-$KERNEL-fallback.img
+ options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && printf "%s " "$LUKS_DEV")rw
+ EOF
+
mkdir -p $MNT/etc/pacman.d/hooks
- cat > $MNT/etc/pacman.d/hooks/systemd-boot.hook << EOF
-[Trigger]
-Type = Package
-Operation = Upgrade
-Target = systemd
-
-[Action]
-Description = Updating systemd-boot
-When = PostTransaction
-Exec = /usr/bin/bootctl update
-EOF
+ cat > $MNT/etc/pacman.d/hooks/systemd-boot.hook <<- EOF
+ [Trigger]
+ Type = Package
+ Operation = Upgrade
+ Target = systemd
+
+ [Action]
+ Description = Updating systemd-boot
+ When = PostTransaction
+ Exec = /usr/bin/bootctl update
+ EOF
+
systemd-machine-id-setup --root="$MNT"
return 0
}
}
###############################################################################
-# helper functions
+# simple functions
+# some help avoid repetition and improve usability of some commands
+# others are initial setup functions used before reaching the main loop
ofn()
{
net_connect || { msg "Not Connected" "\nThis installer requires an active internet connection.\n\nExiting..\n" 2; die 1; }
while :; do
- select_main
+ main
done
# vim:fdm=marker:fmr={,}