From b8f37412b2ce08d29326aa6c4ee5de0e7793e750 Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 12 Oct 2024 03:30:15 -0500 Subject: [PATCH] feat: added reinstall scripts --- profiles/user0/files/modnix.sh | 21 ++++------------ profiles/user0/files/reinstall.sh | 42 +++---------------------------- 2 files changed, 9 insertions(+), 54 deletions(-) diff --git a/profiles/user0/files/modnix.sh b/profiles/user0/files/modnix.sh index 55466e2..352c4cd 100755 --- a/profiles/user0/files/modnix.sh +++ b/profiles/user0/files/modnix.sh @@ -1,20 +1,9 @@ #!/usr/bin/env bash -# Define the path to the configuration file -CONFIG_FILE="/etc/nixos/configuration.nix" +cp /etc/nixos/configuration.nix /etc/nixos/configuration.nix.backup -# Backup the original configuration file -cp "$CONFIG_FILE" "$CONFIG_FILE.bak" +sed -i '/services\.printing\.enable = true;/a\ nix.settings.experimental-features = ["nix-command" "flakes"];\n services.openssh.enable = true;' /etc/nixos/configuration.nix +sed -i '/thunderbird/a\ git\n vscode\n tomb' /etc/nixos/configuration.nix +swapoff -a -# Add experimental features -sed -i '/nix.settings.experimental-features/a\ nix.settings.experimental-features = ["nix-command" "flakes"]; # Added by script' "$CONFIG_FILE" - -# Enable OpenSSH daemon -sed -i '/services.openssh.enable = true;/i\ services.openssh.enable = true; # Added by script' "$CONFIG_FILE" - -# Add user packages -sed -i '/packages = with pkgs; \[/a\ git # Added by script' "$CONFIG_FILE" -sed -i '/git/a\ vscode # Added by script' "$CONFIG_FILE" -sed -i '/vscode/a\ tomb # Added by script' "$CONFIG_FILE" - -echo "Configurations have been added to $CONFIG_FILE." +echo "/etc/nixos/configuration.nix updated successfully." \ No newline at end of file diff --git a/profiles/user0/files/reinstall.sh b/profiles/user0/files/reinstall.sh index 87c36b0..1925f1e 100755 --- a/profiles/user0/files/reinstall.sh +++ b/profiles/user0/files/reinstall.sh @@ -1,45 +1,11 @@ #!/usr/bin/env bash -# Disable all swap -swapoff -a - -# Create necessary directories mkdir -p /var/lib/sops-nix -mkdir -p ~/.config/sops/age +mkdir -p /home/nick/.config/sops/age -# Copy key files -cp /run/media/nick/crypt/key.txt ~/.config/sops/age/ -cp /run/media/nick/crypt/keys.txt /var/lib/sops-nix/keys.txt +cp /run/media/nick/crypt/key.txt /home/nick/.config/sops/age/keys.txt +cp /run/media/nick/crypt/key.txt /var/lib/sops-nix/key.txt -# Slam the tomb -tomb slam - -# Re-enable swap swapon -a -# Define the source and destination files -SOURCE_FILE="/etc/nixos/hardware-configuration.nix" -TARGET_FILE="$HOME/dotfiles/systems/desktop/filesystem.nix" - -# Extract new UUIDs from the source file -new_uuids=$(grep -E 'device = "/dev/disk/by-uuid|swapDevices =' "$SOURCE_FILE" | \ -sed -E 's/.*device = "([^"]+)".*/\1/; s/.*swapDevices = \[(.*)\].*/\1/' | \ -tr -d '{}; ' | \ -awk -F'/' '{print $5}' | tr '\n' ' ') - -# Split the new UUIDs into an array -read -r -a uuid_array <<< "$new_uuids" - -# Check if we have at least 3 UUIDs (root, boot, swap) -if [ "${#uuid_array[@]}" -lt 3 ]; then - echo "Not enough UUIDs found in the source file." - exit 1 -fi - -# Replace old UUIDs in the target file -sed -i -E "s|(/dev/disk/by-uuid/[0-9a-f-]+)|${uuid_array[0]}|; \ -s|(/dev/disk/by-uuid/[0-9a-f-]+)|${uuid_array[1]}|; \ -s|(/dev/disk/by-uuid/[0-9a-f-]+)|${uuid_array[2]}|" "$TARGET_FILE" - -echo "UUIDs in $TARGET_FILE have been replaced with those from $SOURCE_FILE." - +echo "SOPS keys transferred successfully." \ No newline at end of file