#!/usr/bin/env bash # Disable all swap swapoff -a # Create necessary directories mkdir -p /var/lib/sops-nix mkdir -p ~/.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 # 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."