From c26282c6053f58034787e7eb14d9af2d5f9cb077 Mon Sep 17 00:00:00 2001 From: prescientmoon Date: Mon, 26 Aug 2024 19:22:16 +0200 Subject: [PATCH] Update emergency script to support more than one host --- scripts/emergency.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/emergency.sh b/scripts/emergency.sh index 7f3ba5f..23eeedc 100755 --- a/scripts/emergency.sh +++ b/scripts/emergency.sh @@ -4,18 +4,22 @@ # Check if at least one argument is provided if [ "$#" != "1" ] && [ "$#" != "2" ]; then - echo "Usage: $0 $1 [action]" + echo "Usage: $0 [action]" exit 1 fi +host=$1 +mode=$2 +action=$3 + # Ensure correct first argument type -if [ "$2" != "disko" ] && [ "$2" != "mount" ]; then +if [ "$mode" != "disko" ] && [ "$mode" != "mount" ]; then echo "Disko action must be either 'disko' or 'mount'" exit 1 fi # Ensure correct second argument type -if [ "$#" != "2" ] && [ "$3" != "install" ] && [ "$3" != "enter" ]; then +if [ "$#" != "2" ] && [ "$action" != "install" ] && [ "$action" != "enter" ]; then echo "Action must either be empty, 'install' or 'enter'" exit 1 fi @@ -28,20 +32,26 @@ else mount /dev/disk/by-uuid/7FE7-CA68 /hermes fi -echo "Running disko" -if [ "$2" = "mount" ] && [ "$1" = "lapetus" ]; then +if [ "$mode" = "mount" ] && [ "$host" = "lapetus" ]; then + echo "Importing zpool" zpool import -lfR /mnt zroot fi -nix run disko -- --mode $1 ./hosts/nixos/lapetus/filesystems/partitions.nix +echo "Running disko" +nix run disko -- --mode $MODE ./hosts/nixos/$host/filesystems/partitions.nix + +if [ "$action" = "install" ]; then + echo "Generating hardware config" + nixos-generate-config --no-filesystems --show-hardware-config \ + > ./hosts/nixos/$host/hardware/generated.nix + git add . -if [ "$3" = "install" ]; then echo "Installing nixos" - nixos-install --flake ".#$1" + nixos-install --flake ".#$host" fi -if [ "$3" = "enter" ]; then +if [ "$action" = "enter" ]; then echo "Entering nixos" nixos-enter --root /mnt fi