You've already forked al-installer
Combine mount and partition lib files, and other minor changes
This commit is contained in:
@ -35,7 +35,6 @@ select_boot_setup() {
|
||||
|
||||
shim_secure_boot() {
|
||||
# still a W.I.P
|
||||
|
||||
local shim_file="shim64.efi"
|
||||
[[ $IS_64BIT != true ]] && shim_file="shim.efi"
|
||||
efibootmgr -c -w -L $DIST -d $BOOT_DEVICE -p $BOOT_PART_NUM -l ${MNT}${BMNTS[$SYS-$BOOTLDR]}/$shim_file
|
||||
@ -47,21 +46,20 @@ uefi_boot_fallback() {
|
||||
# /boot/efi/EFI/ and named 'boot', 'Boot', or 'BOOT'
|
||||
# copy the bootloaders efi stub to that directory as bootx64.efi
|
||||
|
||||
local boot_dir="$DIST"
|
||||
[[ $BOOTLDR == 'syslinux' ]] && boot_dir="syslinux"
|
||||
|
||||
local default="boot"
|
||||
local esp="${MNT}${BMNTS[$SYS-$BOOTLDR]}"
|
||||
for i in $(find "$esp/EFI/" -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do
|
||||
grep -qi "boot" <<< "$(basename $i)" && { default="$(basename $i)"; break; }
|
||||
done
|
||||
|
||||
if [[ -d $esp/EFI/$default ]]; then
|
||||
rm -f $esp/EFI/$default/*
|
||||
else
|
||||
mkdir -p $esp/EFI/$default
|
||||
fi
|
||||
[[ -d $esp/EFI/$default ]] && rm -f $esp/EFI/$default/* || mkdir -p $esp/EFI/$default
|
||||
|
||||
if [[ $1 == 'syslinux' ]]; then
|
||||
cp -rf $esp/EFI/$1/* $esp/EFI/$default/
|
||||
cp -f $esp/EFI/$1/syslinux.efi $esp/EFI/$default/bootx64.efi
|
||||
cp -rf $esp/EFI/$boot_dir/* $esp/EFI/$default/
|
||||
cp -f $esp/EFI/$boot_dir/syslinux.efi $esp/EFI/$default/bootx64.efi
|
||||
else
|
||||
local grub_file="grubx64.efi"
|
||||
local boot_file="bootx64.efi"
|
||||
@ -69,7 +67,7 @@ uefi_boot_fallback() {
|
||||
local grub_file="grubia32.efi"
|
||||
local boot_file="bootia32.efi"
|
||||
fi
|
||||
cp -f $esp/EFI/$1/$grub_file $esp/EFI/$default/$boot_file
|
||||
cp -f $esp/EFI/$boot_dir/$grub_file $esp/EFI/$default/$boot_file
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@ -105,6 +103,11 @@ prep_for_grub() {
|
||||
prep_for_systemd-boot() {
|
||||
local ucode="$1"
|
||||
|
||||
# no LVM then systemd-boot uses PARTUUID
|
||||
if ! [[ $ROOT_PART =~ /dev/mapper ]]; then
|
||||
ROOT_PART_ID="PART$ROOT_PART_ID"
|
||||
fi
|
||||
|
||||
# create the boot entry configs
|
||||
mkdir -p $MNT/boot/loader/entries
|
||||
cat > $MNT/boot/loader/loader.conf << EOF
|
||||
@ -112,9 +115,10 @@ default $DIST
|
||||
timeout 5
|
||||
editor no
|
||||
EOF
|
||||
cat > $MNT/boot/loader/entries/${DIST}.conf << EOF
|
||||
|
||||
cat > $MNT/boot/loader/entries/${DIST}.conf << EOF
|
||||
title $DIST Linux
|
||||
linux /vmlinuz-${KERNEL}$([[ $ucode ]] && echo -en "\ninitrd $ucode")
|
||||
linux /vmlinuz-${KERNEL}$([[ $ucode ]] && echo -en "\ninitrd /$ucode")
|
||||
initrd /initramfs-$KERNEL.img
|
||||
options root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && echo -n "$LUKS_DEV")rw
|
||||
EOF
|
||||
@ -165,14 +169,14 @@ MENU LABEL $DIST Linux
|
||||
LINUX ../vmlinuz-$KERNEL
|
||||
APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && echo -n "$LUKS_DEV ")rw
|
||||
INITRD ../initramfs-$KERNEL.img
|
||||
$([[ $ucode ]] && echo -en "\nINITRD ..$ucode")
|
||||
$([[ $ucode ]] && echo -en "\nINITRD ../$ucode")
|
||||
|
||||
LABEL ${DIST}fallback
|
||||
MENU LABEL $DIST Linux Fallback
|
||||
LINUX ../vmlinuz-$KERNEL
|
||||
APPEND root=$ROOT_PART_ID $([[ $LUKS_DEV ]] && echo -n "$LUKS_DEV ")rw
|
||||
INITRD ../initramfs-$KERNEL-fallback.img
|
||||
$([[ $ucode ]] && echo -en "\nINITRD ..$ucode")
|
||||
$([[ $ucode ]] && echo -en "\nINITRD ../$ucode")
|
||||
EOF
|
||||
return 0
|
||||
}
|
||||
@ -180,50 +184,34 @@ EOF
|
||||
install_bootloader() {
|
||||
chroot_cmd "export PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/bin/core_perl"
|
||||
|
||||
# if not on an LVM we can use the UUID for booting
|
||||
# not an LVM we can use the UUID for booting otherwise use the partition label
|
||||
if ! [[ $ROOT_PART =~ /dev/mapper ]]; then
|
||||
ROOT_PART_ID="UUID=$(blkid -s PARTUUID $ROOT_PART | sed 's/.*=//g; s/"//g')"
|
||||
[[ $BOOTLDR == 'systemd-boot' ]] && ROOT_PART_ID="PART$ROOT_PART_ID"
|
||||
else
|
||||
# for LVM use the partition name eg. /dev/mapper/cryptroot
|
||||
ROOT_PART_ID="$ROOT_PART"
|
||||
fi
|
||||
|
||||
# needed for os-prober module to work properly in the chroot
|
||||
mkdir -p $MNT/{dev,sys,proc,run/udev}
|
||||
mount remount,rw -t proc proc $MNT/proc
|
||||
mount remount,rw -t sysfs sys $MNT/sys
|
||||
mount --bind /dev $MNT/dev
|
||||
mount remount,rw -t tmpfs tmpfs $MNT/run
|
||||
mount --bind /run/udev $MNT/run/udev
|
||||
# BCMDS[$BOOTLDR]="mkdir -p /run/udev && mount --bind /run/udev /run/udev ; ${BCMDS[$BOOTLDR]}"
|
||||
mkdir -p $MNT/run && mount --rbind /run $MNT/run/
|
||||
|
||||
# make sure efivarfs has been mounted and remove old boot entries
|
||||
if [[ $SYS == 'UEFI' ]]; then
|
||||
# make sure efivarfs has been mounted
|
||||
mount -o remount,rw -t efivarfs efivarfs $EFI >/dev/null 2>&1
|
||||
BCMDS[$BOOTLDR]="mount -o remount,rw -t efivarfs efivarfs $EFI; ${BCMDS[$BOOTLDR]}"
|
||||
|
||||
# remove old boot entries
|
||||
local esp="$MNT/boot/efi/EFI/"
|
||||
[[ ! -d $MNT/boot/efi/EFI && -d $MNT/boot/EFI ]] && esp="$MNT/boot/EFI/"
|
||||
find $esp -maxdepth 1 -mindepth 1 \
|
||||
\( -name '[aA][rR][cC][hH][lL]abs' -o -name '[Bb][oO][oO][tT]' \) \
|
||||
-type d -exec rm -rf '{}' \; >/dev/null 2>&1
|
||||
find $esp -maxdepth 1 -mindepth 1 \( -name '[aA][rR][cC][hH][lL]abs' -o -name '[Bb][oO][oO][tT]' \) -type d -exec rm -rf '{}' \; >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# sets up the bootloader config(s) and ${BCMDS[$BOOTLDR]}
|
||||
prep_for_$BOOTLDR "$UCODE"
|
||||
|
||||
# run the bootloader command
|
||||
chroot_cmd "${BCMDS[$BOOTLDR]}"
|
||||
chroot_cmd "${BCMDS[$BOOTLDR]}" 2>$ERR
|
||||
check_for_errors "${BCMDS[$BOOTLDR]}"
|
||||
|
||||
if [[ $SYS == 'UEFI' && $BOOTLDR =~ (grub|syslinux) ]]; then
|
||||
local boot_dir="$DIST"
|
||||
[[ $BOOTLDR == 'syslinux' ]] && boot_dir="syslinux"
|
||||
|
||||
# copy efi stub to generic catch all
|
||||
uefi_boot_fallback "$boot_dir"
|
||||
fi
|
||||
# copy efi stub to generic catch all
|
||||
[[ $SYS == 'UEFI' && $BOOTLDR =~ (grub|syslinux) ]] && uefi_boot_fallback
|
||||
return 0
|
||||
}
|
@ -42,10 +42,10 @@ install_base() {
|
||||
rsync -ah --info=progress2 /run/archiso/sfs/airootfs/ $MNT/
|
||||
|
||||
# remove archiso init files and clean up install files
|
||||
find $MNT/usr/lib/initcpio -name 'archiso*' -type f -exec rm '{}' \;
|
||||
rm -f $MNT/etc/mkinitcpio-archiso.conf
|
||||
rm -rf $MNT/etc/sudoers.d/g_wheel
|
||||
rm -f $MNT/etc/mkinitcpio-archiso.conf
|
||||
rm -f $MNT/etc/polkit-1/rules.d/49-nopasswd_global.rules
|
||||
find $MNT/usr/lib/initcpio -name 'archiso*' -type f -exec rm '{}' \;
|
||||
|
||||
# cleanup system permissions
|
||||
sed -i 's/volatile/auto/g' $MNT/etc/systemd/journald.conf
|
||||
@ -65,17 +65,11 @@ EndSection
|
||||
EOF
|
||||
fi
|
||||
|
||||
# if not installing the lts kernel, copy the kernel image
|
||||
if [[ $KERNEL != 'linux-lts' ]]; then
|
||||
cp -f /run/archiso/bootmnt/arch/boot/x86_64/vmlinuz $MNT/boot/vmlinuz-linux
|
||||
fi
|
||||
# copy the kernel image fofr the regular kernel
|
||||
[[ $KERNEL != 'linux-lts' ]] && cp -f $RUN/x86_64/vmlinuz $MNT/boot/vmlinuz-linux
|
||||
|
||||
# CPU micro-code
|
||||
if [[ $UCODE == "/intel-ucode.img" ]]; then
|
||||
cp -f /run/archiso/bootmnt/arch/boot/intel_ucode.img $MNT/boot/intel_ucode.img
|
||||
else
|
||||
cp -f /run/archiso/bootmnt/arch/boot/amd_ucode.img $MNT/boot/amd_ucode.img
|
||||
fi
|
||||
# copy CPU micro-code if set. manufacturer_ucode.img -> manufacturer-ucode.img
|
||||
[[ $UCODE ]] && cp -f $RUN/${UCODE/-/_} $MNT/boot/$UCODE
|
||||
|
||||
setup_configs
|
||||
return 0
|
||||
@ -182,10 +176,10 @@ run_mkinitcpio() {
|
||||
luks_keyfile
|
||||
fi
|
||||
|
||||
# new HOOKS needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM
|
||||
# new hooks needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM
|
||||
local add
|
||||
(( LVM == 1 )) && add="lvm2"
|
||||
(( LUKS == 1 )) && add="encrypt$([[ $add != "" ]] && echo -n " $add")"
|
||||
(( LUKS == 1 )) && add="encrypt$([[ $add ]] && echo -n " $add")"
|
||||
|
||||
local conf="$MNT/etc/mkinitcpio.conf"
|
||||
sed -i "s/block filesystems/block ${add} filesystems ${MKINIT_HOOKS}/g" $conf
|
||||
@ -231,7 +225,7 @@ update_system() {
|
||||
local install="pacman -S $inpkg $EXTRA_PACKAGES --needed --noconfirm"
|
||||
local remove="pacman -Rs $rmpkg --noconfirm"
|
||||
|
||||
chroot_cmd "$update; $network; $install; $remove"
|
||||
chroot_cmd "$update; $network; $install; $remove" 2>/dev/null
|
||||
|
||||
if [[ $EXTRA_PACKAGES =~ neovim ]]; then
|
||||
mkdir -p $MNT/home$LIVE/.config/nvim
|
||||
|
305
src/lib/mount.sh
305
src/lib/mount.sh
@ -6,6 +6,311 @@
|
||||
# this file is not meant to be run directly
|
||||
# sourcing this file in a non bash shell is not advised
|
||||
|
||||
########################################################
|
||||
## Partition functions ##
|
||||
########################################################
|
||||
|
||||
format() {
|
||||
infobox "$_FSTitle" "\nFormatting: $1\n\nCommand: ${FS_CMDS[$2]}\n" 0
|
||||
${FS_CMDS[$2]} $1 >/dev/null 2>$ERR
|
||||
check_for_errors "${FS_CMDS[$2]} $1"
|
||||
}
|
||||
|
||||
decr_count() {
|
||||
# remove a partition from the dialog list and decrement the number partitions left
|
||||
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
|
||||
check_for_errors "fallocate -l $SWAP_SIZE $1"
|
||||
chmod 600 $1 2>$ERR
|
||||
check_for_errors "chmod 600 $1"
|
||||
fi
|
||||
mkswap $1 >/dev/null 2>$ERR
|
||||
check_for_errors "mkswap $1"
|
||||
swapon $1 >/dev/null 2>$ERR
|
||||
check_for_errors "swapon $1"
|
||||
return 0
|
||||
}
|
||||
|
||||
mount_partition() {
|
||||
local part="$1"
|
||||
local mount="${MNT}$2"
|
||||
local fs="$(lsblk -lno FSTYPE $part)"
|
||||
|
||||
mkdir -p "$mount"
|
||||
|
||||
if [[ ${FS_OPTS[$fs]} != "" && $part != "$BOOT_PART" ]] && select_mount_opts "$part" "$fs"; then
|
||||
mount -o $MNT_OPTS $part "$mount" 2>$ERR
|
||||
check_for_errors "mount -o $MNT_OPTS $part $mount"
|
||||
else
|
||||
mount $part "$mount" 2>$ERR
|
||||
check_for_errors "mount $part $mount"
|
||||
fi
|
||||
|
||||
confirm_mount $part "$mount" || return 1
|
||||
check_cryptlvm "$part"
|
||||
return 0
|
||||
}
|
||||
|
||||
confirm_mount() {
|
||||
local part="$1"
|
||||
local mount="$2"
|
||||
|
||||
if [[ $mount == "$MNT" ]]; then
|
||||
local msg="Partition: $part\nMountpoint: / (root)"
|
||||
else
|
||||
local msg="Partition: $part\nMountpoint: ${mount#$MNT}"
|
||||
fi
|
||||
|
||||
# partition failed to mount properly
|
||||
if ! [[ $(mount) =~ "$mount" ]]; then
|
||||
infobox "$_MntTitle" "$_MntFail\n$msg\n" 1
|
||||
return 1
|
||||
else
|
||||
# mount was successful
|
||||
infobox "$_MntTitle" "$_MntSucc\n$msg\n" 1
|
||||
decr_count "$part"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
find_partitions() {
|
||||
local str="$1"
|
||||
local err='NONE'
|
||||
|
||||
# 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 != 'NONE' ]]; then
|
||||
msgbox "$_ErrTitle" "$err"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
check_cryptlvm() {
|
||||
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=1
|
||||
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=1
|
||||
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=1
|
||||
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=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
auto_partition() {
|
||||
local device="$1"
|
||||
|
||||
# confirm or bail
|
||||
yesno "$_PrepParts" "$_PartBody1 $device $_PartBody2" || return 0
|
||||
infobox "$_PrepParts" "\nAuto partitioning device: $device\n" 0
|
||||
|
||||
swapoff -a # make sure swap is disabled in case the device was 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
|
||||
|
||||
# make sure we have the correct device table for the system type, gpt or msdos
|
||||
local newtable="gpt"
|
||||
local table="$(awk '/Table:/ {print $3}' <<< "$dev_info")"
|
||||
[[ $SYS == BIOS ]] && newtable="msdos"
|
||||
|
||||
# if the current device table isn't correct run mklabel
|
||||
if [[ $table != "$newtable" ]]; then
|
||||
parted -s $device mklabel $newtable >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# when device contains the string 'nvme' then add 'p' before the part number
|
||||
local nvme=""
|
||||
[[ $device =~ nvme ]] && nvme="p"
|
||||
|
||||
local part_num=1
|
||||
BOOT_PART="$device${nvme}$part_num" # set the boot partition label to the first partition
|
||||
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
parted -s $device mkpart primary ext4 1MiB 513MiB >/dev/null 2>&1
|
||||
mkfs.ext4 -q $BOOT_PART >/dev/null 2>&1
|
||||
else
|
||||
parted -s $device mkpart ESP fat32 1MiB 513MiB >/dev/null 2>&1
|
||||
mkfs.vfat -F32 $BOOT_PART >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
(( part_num++ )) # increment the partition number
|
||||
BOOT_DEVICE="$device" # only grub on BIOS systems uses this
|
||||
ROOT_PART="${device}${nvme}$part_num" # set root partition label to the second partition
|
||||
|
||||
parted -s $device mkpart primary ext4 513MiB 100% >/dev/null 2>&1
|
||||
mkfs.ext4 -q $ROOT_PART >/dev/null 2>&1
|
||||
|
||||
tput civis
|
||||
sleep 0.5 # slow the process down, otherwise lsblk output can be wrong for some things
|
||||
|
||||
echo -e "\nAuto partitioning complete.\n" > /tmp/.devlist
|
||||
lsblk $device -o NAME,MODEL,TYPE,FSTYPE,SIZE >> /tmp/.devlist
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $_PrepParts " --textbox /tmp/.devlist 0 0
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_boot_device() {
|
||||
# set BOOT_DEVICE for syslinux on UEFI and grub on BIOS
|
||||
if [[ $BOOT_PART =~ nvme ]]; then
|
||||
BOOT_DEVICE="${BOOT_PART%p[1-9]}"
|
||||
else
|
||||
BOOT_DEVICE="${BOOT_PART%[1-9]}"
|
||||
fi
|
||||
|
||||
BOOT_PART_NUM="${BOOT_PART: -1}"
|
||||
|
||||
# setup the needed partition flags for boot on both system types
|
||||
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
|
||||
}
|
||||
|
||||
show_devices() {
|
||||
tput civis
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk "!/$IGNORE_DEV/"' && /disk|part|lvm|crypt|NAME/ {print $0}' > /tmp/.devlist
|
||||
else
|
||||
lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk '/disk|part|lvm|crypt|NAME/ {print $0}' > /tmp/.devlist
|
||||
fi
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $_PrepShowDev " --textbox /tmp/.devlist 0 0
|
||||
}
|
||||
|
||||
select_device() {
|
||||
local dev
|
||||
local msg
|
||||
if [[ $1 == 'boot' ]]; then
|
||||
msg="$_DevSelTitle for bootloader\n"
|
||||
else
|
||||
unmount_partitions
|
||||
fi
|
||||
|
||||
if (( DEV_COUNT == 1 )) && [[ $SYS_DEVS ]]; then
|
||||
DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")"
|
||||
msg="\nOnly one device available$([[ $1 == 'boot' ]] && echo -n " 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' ]] && echo -n " 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
|
||||
}
|
||||
|
||||
edit_partitions() {
|
||||
local device="$1"
|
||||
if [[ $device == "" ]]; then
|
||||
select_device 'root' || return 1
|
||||
device="$DEVICE"
|
||||
fi
|
||||
|
||||
tput civis
|
||||
local choice
|
||||
choice="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_PartTitle " --menu "$_PartBody" 0 0 0 "$_PartAuto" "-" \
|
||||
$( ([[ $DISPLAY ]] && hash gparted >/dev/null 2>&1) && echo -n "gparted -") "cfdisk" "-"\
|
||||
"parted" "-" "$_PartWipe" "-")"
|
||||
[[ $? != 0 || $choice == "" ]] && return 1
|
||||
|
||||
clear
|
||||
tput cnorm
|
||||
|
||||
if [[ $choice != "$_PartWipe" && $choice != "$_PartAuto" ]]; then
|
||||
$choice $device
|
||||
elif [[ $choice == "$_PartWipe" ]]; then
|
||||
yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2" && { clear; wipe -Ifrev $device; }
|
||||
edit_partitions $device
|
||||
else
|
||||
# if auto_partition fails we need to re-initialize the variables, just to be sure
|
||||
auto_partition $device || { initialize_variables; return 1; }
|
||||
fi
|
||||
}
|
||||
|
||||
########################################################
|
||||
## Mount functions ##
|
||||
########################################################
|
||||
|
||||
mount_main() {
|
||||
msgbox "$_PrepMount" "$_WarnMount"
|
||||
lvm_detect
|
||||
|
@ -1,293 +0,0 @@
|
||||
#!/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
|
||||
|
||||
format() {
|
||||
infobox "$_FSTitle" "\nFormatting: $1\n\nCommand: ${FS_CMDS[$2]}\n" 0
|
||||
${FS_CMDS[$2]} $1 >/dev/null 2>$ERR
|
||||
check_for_errors "${FS_CMDS[$2]} $1"
|
||||
}
|
||||
|
||||
decr_count() {
|
||||
# remove a partition from the dialog list and decrement the number partitions left
|
||||
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() {
|
||||
[[ $1 == "$MNT/swapfile" ]] && { fallocate -l $SWAP_SIZE $1; chmod 600 $1; }
|
||||
mkswap $1 >/dev/null 2>&1
|
||||
swapon $1 >/dev/null 2>&1
|
||||
return 0
|
||||
}
|
||||
|
||||
mount_partition() {
|
||||
local part="$1"
|
||||
local mount="${MNT}$2"
|
||||
local fs="$(lsblk -lno FSTYPE $part)"
|
||||
|
||||
mkdir -p "$mount"
|
||||
|
||||
if [[ ${FS_OPTS[$fs]} != "" && $part != "$BOOT_PART" ]] && select_mount_opts "$part" "$fs"; then
|
||||
mount -o $MNT_OPTS $part "$mount" 2>$ERR
|
||||
check_for_errors "mount -o $MNT_OPTS $part $mount"
|
||||
else
|
||||
mount $part "$mount" 2>$ERR
|
||||
check_for_errors "mount $part $mount"
|
||||
fi
|
||||
|
||||
confirm_mount $part "$mount" || return 1
|
||||
check_cryptlvm "$part"
|
||||
return 0
|
||||
}
|
||||
|
||||
confirm_mount() {
|
||||
local part="$1"
|
||||
local mount="$2"
|
||||
|
||||
if [[ "$mount" == "$MNT" ]]; then
|
||||
local msg="Partition: $part\nMountpoint: / (root)"
|
||||
else
|
||||
local msg="Partition: $part\nMountpoint: ${mount#$MNT}"
|
||||
fi
|
||||
|
||||
# partition failed to mount properly
|
||||
if ! grep -q "$mount" <<< "$(mount)"; then
|
||||
infobox "$_MntTitle" "$_MntFail\n$msg\n" 1
|
||||
return 1
|
||||
else
|
||||
# mount was successful
|
||||
infobox "$_MntTitle" "$_MntSucc\n$msg\n" 1
|
||||
decr_count "$part"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
find_partitions() {
|
||||
local str="$1"
|
||||
local err='NONE'
|
||||
|
||||
# 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 != 'NONE' ]]; then
|
||||
msgbox "$_ErrTitle" "$err"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
check_cryptlvm() {
|
||||
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=1
|
||||
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=1
|
||||
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=1
|
||||
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=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
auto_partition() {
|
||||
local device="$1"
|
||||
|
||||
# confirm or bail
|
||||
yesno "$_PrepParts" "$_PartBody1 $device $_PartBody2" || return 0
|
||||
infobox "$_PrepParts" "\nAuto partitioning device: $device\n" 0
|
||||
|
||||
swapoff -a # make sure swap is disabled in case the device was 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
|
||||
|
||||
# make sure we have the correct device table for the system type, gpt or msdos
|
||||
local newtable="gpt"
|
||||
local table="$(awk '/Table:/ {print $3}' <<< "$dev_info")"
|
||||
[[ $SYS == BIOS ]] && newtable="msdos"
|
||||
|
||||
# if the current device table isn't correct run mklabel
|
||||
if [[ $table != "$newtable" ]]; then
|
||||
parted -s $device mklabel $newtable >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
# when device contains the string 'nvme' then add 'p' before the part number
|
||||
local nvme=""
|
||||
[[ $device =~ nvme ]] && nvme="p"
|
||||
|
||||
local part_num=1
|
||||
BOOT_PART="$device${nvme}$part_num" # set the boot partition label to the first partition
|
||||
|
||||
if [[ $SYS == "BIOS" ]]; then
|
||||
parted -s $device mkpart primary ext4 1MiB 513MiB >/dev/null 2>&1
|
||||
mkfs.ext4 -q $BOOT_PART >/dev/null 2>&1
|
||||
else
|
||||
parted -s $device mkpart ESP fat32 1MiB 513MiB >/dev/null 2>&1
|
||||
mkfs.vfat -F32 $BOOT_PART >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
(( part_num++ )) # increment the partition number
|
||||
BOOT_DEVICE="$device" # only grub on BIOS systems uses this
|
||||
ROOT_PART="${device}${nvme}$part_num" # set root partition label to the second partition
|
||||
|
||||
parted -s $device mkpart primary ext4 514MiB 100% >/dev/null 2>&1
|
||||
mkfs.ext4 -q $ROOT_PART >/dev/null 2>&1
|
||||
|
||||
tput civis
|
||||
sleep 0.5 # slow the process down, otherwise lsblk output can be wrong for some things
|
||||
|
||||
echo -e "\nAuto partitioning complete.\n" > /tmp/.devlist
|
||||
lsblk $device -o NAME,MODEL,TYPE,FSTYPE,SIZE >> /tmp/.devlist
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $_PrepParts " --textbox /tmp/.devlist 0 0
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_boot_device() {
|
||||
# set BOOT_DEVICE for syslinux on UEFI and grub on BIOS
|
||||
if [[ $BOOT_PART =~ nvme ]]; then
|
||||
BOOT_DEVICE="${BOOT_PART%p[1-9]}"
|
||||
else
|
||||
BOOT_DEVICE="${BOOT_PART%[1-9]}"
|
||||
fi
|
||||
|
||||
BOOT_PART_NUM="${BOOT_PART: -1}"
|
||||
|
||||
# setup the needed partition flags for boot on both system types
|
||||
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
|
||||
}
|
||||
|
||||
show_devices() {
|
||||
tput civis
|
||||
if [[ $IGNORE_DEV != "" ]]; then
|
||||
lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk "!/$IGNORE_DEV/"' && /disk|part|lvm|crypt|NAME/ {print $0}' > /tmp/.devlist
|
||||
else
|
||||
lsblk -o NAME,MODEL,TYPE,FSTYPE,SIZE,MOUNTPOINT |
|
||||
awk '/disk|part|lvm|crypt|NAME/ {print $0}' > /tmp/.devlist
|
||||
fi
|
||||
dialog --cr-wrap --backtitle "$BT" --title " $_PrepShowDev " --textbox /tmp/.devlist 0 0
|
||||
}
|
||||
|
||||
select_device() {
|
||||
local dev
|
||||
local msg
|
||||
if [[ $1 == 'boot' ]]; then
|
||||
msg="$_DevSelTitle for bootloader\n"
|
||||
else
|
||||
unmount_partitions
|
||||
fi
|
||||
|
||||
if (( DEV_COUNT == 1 )) && [[ $SYS_DEVS ]]; then
|
||||
DEVICE="$(awk '{print $1}' <<< "$SYS_DEVS")"
|
||||
msg="\nOnly one device available$([[ $1 == 'boot' ]] && echo -n " 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' ]] && echo -n " 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
|
||||
}
|
||||
|
||||
edit_partitions() {
|
||||
local device="$1"
|
||||
if [[ $device == "" ]]; then
|
||||
select_device 'root' || return 1
|
||||
device="$DEVICE"
|
||||
fi
|
||||
|
||||
tput civis
|
||||
local choice
|
||||
choice="$(dialog --cr-wrap --stdout --backtitle "$BT" \
|
||||
--title " $_PartTitle " --menu "$_PartBody" 0 0 0 "$_PartAuto" "-" \
|
||||
$( ([[ $DISPLAY ]] && hash gparted >/dev/null 2>&1) && echo -n "gparted -") "cfdisk" "-"\
|
||||
"parted" "-" "$_PartWipe" "-")"
|
||||
[[ $? != 0 || $choice == "" ]] && return 1
|
||||
|
||||
clear
|
||||
tput cnorm
|
||||
|
||||
if [[ $choice != "$_PartWipe" && $choice != "$_PartAuto" ]]; then
|
||||
$choice $device
|
||||
elif [[ $choice == "$_PartWipe" ]]; then
|
||||
yesno "$_PartWipe" "$_PartBody1 $device $_PartWipeBody2" && { clear; wipe -Ifrev $device; }
|
||||
edit_partitions $device
|
||||
else
|
||||
# if auto_partition fails we need to re-initialize the variables, just to be sure
|
||||
auto_partition $device || { initialize_variables; return 1; }
|
||||
fi
|
||||
}
|
@ -60,17 +60,16 @@ check_for_errors() {
|
||||
|
||||
local msg="\nThe command exited abnormally: $1"
|
||||
|
||||
# get error message from logfile and attempt to format slightly better for humans
|
||||
# strip any non-printable characters, escape sequences, and other known messy text
|
||||
# get error message from logfile and strip any non-printable characters,
|
||||
# escape sequences, and other messy text
|
||||
local err
|
||||
err="$(sed 's/[^[:print:]]//g; s/\[[0-9\;:]*\?m//g; s/==> //g; s/] ERROR:/]\nERROR:/g' "$ERR")"
|
||||
[[ $err != "" ]] && msgbox "$_ErrTitle" "$msg\n\nWith the following error message:\n\n$err"
|
||||
|
||||
|
||||
msg="$([[ $err == "" ]] && echo -n "$msg")\n$_ErrChoice"
|
||||
if [[ -e /tmp/debug-log && $TERM == 'linux' ]]; then
|
||||
msg="$([[ $err == "" ]] && echo -n "$msg")\n$_ErrChoiceConsole"
|
||||
yesno "$_ErrTitle" "$msg" "View Log" "Continue" && { less /tmp/debug-log; die 0; }
|
||||
yesno "$_ErrTitle" "$msg" "Exit & Open Log" "Ignore & Continue" && { less /tmp/debug-log; die 0; }
|
||||
else
|
||||
yesno "$_ErrTitle" "$msg" "Exit & Shutdown" "Ignore & Continue" && die 'shutdown'
|
||||
fi
|
||||
@ -80,9 +79,13 @@ check_for_errors() {
|
||||
|
||||
check_install_ready() {
|
||||
if ! [[ $(lsblk -o MOUNTPOINT) =~ $MNT ]]; then
|
||||
msgbox "$_ErrTitle" "$_ErrNoMount"; return 4
|
||||
msgbox "$_ErrTitle" "$_ErrNoMount"
|
||||
MENU_HIGHLIGHT=4
|
||||
return 1
|
||||
elif [[ $CONFIG_DONE != true ]]; then
|
||||
msgbox "$_ErrTitle" "$_ErrNoConfig"; return 5
|
||||
msgbox "$_ErrTitle" "$_ErrNoConfig"
|
||||
MENU_HIGHLIGHT=5
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@ -139,7 +142,7 @@ die() {
|
||||
tput cnorm
|
||||
unmount_partitions
|
||||
pgrep -f "$TERM_CMD -e tail" && pkill -f "$TERM_CMD -e tail"
|
||||
[[ $1 =~ [0-9] ]] && exit $1 || systemctl $1
|
||||
[[ $1 =~ [0-9] ]] && exit $1 || $1
|
||||
}
|
||||
|
||||
sigint() {
|
||||
|
Reference in New Issue
Block a user