#!/bin/bash # Ensure script is run as root if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" 1>&2 exit 1 fi # Update the system and install dependencies echo "Updating system and installing required dependencies..." apt update && apt upgrade -y apt install -y curl git sudo build-essential openssl # Install Nix package manager echo "Installing Nix..." curl -L https://nixos.org/nix/install | sh -s -- --daemon source /home/$USER/.nix-profile/etc/profile.d/nix.sh # Set up Nix and Home Manager configuration echo "Setting up Nix and Home Manager..." mkdir -p /etc/nix echo 'experimental-features = nix-command flakes' > /etc/nix/nix.conf mkdir -p /home/$USER/.config/nixpkgs # Download flake.nix file echo "Downloading flake.nix configuration..." cp /path/to/flake.nix /home/$USER/.config/nixpkgs/flake.nix # Change this to the correct path # Generate passwords echo "Generating passwords for user 'gabriel'..." num_passwords=8 password_file="/home/gabriel/password.txt" > "$password_file" for i in $(seq 1 $num_passwords); do password=$(openssl rand -base64 32) # Generate a random 32-byte password in base64 echo "Password $i: $password" # Print password to terminal echo "$password" >> "$password_file" # Save password to password.txt done # Swap file setup echo "Setting up swap file..." if [ ! -f /swapfile ]; then fallocate -l 2G /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile fi # Make swap permanent by adding it to /etc/fstab if ! grep -q '/swapfile' /etc/fstab; then echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab fi # Create user 'gabriel' if it doesn't exist echo "Creating user 'gabriel'..." if ! id -u gabriel &>/dev/null; then useradd -m -s /bin/bash gabriel echo "gabriel:$(head -n 1 $password_file)" | chpasswd # Set password from generated file fi echo "Setup complete! Passwords have been saved to /home/gabriel/password.txt"