From e6f7934c7eaa23924031a2912eef49b5dc86893f Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Sat, 12 Oct 2024 17:19:59 +0200
Subject: [PATCH] Streamline hooks in `fish` scripts

---
 scripts/Arch/OS/setup.fish        |  1 -
 scripts/Common/OS/install.fish    |  2 +-
 scripts/Common/OS/setup.fish      | 13 +++----------
 scripts/Common/Scripts/hooks.fish |  8 +++++---
 4 files changed, 9 insertions(+), 15 deletions(-)

diff --git a/scripts/Arch/OS/setup.fish b/scripts/Arch/OS/setup.fish
index 4509dbd4..7fe03a7a 100755
--- a/scripts/Arch/OS/setup.fish
+++ b/scripts/Arch/OS/setup.fish
@@ -81,7 +81,6 @@ begin
             and echo (getOSConfig hostname) | arch-chroot "$mountDir" tee /etc/hostname >/dev/null
 
             and arch-chroot "$mountDir" mkinitcpio -P
-            and runHook installDrivers "Installing drivers..." || true
             and runInOS fish "$tempDir/../Software/GRUB/main.fish"
 
             and if set -l keyLayout (getOSConfig keyboardLayout)
diff --git a/scripts/Common/OS/install.fish b/scripts/Common/OS/install.fish
index 9e3100f0..33c62083 100755
--- a/scripts/Common/OS/install.fish
+++ b/scripts/Common/OS/install.fish
@@ -8,7 +8,7 @@ if [ (id -u) -eq 0 ]
     set -l sudoConfig "/etc/sudoers.d/PortValhalla"
     rm ~/.bash_profile
 
-    runHook createUser || begin
+    begin
         echo "Creating setup user"
 
         and useradd \
diff --git a/scripts/Common/OS/setup.fish b/scripts/Common/OS/setup.fish
index fc6e8cf7..87be8e93 100755
--- a/scripts/Common/OS/setup.fish
+++ b/scripts/Common/OS/setup.fish
@@ -22,13 +22,6 @@ function runSetup
         end
     end
 
-    if not type -q installValhallaDeps
-        function installValhallaDeps
-            echo 'Please set up the hook `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.'
-            exit 1
-        end
-    end
-
     function getCloneFile -S -a path
         set -l relativeDir (realpath --relative-to "$projectRoot" "$dir")
         set -l relativePath (realpath --relative-to "$dir" "$path")
@@ -64,15 +57,15 @@ function runSetup
     end
 
     and echo "Installing dependencies..."
-    and runHook installValhallaDeps
+    and runHook installValhallaDeps true 'Please set up a function `installValhallaDeps` for installing `fish`, `git`, `jq`, `nix`, `sudo` and `tmux`.'
 
     and echo "Cloning project..."
     and source "$dir/../../copy-repo.fish" "$mountDir$PROJECT_CLONE_ROOT"
     runChroot "$mountDir" git config --system --add safe.directory "$PROJECT_CLONE_ROOT"
-    and runHook setupOS || true
+    and runHook setupOS
 
     and echo "Preparing auto-login..."
-    and runHook autologin || true
+    and runHook autologin true "Please set up a function `autologin` for  setting up autologin for the `root` user"
 
     and begin
         set -l script (string escape (getCloneFile (getInstallerScript)))
diff --git a/scripts/Common/Scripts/hooks.fish b/scripts/Common/Scripts/hooks.fish
index beef08dc..49378f79 100755
--- a/scripts/Common/Scripts/hooks.fish
+++ b/scripts/Common/Scripts/hooks.fish
@@ -1,11 +1,13 @@
-function runHook -S -a name message
+function runHook -S -a name force message
     if type -q "$name"
+        "$name"
+        or exit 1
+    else if $force
         if test -n "$message"
             echo "$message"
         end
 
-        "$name"
-        or exit
+        exit 1
     else
         return 1
     end