diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d6346e0 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +.PHONY: all +all: test + +test: + shellcheck --check-sourced --external-sources de-p1st-installer.sh diff --git a/de-p1st-installer.sh b/de-p1st-installer.sh index 6d211da..f8936f1 100755 --- a/de-p1st-installer.sh +++ b/de-p1st-installer.sh @@ -1,14 +1,33 @@ #!/bin/bash +# Exit on error. set -e +# Exit on undefined variable reference. set -u -# load config -source /etc/de-p1st-installer/installer.cfg +# Check if run from installation or locally (development setup). +# -> Print commands before they get executed (set -v). +# -> Determine library directory. +script_dir="$(dirname "${BASH_SOURCE[0]}")" || exit 1 +if [ "${script_dir}" = '/usr/bin' ]; then + # This script has been installed. + lib_dir='/usr/lib/de-p1st-installer' +else + # This script is run locally (development setup). + lib_dir='./lib' + set -v +fi -# load functions -source /usr/lib/de-p1st-installer/util.sh -source /usr/lib/de-p1st-installer/user-input.sh -source /usr/lib/de-p1st-installer/block-device.sh +# Source library files. +# shellcheck source=lib/util.sh +source "${lib_dir}"/util.sh +# shellcheck source=lib/user-input.sh +source "${lib_dir}"/user-input.sh +# shellcheck source=lib/block-device.sh +source "${lib_dir}"/block-device.sh + +# Source the configuration file. +# shellcheck source=installer.cfg +source /etc/de-p1st-installer/installer.cfg function main() { # @pre @@ -91,7 +110,7 @@ function increase_cow_space() { # May be useful when running 'pacman -Syu' on the live medium. # Usually not necessary! - # make sure that we are on a live medium: + # Make sure that we are on a live medium: findmnt /run/archiso/cowspace >/dev/null || { echo 'Not on live medium, did not increase cowspace!' return 1 @@ -326,7 +345,7 @@ function run_pacstrap() { local args=() if [ "${PACSTRAP_INTERACTIVE}" = 'true' ]; then - args+=('-i') # run interactively + args+=('-i') # Run interactively fi args+=('/mnt') @@ -409,7 +428,7 @@ function user_and_pwd() { # ROOT_PWD (optional) echo 'Adding user and changing shell to /bin/zsh ...' - # -m: create home + # -m: Create home # -U: Create a group with the same name as the user, and add the user to this group. sudo arch-chroot /mnt useradd -m -s /usr/bin/zsh -g wheel "${USERNAME}" sudo arch-chroot /mnt chsh -s /usr/bin/zsh @@ -430,7 +449,7 @@ function bootloader() { echo 'Installing grub ...' case "${BOOT_FIRMWARE}" in uefi) - # portable fallback efi name for grub: + # Portable fallback efi name for grub: # * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming # * arch-chroot /mnt cp /boot/EFI/GRUB/grubx64.efi /boot/EFI/BOOT/bootx64.efi sudo arch-chroot /mnt grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot --removable