From b9ba99c6f41aebbc21f09f8fed0a48e842dc4c0d Mon Sep 17 00:00:00 2001
From: prescientmoon <git@moonythm.dev>
Date: Mon, 26 Aug 2024 19:17:13 +0200
Subject: [PATCH] Update emergency script

---
 scripts/{emergency-lapetus.sh => emergency.sh} | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
 rename scripts/{emergency-lapetus.sh => emergency.sh} (66%)

diff --git a/scripts/emergency-lapetus.sh b/scripts/emergency.sh
similarity index 66%
rename from scripts/emergency-lapetus.sh
rename to scripts/emergency.sh
index 19797cf..7f3ba5f 100755
--- a/scripts/emergency-lapetus.sh
+++ b/scripts/emergency.sh
@@ -3,24 +3,24 @@
 #!nix-shell -i bash
 
 # Check if at least one argument is provided
-if [ "$#" -eq 0 ]; then
-    echo "Usage: $0 <disko-mode> [action]"
+if [ "$#" != "1" ] && [ "$#" != "2" ]; then
+    echo "Usage: $0 $1 <disko-mode> [action]"
     exit 1
 fi
 
 # Ensure correct first argument type
-if [ "$1" != "disko" ] && [ "$1" != "mount" ]; then
+if [ "$2" != "disko" ] && [ "$2" != "mount" ]; then
     echo "Disko action must be either 'disko' or 'mount'"
     exit 1
 fi
 
 # Ensure correct second argument type
-if [ "$#" != "1" ] && [ "$2" != "install" ] && [ "$2" != "enter" ]; then
+if [ "$#" != "2" ] && [ "$3" != "install" ] && [ "$3" != "enter" ]; then
     echo "Action must either be empty, 'install' or 'enter'"
     exit 1
 fi
 
-if mountpoint -q /hermes; then 
+if mountpoint -q /hermes; then
   echo "Keys already mounted"
 else
   echo "Mounting keys"
@@ -30,18 +30,18 @@ fi
 
 echo "Running disko"
 
-if [ "$1" = "mount" ]; then
+if [ "$2" = "mount" ] && [ "$1" = "lapetus" ]; then
   zpool import -lfR /mnt zroot
 fi
 
 nix run disko -- --mode $1 ./hosts/nixos/lapetus/filesystems/partitions.nix
 
-if [ "$2" = "install" ]; then
+if [ "$3" = "install" ]; then
   echo "Installing nixos"
-  nixos-install --flake ".#lapetus"
+  nixos-install --flake ".#$1"
 fi
 
-if [ "$2" = "enter" ]; then
+if [ "$3" = "enter" ]; then
   echo "Entering nixos"
   nixos-enter --root /mnt
 fi