You've already forked al-installer
Split the large amount of varaible setup to a lib file
This commit is contained in:
@ -42,32 +42,34 @@ shim_secure_boot() {
|
||||
}
|
||||
|
||||
uefi_boot_fallback() {
|
||||
# some UEFI firmware is finicky and requires a specific folder in
|
||||
# /boot/efi/EFI/ and named 'boot', 'Boot', or 'BOOT'
|
||||
# copy the bootloaders efi stub to that directory as bootx64.efi
|
||||
# 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
|
||||
|
||||
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
|
||||
|
||||
[[ -d $esp/EFI/$default ]] && rm -f $esp/EFI/$default/* || mkdir -p $esp/EFI/$default
|
||||
local default
|
||||
default="$(find $esp/EFI/ -maxdepth 1 -mindepth 1 -name '[Bb][oO][oO][tT]' -type d)"
|
||||
[[ $default ]] && default="$(basename $default)" || default="boot"
|
||||
|
||||
if [[ $1 == 'syslinux' ]]; then
|
||||
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"
|
||||
# directory exists: remove everything inside, otherwise mkdir it
|
||||
[[ -d $esp/EFI/$default ]] && rm -rf $esp/EFI/$default/* || mkdir -p $esp/EFI/$default
|
||||
|
||||
# copy efi stub to the new default location
|
||||
if [[ $BOOTLDR == 'syslinux' ]]; then
|
||||
# syslinux requires the whole boot setup be copied, not just the stub
|
||||
cp -rf $esp/EFI/syslinux/* $esp/EFI/$default/
|
||||
cp -f $esp/EFI/syslinux/syslinux.efi $esp/EFI/$default/bootx64.efi
|
||||
elif [[ $BOOTLDR == 'grub' ]]; then
|
||||
# grub uses different names for the stub depending on architecture
|
||||
if [[ $IS_64BIT != true ]]; then
|
||||
local grub_file="grubia32.efi"
|
||||
local boot_file="bootia32.efi"
|
||||
else
|
||||
local grub_file="grubx64.efi"
|
||||
local boot_file="bootx64.efi"
|
||||
fi
|
||||
cp -f $esp/EFI/$boot_dir/$grub_file $esp/EFI/$default/$boot_file
|
||||
cp -f $esp/EFI/$DIST/$grub_file $esp/EFI/$default/$boot_file
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
@ -101,12 +103,8 @@ 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
|
||||
! [[ $ROOT_PART =~ /dev/mapper ]] && ROOT_PART_ID="PART$ROOT_PART_ID"
|
||||
|
||||
# create the boot entry configs
|
||||
mkdir -p $MNT/boot/loader/entries
|
||||
@ -118,7 +116,7 @@ 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
|
||||
@ -142,7 +140,6 @@ EOF
|
||||
}
|
||||
|
||||
prep_for_syslinux() {
|
||||
local ucode="$1"
|
||||
local cfgdir="$MNT/boot/syslinux"
|
||||
local cfgsrcdir="/usr/lib/syslinux/bios/"
|
||||
FILES[9]="/boot/syslinux/syslinux.cfg"
|
||||
@ -169,21 +166,19 @@ 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
|
||||
}
|
||||
|
||||
install_bootloader() {
|
||||
chroot_cmd "export PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/bin/core_perl"
|
||||
|
||||
# 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')"
|
||||
@ -191,21 +186,12 @@ install_bootloader() {
|
||||
ROOT_PART_ID="$ROOT_PART"
|
||||
fi
|
||||
|
||||
# needed for os-prober module to work properly in the chroot
|
||||
mkdir -p $MNT/run && mount --rbind /run $MNT/run/
|
||||
|
||||
# make sure efivarfs has been mounted and remove old boot entries
|
||||
if [[ $SYS == 'UEFI' ]]; then
|
||||
mount -o remount,rw -t efivarfs efivarfs $EFI >/dev/null 2>&1
|
||||
BCMDS[$BOOTLDR]="mount -o remount,rw -t efivarfs efivarfs $EFI; ${BCMDS[$BOOTLDR]}"
|
||||
|
||||
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
|
||||
fi
|
||||
# remove old UEFI boot entries
|
||||
[[ $SYS == 'UEFI' ]] && find $MNT${BMNTS[$SYS-$BOOTLDR]}/EFI/ -maxdepth 1 -mindepth 1 \
|
||||
-name '[aA][rR][cC][hH][lL]abs' -type d -exec rm -rf '{}' \; >/dev/null 2>&1
|
||||
|
||||
# sets up the bootloader config(s) and ${BCMDS[$BOOTLDR]}
|
||||
prep_for_$BOOTLDR "$UCODE"
|
||||
prep_for_$BOOTLDR
|
||||
|
||||
# run the bootloader command
|
||||
chroot_cmd "${BCMDS[$BOOTLDR]}" 2>$ERR
|
||||
|
@ -51,11 +51,11 @@ install_base() {
|
||||
sed -i 's/volatile/auto/g' $MNT/etc/systemd/journald.conf
|
||||
sed -i "s/# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/g" $MNT/etc/sudoers
|
||||
|
||||
# for virtual machines remove configs for xorg, these cause mouse issues
|
||||
if [[ $VM ]]; then
|
||||
# in a VM remove xorg configs, these cause issues
|
||||
rm -rf $MNT/etc/X11/xorg.conf.d
|
||||
elif [[ $(lspci | grep ' VGA ' | grep 'Intel') != "" ]]; then
|
||||
# setup xorg vsync config for intel graphics
|
||||
# xorg config for intel, this should never happen in a VM
|
||||
cat > $MNT/etc/X11/xorg.conf.d/20-intel.conf <<EOF
|
||||
Section "Device"
|
||||
Identifier "Intel Graphics"
|
||||
@ -71,11 +71,6 @@ EOF
|
||||
# copy CPU micro-code if set. manufacturer_ucode.img -> manufacturer-ucode.img
|
||||
[[ $UCODE ]] && cp -f $RUN/${UCODE/-/_} $MNT/boot/$UCODE
|
||||
|
||||
setup_configs
|
||||
return 0
|
||||
}
|
||||
|
||||
setup_configs() {
|
||||
# copy network settings
|
||||
cp -rf /etc/NetworkManager/system-connections $MNT/etc/NetworkManager/
|
||||
cp -f /etc/resolv.conf $MNT/etc/
|
||||
@ -124,7 +119,7 @@ EOF
|
||||
|
||||
create_user() {
|
||||
local _home="$MNT/home/$LIVE"
|
||||
local serve="$MNT/etc/systemd/system/getty@tty1.service.d"
|
||||
local service="$MNT/etc/systemd/system/getty@tty1.service.d"
|
||||
|
||||
# set root password
|
||||
chroot_cmd "echo 'root:$ROOT_PASS' | chpasswd"
|
||||
@ -138,29 +133,22 @@ create_user() {
|
||||
if [[ $LOGIN_TYPE == 'lightdm' ]]; then
|
||||
[[ $AUTOLOGIN == true ]] && groups="$groups,nopasswdlogin"
|
||||
rm -rf $_home/.{zprofile,xinitrc}
|
||||
rm -rf $serve
|
||||
rm -rf $service
|
||||
else
|
||||
if [[ $AUTOLOGIN == true ]]; then
|
||||
sed -i "s/${LIVE}/${NEWUSER}/g" $serve/autologin.conf
|
||||
sed -i "s/${LIVE}/${NEWUSER}/g" $service/autologin.conf
|
||||
else
|
||||
rm -rf $service
|
||||
fi
|
||||
sed -i "s/openbox-session/${LOGIN_WM}/g" $_home/.xinitrc
|
||||
sed -i '/archlabs-installer/d' $_home/.zprofile
|
||||
cat >> $_home/.zprofile << EOF
|
||||
[[ -z \$DISPLAY && \$XDG_VTNR -eq 1 ]] && exec startx -- vt1 &>/dev/null
|
||||
EOF
|
||||
sed -i 's|exec sudo archlabs-installer|exec startx -- vt1 &>/dev/null|' $_home/.zprofile
|
||||
fi
|
||||
|
||||
sed -i "s/${LIVE}/${NEWUSER}/g" $_home/.config/gtk-3.0/bookmarks
|
||||
sed -i "s/${LIVE}/${NEWUSER}/g" $_home/.mozilla/firefox/archlabs.default/prefs.js
|
||||
sed -i "s/${LIVE}/${NEWUSER}/g" $_home/.mozilla/firefox/archlabs.default/sessionstore.js
|
||||
sed -i "s/${LIVE}/${NEWUSER}/g" $_home/.config/gtk-3.0/bookmarks $_home/.mozilla/firefox/archlabs.default/{prefs,sessionstore}.js
|
||||
|
||||
if ! [[ $INSTALL_WMS =~ openbox ]]; then
|
||||
rm -rf $_home/.config/openbox
|
||||
elif ! [[ $INSTALL_WMS =~ bspwm ]]; then
|
||||
rm -rf $_home/.config/{bspwm,sxhkd}
|
||||
elif ! [[ $INSTALL_WMS =~ i3-gaps ]]; then
|
||||
rm -rf $_home/.config/i3
|
||||
fi
|
||||
! [[ $INSTALL_WMS =~ openbox ]] && rm -rf $_home/.config/{openbox}
|
||||
! [[ $INSTALL_WMS =~ bspwm ]] && rm -rf $_home/.config/{bspwm,sxhkd}
|
||||
! [[ $INSTALL_WMS =~ i3-gaps ]] && rm -rf $_home/.config/i3
|
||||
|
||||
chroot_cmd "mv -f /home/$LIVE /home/$NEWUSER"
|
||||
chroot_cmd "usermod -aG $groups $NEWUSER"
|
||||
@ -172,9 +160,7 @@ EOF
|
||||
|
||||
run_mkinitcpio() {
|
||||
# setup a keyfile for LUKS.. Only when choosing grub and system is UEFI
|
||||
if [[ $LUKS -eq 1 && $LVM != 1 && $SYS == 'UEFI' && $BOOTLDR == 'grub' ]]; then
|
||||
luks_keyfile
|
||||
fi
|
||||
[[ $LUKS -eq 1 && $LVM != 1 && $SYS == 'UEFI' && $BOOTLDR == 'grub' ]] && luks_keyfile
|
||||
|
||||
# new hooks needed in /etc/mkinitcpio.conf if we used LUKS and/or LVM
|
||||
local add
|
||||
@ -182,6 +168,7 @@ run_mkinitcpio() {
|
||||
(( 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
|
||||
|
||||
tput civis
|
||||
@ -210,27 +197,25 @@ update_system() {
|
||||
fi
|
||||
|
||||
# for gnome and cinnamon we don't need the xfce provided stuff
|
||||
if [[ $INSTALL_WMS == 'gnome' || $INSTALL_WMS == 'cinnamon' ]]; then
|
||||
rmpkg="$(pacman -Qssq 'xfce4*' 2>/dev/null)"
|
||||
fi
|
||||
[[ $INSTALL_WMS == 'gnome' || $INSTALL_WMS == 'cinnamon' ]] && rmpkg="$(pacman -Qssq 'xfce4*' 2>/dev/null)"
|
||||
|
||||
if [[ $BOOTLDR != 'grub' ]]; then
|
||||
rmpkg="$rmpkg grub"
|
||||
rm -f $MNT/etc/default/grub
|
||||
find $MNT/boot/ -name 'grub*' -exec rm -rf '{}' \; >/dev/null 2>&1
|
||||
elif [[ $BOOTLDR != 'syslinux' ]]; then
|
||||
find $MNT/boot/ -name 'syslinux*' -exec rm -rf '{}' \; >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
local update="pacman -Syyu --noconfirm"
|
||||
local network="pacman -S iputils --noconfirm"
|
||||
local install="pacman -S $inpkg $EXTRA_PACKAGES --needed --noconfirm"
|
||||
local remove="pacman -Rs $rmpkg --noconfirm"
|
||||
|
||||
chroot_cmd "$update; $network; $install; $remove" 2>/dev/null
|
||||
chroot_cmd "pacman -Syyu --noconfirm; pacman -S iputils --noconfirm; $install; $remove" 2>/dev/null
|
||||
|
||||
if [[ $EXTRA_PACKAGES =~ 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
|
||||
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
|
||||
fi
|
||||
|
||||
if [[ $INSTALL_WMS =~ dwm ]]; then
|
||||
|
Reference in New Issue
Block a user