test: add shellcheck

This commit is contained in:
Daniel Langbein 2023-03-16 16:45:32 +01:00
parent 472659455e
commit 03e1135e4c
2 changed files with 34 additions and 10 deletions

5
Makefile Normal file
View File

@ -0,0 +1,5 @@
.PHONY: all
all: test
test:
shellcheck --check-sourced --external-sources de-p1st-installer.sh

View File

@ -1,14 +1,33 @@
#!/bin/bash #!/bin/bash
# Exit on error.
set -e set -e
# Exit on undefined variable reference.
set -u set -u
# load config # Check if run from installation or locally (development setup).
source /etc/de-p1st-installer/installer.cfg # -> 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 library files.
source /usr/lib/de-p1st-installer/util.sh # shellcheck source=lib/util.sh
source /usr/lib/de-p1st-installer/user-input.sh source "${lib_dir}"/util.sh
source /usr/lib/de-p1st-installer/block-device.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() { function main() {
# @pre # @pre
@ -91,7 +110,7 @@ function increase_cow_space() {
# May be useful when running 'pacman -Syu' on the live medium. # May be useful when running 'pacman -Syu' on the live medium.
# Usually not necessary! # 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 || { findmnt /run/archiso/cowspace >/dev/null || {
echo 'Not on live medium, did not increase cowspace!' echo 'Not on live medium, did not increase cowspace!'
return 1 return 1
@ -326,7 +345,7 @@ function run_pacstrap() {
local args=() local args=()
if [ "${PACSTRAP_INTERACTIVE}" = 'true' ]; then if [ "${PACSTRAP_INTERACTIVE}" = 'true' ]; then
args+=('-i') # run interactively args+=('-i') # Run interactively
fi fi
args+=('/mnt') args+=('/mnt')
@ -409,7 +428,7 @@ function user_and_pwd() {
# ROOT_PWD (optional) # ROOT_PWD (optional)
echo 'Adding user and changing shell to /bin/zsh ...' 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. # -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 useradd -m -s /usr/bin/zsh -g wheel "${USERNAME}"
sudo arch-chroot /mnt chsh -s /usr/bin/zsh sudo arch-chroot /mnt chsh -s /usr/bin/zsh
@ -430,7 +449,7 @@ function bootloader() {
echo 'Installing grub ...' echo 'Installing grub ...'
case "${BOOT_FIRMWARE}" in case "${BOOT_FIRMWARE}" in
uefi) uefi)
# portable fallback efi name for grub: # Portable fallback efi name for grub:
# * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming # * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming
# * arch-chroot /mnt cp /boot/EFI/GRUB/grubx64.efi /boot/EFI/BOOT/bootx64.efi # * 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 sudo arch-chroot /mnt grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot --removable