Function style change, clean up for virtualbox utils

This commit is contained in:
natemaia 2018-11-25 00:18:33 -08:00
parent 76a62ee6da
commit 8e1b4a6647
11 changed files with 264 additions and 132 deletions

View File

@ -19,22 +19,21 @@
- `arch-chroot` to perform operations in a chroot.
- `chpasswd` to set root and user passwords.
- `openssl` to encrypt passwords.
- Basic Unix tools
- `awk` `sed` `grep` `uniq` `sort` `find` `ping` `mkfs` `lsblk` `curl`.
- Basic unix tool set: `awk` `sed` `grep` `uniq` `sort` `find` `ping` `mkfs` `lsblk` `curl`.
- Network connection is needed to install packages and update the system.
#### Manual Installation
- curl
```
sh -c "$(curl -fsSL https://bitbucket.org/archlabslinux/installer/raw/master/install.sh)"
```
```
sh -c "$(curl -fsSL https://bitbucket.org/archlabslinux/installer/raw/master/install.sh)"
```
- wget
```
sh -c "$(wget https://bitbucket.org/archlabslinux/installer/raw/master/install.sh -O -)"
```
```
sh -c "$(wget https://bitbucket.org/archlabslinux/installer/raw/master/install.sh -O -)"
```
- Packages for `pacman` can be found in our repos:
- stable: https://bitbucket.org/archlabslinux/archlabs_repo/src/master/x86_64/
- unstable: https://bitbucket.org/archlabslinux/archlabs_unstable/src/master/x86_64/
- Pre-built packages can be found in our repos:
[stable](https://bitbucket.org/archlabslinux/archlabs_repo/src/master/x86_64/)
[unstable](https://bitbucket.org/archlabslinux/archlabs_unstable/src/master/x86_64/)

View File

@ -1,5 +1,7 @@
#!/usr/bin/bash
# shellcheck disable=2154,2034,2153
# vim:fdm=marker:fmr={,}
# This program is free software, provided under the GNU GPL
# Written by Nathaniel Maia for use in Archlabs
@ -8,13 +10,14 @@
# immutable globals
readonly VER="1.7.19" # Installer version
readonly VER="1.7.20" # Installer version
readonly DIST="ArchLabs" # Linux distributor
readonly MNT="/mnt/install" # Install mountpoint
readonly ERR="/tmp/errlog" # Built-in error log
readonly DBG="/tmp/debuglog" # Built-in error log
main() {
main()
{
if [[ $CURRENT_MENU != "main" ]]; then
if [[ $SAVED ]]; then
SELECTED=$((SAVED + 1))

View File

@ -35,7 +35,8 @@ declare -Agx EDIT_FILES=(
[11]="" # login files, left empty, don't know the username yet for /home/USER/FILES
)
prep_for_grub() {
prep_for_grub()
{
local cfg="$MNT/etc/default/grub"
sed -i "s/GRUB_DISTRIBUTOR=.*/GRUB_DISTRIBUTOR=\"${DIST}\"/g;
s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"\"/g" $cfg
@ -49,7 +50,8 @@ prep_for_grub() {
return 0
}
prep_for_systemd-boot() {
prep_for_systemd-boot()
{
# no LVM then systemd-boot uses PARTUUID
[[ $ROOT_PART =~ /dev/mapper ]] || ROOT_PART_ID="PART$ROOT_PART_ID"
@ -84,7 +86,8 @@ EOF
return 0
}
prep_for_syslinux() {
prep_for_syslinux()
{
if [[ $SYS == 'UEFI' ]]; then
local cfgdir="${MNT}${BMNTS[$SYS-$BOOTLDR]}/EFI/syslinux"
local cfgsrcdir="/usr/lib/syslinux/efi32/"
@ -119,7 +122,8 @@ EOF
return 0
}
install_bootloader() {
install_bootloader()
{
# not an LVM we can use the UUID for booting otherwise use the partition label
if ! [[ $ROOT_PART =~ /dev/mapper ]]; then
ROOT_PART_ID="UUID=$(blkid -s PARTUUID -o value $ROOT_PART)"
@ -145,7 +149,8 @@ install_bootloader() {
return 0
}
uefi_boot_fallback() {
uefi_boot_fallback()
{
# some UEFI firmware requires a directory in the ESP and a generic bootx64.efi
# see: https://wiki.archlinux.org/index.php/GRUB#UEFI
# also: https://wiki.archlinux.org/index.php/syslinux#UEFI_Systems
@ -172,7 +177,8 @@ uefi_boot_fallback() {
return 0
}
shim_secure_boot() {
shim_secure_boot()
{
# still a W.I.P
local shim_file="shim.efi"
[[ $IS_64BIT == true ]] && shim_file="shim64.efi"

View File

@ -8,7 +8,9 @@
# shellcheck disable=2154,2034,2153
# mutable globals {
# mutable globals
# {
declare -g WARN=false
declare -g AUTOLOGIN=false
declare -g CONFIG_DONE=false
@ -38,15 +40,16 @@ declare -g MKINIT_HOOKS="shutdown"
# }
# basic dialog helper functions
msgbox() {
msgbox()
{
tput civis
dialog --cr-wrap --backtitle "$BT" --title " $1 " --msgbox "$2\n" 0 0
}
menubox() {
menubox()
{
local title="$1"
local body="$2"
local h=$3
@ -60,7 +63,8 @@ menubox() {
printf "%s" "$response"
}
checkbox() {
checkbox()
{
local title="$1"
local body="$2"
local h=$3
@ -74,7 +78,8 @@ checkbox() {
printf "%s" "$response"
}
getinput() {
getinput()
{
local answer
if ! answer="$(dialog --cr-wrap --max-input 63 --stdout --no-cancel --backtitle "$BT" --title " $1 " --inputbox "$2" 0 0 "$3")" || [[ $answer == '' ]]; then
return 1
@ -82,14 +87,16 @@ getinput() {
printf "%s" "$answer"
}
infobox() {
infobox()
{
local sec="$3"
tput civis
dialog --cr-wrap --backtitle "$BT" --title " $1 " --infobox "$2\n" 0 0
sleep ${sec:-2}
}
yesno() {
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
@ -106,7 +113,8 @@ yesno() {
# larger specific dialog menus
select_language() {
select_language()
{
tput civis
local lang
local title="\nLanguage - sprache - taal - språk - lingua - idioma - nyelv - língua\n"
@ -145,7 +153,8 @@ select_language() {
return 0
}
user_creation() {
user_creation()
{
tput cnorm
local values
if ! values="$(dialog --stdout --no-cancel --separator '~' --ok-label "Submit" --backtitle "$BT" \
@ -211,7 +220,8 @@ user_creation() {
return 0
}
select_keymap() {
select_keymap()
{
tput civis
if ! KEYMAP="$(menubox "$_PrepLayout" "$_XMapBody" 20 70 12 \
'us' 'English' 'cm' 'English' 'gb' 'English' 'au' 'English' 'gh' 'English' \
@ -254,7 +264,8 @@ select_keymap() {
return 0
}
select_timezone() {
select_timezone()
{
# create associative array for SUBZONES[zone]
local f="/usr/share/zoneinfo/zone.tab"
declare -A SUBZONES
@ -276,7 +287,8 @@ select_timezone() {
yesno "$_TimeZTitle" "$_TimeZQ $ZONE/$SUBZONE?\n" && return 0 || select_timezone
}
select_wm_or_de() {
select_wm_or_de()
{
declare -g PACKAGES=""
tput civis
@ -348,7 +360,8 @@ select_wm_or_de() {
return 0
}
select_login_method() {
select_login_method()
{
if ! LOGIN_TYPE="$(menubox "$_WMLogin" "$_LoginTypeBody" 0 0 0 \
"xinit" "Console login without a display manager" \
"lightdm" "Lightweight display manager with a gtk greeter")"; then
@ -362,7 +375,8 @@ select_login_method() {
fi
}
select_packages() {
select_packages()
{
if [[ $CURRENT_MENU != "packages" ]]; then
declare -g SAVED=$SELECTED
SELECTED=1
@ -402,7 +416,8 @@ select_packages() {
fi
}
select_mirrorcmd() {
select_mirrorcmd()
{
local ip c
local key="5f29642060ab983b31fdf4c2935d8c56"
@ -444,7 +459,8 @@ select_mirrorcmd() {
return 0
}
display_system_settings() {
display_system_settings()
{
local cmd mnt pkgs
cmd="${BCMDS[$BOOTLDR]}"
mnt="${BMNTS[$SYS-$BOOTLDR]}"
@ -498,7 +514,8 @@ display_system_settings() {
"
}
configure_system_settings() {
configure_system_settings()
{
tput cnorm
if ! HOSTNAME="$(getinput "$_ConfHost" "$_HostNameBody" "${DIST,,}")"; then
return 1
@ -540,7 +557,8 @@ configure_system_settings() {
return 0
}
edit_system_configs() {
edit_system_configs()
{
if [[ $CURRENT_MENU != "edit" ]]; then
SELECTED=1; CURRENT_MENU="edit"
elif (( SELECTED < 11 )); then

View File

@ -1,19 +1,23 @@
#!/usr/bin/bash
# vim:ft=sh:fdm=marker:fmr={,}
# shellcheck disable=2153
# 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
# shellcheck disable=2153
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
clear; tput cnorm
install()
{
# NOTE: function calls prefixed with 'oneshot' will only ever be run once
# this allows running install() multiple times without redoing things
clear
tput cnorm
# unpack the file system
oneshot install_base
@ -52,11 +56,14 @@ install() {
edit_system_configs
}
install_base() {
install_base()
{
# compressed image?
if [[ -e /run/archiso/sfs/airootfs/ ]]; then
printf "\nUnpacking base system --- Total: ~ 2.9G\n\n"
rsync -ah --info=progress2 /run/archiso/sfs/airootfs/ $MNT/
else
# update the mirrorlist.. MUST be done before pacstrapping or it may be slow
oneshot mirrorlist_sort
@ -108,7 +115,8 @@ EOF
[[ -e /etc/NetworkManager/system-connections ]] && cp -rf /etc/NetworkManager/system-connections $MNT/etc/NetworkManager/
cp -f /etc/resolv.conf $MNT/etc/
# set the locale and timezone
# set the locale
cat > $MNT/etc/locale.conf << EOF
LANG=$LOCALE
EOF
@ -117,8 +125,12 @@ LANG=$LOCALE
EOF
sed -i "s/#en_US.UTF-8/en_US.UTF-8/g; s/#${LOCALE}/${LOCALE}/g" $MNT/etc/locale.gen
chrun "locale-gen" 2>/dev/null
# set the timezone
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 <<EOF
# Use localectl(1) to instruct systemd-localed to update it.
@ -137,11 +149,15 @@ XKBVARIANT=""
XKBOPTIONS=""
BACKSPACE="guess"
EOF
# console keymap
cat > $MNT/etc/vconsole.conf <<EOF
KEYMAP=$CMAP
FONT=$FONT
EOF
# set the hostname
cat > $MNT/etc/hostname << EOF
$HOSTNAME
@ -153,27 +169,31 @@ EOF
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
return 0
}
create_user() {
create_user()
{
# set root password
chrun "chpasswd <<< 'root:$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$ROOT_PASS")'"
# Create the user, set password, then remove temporary password file
local groups='audio,autologin,floppy,log,network,rfkill,scanner,storage,optical,power,wheel'
# setup the autologin group
chrun "groupadd -r autologin"
# Create the user, set password, and make sure the ownership of ~/ is correct
chrun "useradd -m -u 1000 -g users -G $groups -s $MYSHELL $NEWUSER" 2>$ERR
chrun "chpasswd <<< '$NEWUSER:$(openssl enc -pbkdf2 -a -d -salt -pass pass:$SALT <<< "$USER_PASS")'"
chrun "chown -Rf $NEWUSER:users /home/$NEWUSER"
# remove welcome message
# remove configs for window managers that were never installed
[[ $INSTALL_WMS =~ i3-gaps ]] || rm -rf $MNT/home/$NEWUSER/.config/i3
[[ $INSTALL_WMS =~ bspwm ]] || rm -rf $MNT/home/$NEWUSER/.config/{bspwm,sxhkd}
[[ $INSTALL_WMS =~ openbox ]] || rm -rf $MNT/home/$NEWUSER/.config/{openbox,skippy-xd,jgmenu,conky,tint2}
[[ $INSTALL_WMS =~ (openbox|i3-gaps|bspwm) ]] || rm -rf $MNT/home/$NEWUSER/.config/polybar
# for neovim copy the default vimrc and colorscheme to ~/.config/nvim
# for neovim set up ~/.config/nvim
if [[ $PACKAGES =~ neovim ]]; then
mkdir -p $MNT/home/$NEWUSER/.config/nvim
cp -f $MNT/home/$NEWUSER/.vimrc $MNT/home/$NEWUSER/.config/nvim/init.vim
@ -184,15 +204,19 @@ create_user() {
return 0
}
login_manager() {
login_manager()
{
local service="$MNT/etc/systemd/system/getty@tty1.service.d"
# remove welcome message
sed -i '/printf/d' $MNT/root/.zshrc
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
rm -rf $service
chrun 'systemctl enable lightdm.service && systemctl set-default graphical.target'
cat > $MNT/etc/lightdm/lightdm-gtk-greeter.conf << EOF
# LightDM GTK+ Configuration
@ -205,8 +229,9 @@ icon-theme-name=Adwaita
font-name=DejaVu Sans Mono 11
position=30%,end 50%,end
EOF
else
# xinit login
else # xinit login
if [[ -e $MNT/home/$NEWUSER/.xinitrc ]]; then
sed -i "s/openbox-session/${LOGIN_WM}/g" $MNT/home/$NEWUSER/.xinitrc
else
@ -214,8 +239,14 @@ EOF
fi
# automatic startx for login shells
[[ $MYSHELL == '/bin/bash' ]] && local loginrc=".bash_profile" || local loginrc=".zprofile"
EDIT_FILES[11]+="/home/$NEWUSER/$loginrc"
case $MYSHELL in
/bin/bash) local loginrc=".bash_profile" ;;
/usr/bin/zsh) local loginrc=".zprofile" ;;
/usr/bin/mksh) local loginrc=".profile" ;;
esac
# add the shell login file to the edit list after install
EDIT_FILES[11]+=" /home/$NEWUSER/$loginrc"
cat >> $MNT/home/$NEWUSER/$loginrc << EOF
# ~/$loginrc
@ -234,7 +265,8 @@ EOF
fi
}
run_mkinitcpio() {
run_mkinitcpio()
{
local add=""
# setup a keyfile for LUKS.. Only when choosing grub and system is UEFI
[[ $LUKS && ! $LVM && $SYS == 'UEFI' && $BOOTLDR == 'grub' ]] && luks_keyfile
@ -248,7 +280,8 @@ run_mkinitcpio() {
echeck "mkinitcpio -p $KERNEL"
}
mirrorlist_sort() {
mirrorlist_sort()
{
printf "\n\n%s\n\n" "Sorting the mirrorlist"
if hash reflector >/dev/null 2>&1; then
$MIRROR_CMD --save $MNT/etc/pacman.d/mirrorlist --verbose ||
@ -259,19 +292,24 @@ mirrorlist_sort() {
fi
}
package_operations() {
package_operations()
{
local inpkg="$PACKAGES" # add the packages chosen during setup
local rmpkg="archlabs-installer" # always remove the installer
# the LTS kernel uses different packages
if [[ $KERNEL == 'linux-lts' ]]; then
rmpkg+=" virtualbox-guest-modules-arch linux"
rmpkg+=" linux"
inpkg+=" linux-lts"
# if the system is a VM then install the needed packages otherwise remove the guest utils
[[ $VM ]] && inpkg+=" virtualbox-guest-dkms linux-lts-headers" || rmpkg+=" virtualbox-guest-utils"
fi
# if the system is a VM then install the needed packages
if [[ $VM ]]; then
inpkg+=" virtualbox-guest-utils"
if [[ $KERNEL == 'linux-lts' ]]; then
inpkg+=" virtualbox-guest-dkms linux-lts-headers"
else
# if the system is not a VM then remove the guest utils
[[ $VM ]] || rmpkg+=" virtualbox-guest-modules-arch virtualbox-guest-utils"
inpkg+=" virtualbox-guest-modules-arch"
fi
fi
# for only gnome or cinnamon we don't need the xfce provided stuff
@ -295,7 +333,8 @@ package_operations() {
return 0
}
suckless_install() {
suckless_install()
{
# install and setup dwm
printf "\n\n%s\n\n" "Installing and setting up dwm."
mkdir -pv $MNT/home/$NEWUSER/suckless

View File

@ -15,7 +15,8 @@ declare -g LUKS_PASS=""
declare -g LUKS_UUID=""
declare -g LUKS_NAME="cryptroot"
luks_open() {
luks_open()
{
LUKS_PART=""
modprobe -a dm-mod dm_crypt
umount_dir $MNT
@ -44,7 +45,8 @@ luks_open() {
return 0
}
luks_pass() {
luks_pass()
{
local title="$1"
local name="$2"
LUKS_PASS=""
@ -86,7 +88,8 @@ luks_pass() {
return 0
}
luks_setup() {
luks_setup()
{
LUKS_PART=""
modprobe -a dm-mod dm_crypt
umount_dir $MNT
@ -114,7 +117,8 @@ luks_setup() {
return 0
}
luks_default() {
luks_default()
{
luks_setup || return 1
infobox "$_LuksEncrypt" "$_LuksWaitBody $LUKS_NAME $_LuksWaitBody2 $LUKS_PART\n" 0
@ -129,7 +133,8 @@ luks_default() {
return 0
}
luks_keycmd() {
luks_keycmd()
{
if luks_setup; then
tput cnorm
local cipher
@ -151,13 +156,15 @@ luks_keycmd() {
return 1
}
luks_show() {
luks_show()
{
tput civis
sleep 0.5
msgbox "$_LuksEncrypt" "${_LuksEncryptSucc}\n$(lsblk $LUKS_PART -o NAME,MODEL,TYPE,FSTYPE,SIZE)"
}
luks_menu() {
luks_menu()
{
tput civis
local choice
choice="$(menubox "$_PrepLUKS" "${_LuksMenuBody}${_LuksMenuBody2}${_LuksMenuBody3}" 0 0 0 \
@ -176,7 +183,8 @@ luks_menu() {
luks_menu
}
luks_keyfile() {
luks_keyfile()
{
# Only used when choosing grub as bootloader.
# Without a keyfile, during boot the user will be asked
# to enter password for decryption twice, this is annoying

View File

@ -12,7 +12,8 @@ declare -g LVM=""
declare -g VOL_GROUP_MB=0
declare -g GROUP_PARTS=0
lvm_detect() {
lvm_detect()
{
PHYSICAL_VOLUMES="$(pvs -o pv_name --noheading 2>/dev/null)"
VOLUME_GROUP="$(vgs -o vg_name --noheading 2>/dev/null)"
VOLUMES="$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)"
@ -28,7 +29,8 @@ lvm_detect() {
fi
}
lvm_show_vg() {
lvm_show_vg()
{
DEL_VG=""
VOL_GROUP_LIST=""
@ -48,7 +50,8 @@ lvm_show_vg() {
return 0
}
get_lv_size() {
get_lv_size()
{
tput cnorm
local ttl=" $_LvmCreateVG (LV:$VOL_COUNT) "
local msg="${VOLUME_GROUP}: ${GROUP_SIZE}$GROUP_SIZE_TYPE (${VOL_GROUP_MB}MB $_LvmLvSizeBody1).$_LvmLvSizeBody2"
@ -98,7 +101,8 @@ get_lv_size() {
return 0
}
lvm_volume_name() {
lvm_volume_name()
{
local msg="$1"
local default="volmain"
@ -120,7 +124,8 @@ lvm_volume_name() {
return 0
}
lvm_group_name() {
lvm_group_name()
{
tput cnorm
local group
if ! group="$(getinput "$_LvmCreateVG" "$_LvmNameVgBody" "VolGroup")"; then
@ -137,7 +142,8 @@ lvm_group_name() {
return 0
}
lvm_extra_lvs() {
lvm_extra_lvs()
{
while (( VOL_COUNT > 1 )); do
# get the name and size
lvm_volume_name "$_LvmLvNameBody1" || { break; return 1; }
@ -154,7 +160,8 @@ lvm_extra_lvs() {
return 0
}
lvm_volume_count() {
lvm_volume_count()
{
if ! VOL_COUNT=$(dialog --cr-wrap --stdout --backtitle "$BT" --title " $_LvmCreateVG " \
--radiolist "$_LvmLvNumBody1 $VOLUME_GROUP\n$_LvmLvNumBody2" 0 0 0 \
"1" "-" off "2" "-" off "3" "-" off "4" "-" off "5" "-" off \
@ -164,7 +171,8 @@ lvm_volume_count() {
return 0
}
lvm_partitions() {
lvm_partitions()
{
find_partitions 'part|crypt' || return 1
PARTS="$(awk 'NF > 0 {print $0 " off"}' <<< "$PARTS")"
@ -177,7 +185,8 @@ lvm_partitions() {
return 0
}
lvm_create_group() {
lvm_create_group()
{
# get volume group name
lvm_group_name || return 1
@ -203,7 +212,8 @@ lvm_create_group() {
return 0
}
lvm_create() {
lvm_create()
{
VOLUME_GROUP=""
GROUP_PARTS=""
VOL_GROUP_MB=0
@ -230,14 +240,16 @@ lvm_create() {
return 0
}
lvm_del_vg() {
lvm_del_vg()
{
if lvm_show_vg; then
yesno "$_LvmDelVG" "$_LvmDelQ" && vgremove -f "$DEL_VG" >/dev/null 2>&1
fi
return 0
}
lvm_del_all() {
lvm_del_all()
{
PHYSICAL_VOLUMES="$(pvs -o pv_name --noheading 2>/dev/null)"
VOLUME_GROUP="$(vgs -o vg_name --noheading 2>/dev/null)"
VOLUMES="$(lvs -o vg_name,lv_name --noheading --separator - 2>/dev/null)"
@ -258,7 +270,8 @@ lvm_del_all() {
return 0
}
lvm_menu() {
lvm_menu()
{
lvm_detect
tput civis

View File

@ -13,7 +13,8 @@ readonly SALT="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | 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 " -"}')"
mount_install_partitions() {
mount_install_partitions()
{
# prepare partition list PARTS for dialog
lvm_detect
umount_dir $MNT
@ -39,7 +40,8 @@ mount_install_partitions() {
return 0
}
select_swap() {
select_swap()
{
# Ask user to select partition or create swapfile
tput civis
if ! SWAP_PART="$(menubox "$_SelSwpSetup" "$_SelSwpBody" 0 0 0 \
@ -70,7 +72,8 @@ select_swap() {
return 0
}
select_mountpoint() {
select_mountpoint()
{
tput cnorm
if ! EXTRA_MNT="$(getinput "$_PrepMount $part" "$_ExtPartBody1 /home /var\n" "/")"; then
return 1
@ -84,7 +87,8 @@ select_mountpoint() {
return 0
}
select_boot_setup() {
select_boot_setup()
{
# choose bootloader and mountpoint (if needed)
tput civis
if ! BOOTLDR="$(menubox "$_PrepMount" "$_MntBootBody" 0 0 0 ${BOOTLDRS[$SYS]})"; then
@ -132,7 +136,8 @@ select_boot_setup() {
return 0
}
select_mount_opts() {
select_mount_opts()
{
local part="$1"
local fs="$2"
local title="${fs^} Mount Options"
@ -152,7 +157,8 @@ select_mount_opts() {
return 0
}
select_filesystem() {
select_filesystem()
{
local part="$1"
local fs cur_fs str title
cur_fs="$(lsblk -lno FSTYPE $part)"
@ -177,7 +183,8 @@ select_filesystem() {
return 0
}
select_efi_partition() {
select_efi_partition()
{
tput civis
if (( COUNT == 1 )); then
BOOT_PART="$(awk 'NF > 0 {print $1}' <<< "$PARTS")"
@ -198,7 +205,8 @@ select_efi_partition() {
return 0
}
select_boot_partition() {
select_boot_partition()
{
tput civis
if ! BOOT_PART="$(menubox "$_PrepMount" "$_SelBiosBody" 0 0 0 "$_Skip" "-" $PARTS)" || [[ $BOOT_PART == "$_Skip" ]]; then
BOOT_PART=""
@ -213,7 +221,8 @@ select_boot_partition() {
return 0
}
select_root_partition() {
select_root_partition()
{
# if we used LUKS and no LVM or LUKS+LVM remove the relevant partition labels from the list
if [[ $LUKS && ! $LVM ]]; then
ROOT_PART="/dev/mapper/$LUKS_NAME"
@ -242,7 +251,8 @@ select_root_partition() {
return 0
}
select_extra_partitions() {
select_extra_partitions()
{
while (( COUNT > 0 )); do
tput civis
local part

View File

@ -27,7 +27,8 @@ declare -gA PKG_EXT=(
[qutebrowser]="qt5ct qt5-styleplugins"
)
select_browsers() {
select_browsers()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"firefox" "A popular open-source graphical web browser from Mozilla" off \
@ -38,7 +39,8 @@ select_browsers() {
printf "%s" "$pkgs"
}
select_editors() {
select_editors()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"atom" "An open-source text editor developed by GitHub that is licensed under the MIT License" off \
@ -49,7 +51,8 @@ select_editors() {
printf "%s" "$pkgs"
}
select_terminals() {
select_terminals()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"termite" "A minimal VTE-based terminal emulator" off \
@ -61,7 +64,8 @@ select_terminals() {
printf "%s" "$pkgs"
}
select_music_and_video() {
select_music_and_video()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"vlc" "A free and open source cross-platform multimedia player" off \
@ -77,7 +81,8 @@ select_music_and_video() {
printf "%s" "$pkgs"
}
select_mail_and_chat() {
select_mail_and_chat()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"thunderbird" "Standalone mail and news reader from mozilla" off \
@ -91,7 +96,8 @@ select_mail_and_chat() {
printf "%s" "$pkgs"
}
select_office_and_editing() {
select_office_and_editing()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"libreoffice-fresh" "Full featured office suite" off \
@ -109,7 +115,8 @@ select_office_and_editing() {
printf "%s" "$pkgs"
}
select_managment() {
select_managment()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"thunar" "A modern file manager for the Xfce Desktop Environment" off \
@ -126,7 +133,8 @@ select_managment() {
printf "%s" "$pkgs"
}
select_extra() {
select_extra()
{
local pkgs=""
pkgs="$(checkbox "$_Packages" "$_PackageBody" 0 0 0 \
"steam" "A popular game distribution platform by Valve" off \

View File

@ -23,13 +23,15 @@ declare -Agr FS_OPTS=([vfat]="" [ntfs]="" [ext2]="" [ext3]=""
[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() {
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() {
partition()
{
local device
if [[ $# -eq 0 ]]; then
select_device 'root' || return 1
@ -61,7 +63,8 @@ partition() {
fi
}
decr_count() {
decr_count()
{
# remove a partition from the dialog list and decrement the number partitions left
(( $# == 1 )) || return 1
@ -71,7 +74,8 @@ decr_count() {
return 0
}
enable_swap() {
enable_swap()
{
if [[ $1 == "$MNT/swapfile" && $SWAP_SIZE ]]; then
fallocate -l $SWAP_SIZE $1 2>$ERR
echeck "fallocate -l $SWAP_SIZE $1"
@ -85,7 +89,8 @@ enable_swap() {
return 0
}
device_tree() {
device_tree()
{
tput civis
local msg
if [[ $IGNORE_DEV != "" ]]; then
@ -98,7 +103,8 @@ device_tree() {
msgbox "$_PrepShowDev" "$msg"
}
select_device() {
select_device()
{
local dev
local msg
[[ $1 == 'boot' ]] && msg="$_DevSelTitle for bootloader\n" || umount_dir $MNT
@ -121,7 +127,8 @@ select_device() {
return 0
}
confirm_mount() {
confirm_mount()
{
local part="$1"
local mount="$2"
local msg="Partition: $part\n"
@ -135,7 +142,8 @@ confirm_mount() {
return 0
}
check_cryptlvm() {
check_cryptlvm()
{
local dev=""
local part="$1"
local devs
@ -182,7 +190,8 @@ check_cryptlvm() {
fi
}
auto_partition() {
auto_partition()
{
local device="$1"
local size
size=$(lsblk -lno SIZE $device | awk 'NR == 1 {
@ -246,7 +255,8 @@ auto_partition() {
msgbox "$_PrepParts" "\nAuto partitioning complete.\n\n$(lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE $device)"
}
mount_partition() {
mount_partition()
{
local part="$1"
local mountp="${MNT}$2"
local fs
@ -267,7 +277,8 @@ mount_partition() {
return 0
}
find_partitions() {
find_partitions()
{
local str="$1"
local err=''
@ -300,7 +311,8 @@ find_partitions() {
return 0
}
setup_boot_device() {
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}"

View File

@ -8,23 +8,27 @@
# shellcheck disable=2154
chrun() {
chrun()
{
# run a shell command in the chroot dir $MNT
arch-chroot $MNT /bin/bash -c "$1"
}
json() {
json()
{
# get a value from http://api.ipstack.com in json format using my API key
# this includes: ip, geolocation, country name
curl -s "http://api.ipstack.com/$2" | python3 -c "import sys, json; print(json.load(sys.stdin)['$1'])"
}
src() {
src()
{
# source a file ($1), if it fails we die with an error message
. "$1" || { printf "\nFailed to source file %s\n" "$1"; die 1; }
}
ssd() {
ssd()
{
# returns 0 (true) when the device passed ($1) is NOT a rotational device
local dev=$1
dev=${dev#/dev/}
@ -32,7 +36,8 @@ ssd() {
[[ $(cat /sys/block/$dev/queue/rotational) -eq 0 ]] || return 1
}
die() {
die()
{
# die peacefully
local exitcode=0
(( $# == 0 )) || exitcode=$1
@ -52,13 +57,15 @@ die() {
exit $exitcode
}
sigint() {
sigint()
{
# used to trap SIGINT and cleanly exit the program
printf "\n** CTRL-C caught"
die 1
}
print4() {
print4()
{
# takes an arbitrary number of input fields and prints them out in fourths on separate lines
local str="$*"
if [[ ${#str} -gt $(( ${COLUMNS:-$(tput cols)} / 2 )) ]]; then
@ -87,14 +94,16 @@ print4() {
printf "%s\n" "$str"
}
oneshot() {
oneshot()
{
[[ -e /tmp/.ai_$1 || ! $(type $1) ]] && return 0
$1 || return 1
touch "/tmp/.ai_$1"
return 0
}
system_devices() {
system_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}')"
@ -105,7 +114,8 @@ system_devices() {
declare -grx SYS_DEVS IGNORE_DEV DEV_COUNT
}
system_identify() {
system_identify()
{
declare -g IS_64BIT=false
local efidir="/sys/firmware/efi"
@ -129,11 +139,13 @@ system_identify() {
SYS="BIOS"
fi
# shellcheck disable=2034
declare -g BT="$DIST Installer - $SYS (x86_64) - Version $VER"
return 0
}
system_checks() {
system_checks()
{
[[ $(whoami) == "root" ]] || { infobox "$_ErrTitle" "$_NotRoot\n$_Exit" && die 1; }
grep -qw 'lm' /proc/cpuinfo || { infobox "$_ErrTitle" "$_Not64Bit\n$_Exit" && die 1; }
@ -152,7 +164,8 @@ system_checks() {
return 0
}
preinstall_checks() {
preinstall_checks()
{
[[ $(lsblk -o MOUNTPOINT) =~ $MNT ]] || { msgbox "$_ErrTitle" "$_ErrNoMount"; export SELECTED=4; return 1; }
if [[ $# -eq 1 ]]; then
[[ $CONFIG_DONE == true ]] || { msgbox "$_ErrTitle" "$_ErrNoConfig"; export SELECTED=5; return 1; }
@ -160,7 +173,8 @@ preinstall_checks() {
return 0
}
echeck() {
echeck()
{
# return if the last process exited normally
local last_exit_code=$?
(( last_exit_code == 0 )) && return 0
@ -182,7 +196,8 @@ echeck() {
return 0
}
debug() {
debug()
{
set -x
exec 3>| $DBG
BASH_XTRACEFD=3
@ -196,7 +211,8 @@ debug() {
export DEBUG=true
}
umount_dir() {
umount_dir()
{
swapoff -a
[[ -d $1 ]] && umount -R $1 >/dev/null 2>&1
return 0