NixOS-PVE-Deployment-Util/setup.sh

65 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
set -e
# ANSI color codes
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
# Check if running as root
if [ "$(id -u)" -ne 0 ]; then
echo -e "${RED}This script must be run as root${NC}"
exit 1
fi
# Check and install git if needed
if ! command -v git >/dev/null 2>&1; then
echo "Installing git..."
nix-env -i git
fi
REPO_DIR="/root/.nixos-utils"
# Clone or update repository
if [ -d "$REPO_DIR" ]; then
echo "Updating existing repository..."
cd "$REPO_DIR"
git pull
else
echo "Cloning repository..."
git clone https://git.jeirslab.xyz/jeirmeister/NixOS-PVE-LXC.git "$REPO_DIR"
cd "$REPO_DIR"
fi
# Make scripts executable
echo "Making scripts executable..."
find ./scripts -name "*.sh" -execdir chmod u+x {} +
# Get CTID from list-lxcs.sh
echo -e "${BLUE}Detecting NixOS containers...${NC}"
CTID=$(./scripts/list-lxcs.sh)
if [ -z "$CTID" ]; then
echo -e "${RED}No container ID was selected${NC}"
exit 1
fi
echo -e "${GREEN}Selected container: $CTID${NC}"
# Execute configuration steps in sequence
echo -e "\nConfiguring NixOS container $CTID..."
echo "Step 1: Setting up LXC terminal..."
./scripts/setup-lxc-terminal.sh "$CTID"
echo "Step 2: Mounting and copying NixOS configuration..."
./scripts/mount-nixos-config.sh "$CTID"
echo "Step 3: Rebuilding NixOS configuration..."
./scripts/rebuild-nixos.sh "$CTID"
echo "Step 4: Running post-deployment tasks..."
./scripts/post-deploy.sh
echo -e "${GREEN}NixOS container $CTID has been configured successfully!${NC}"