49 lines
1.5 KiB
Bash
49 lines
1.5 KiB
Bash
#!/bin/bash
|
|
|
|
BASE_URL="https://hydra.nixos.org/job/nixos/release-24.11/nixos"
|
|
LXC_TEMPLATE_DIR="/var/lib/vz/template/cache"
|
|
VM_BACKUP_DIR="/var/lib/vz/dump"
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Please run as root"
|
|
exit 1
|
|
fi
|
|
|
|
# Create directories if they don't exist
|
|
mkdir -p "$LXC_TEMPLATE_DIR" "$VM_BACKUP_DIR"
|
|
|
|
# Define file paths and URLs
|
|
LXC_FILE="${LXC_TEMPLATE_DIR}/nixos_proxmox_lxc.tar.xz"
|
|
VM_FILE="${VM_BACKUP_DIR}/nixos_proxmox_vm.vma.zst"
|
|
LXC_URL="${BASE_URL}.proxmoxLXC.x86_64-linux/latest/download/1"
|
|
VM_URL="${BASE_URL}.proxmoxImage.x86_64-linux/latest/download/1"
|
|
|
|
# Function to check and download file
|
|
check_and_download() {
|
|
local file=$1
|
|
local url=$2
|
|
local type=$3
|
|
|
|
if [ -f "$file" ]; then
|
|
# Get remote file size
|
|
remote_size=$(curl -sI "$url" | grep -i content-length | awk '{print $2}' | tr -d '\r')
|
|
local_size=$(stat -f%z "$file" 2>/dev/null || stat -c%s "$file")
|
|
|
|
if [ "$local_size" != "$remote_size" ]; then
|
|
echo "Size mismatch for $type, downloading new version..."
|
|
wget -q --show-progress -O "$file" "$url"
|
|
else
|
|
echo "$type is up to date"
|
|
fi
|
|
else
|
|
echo "Downloading $type..."
|
|
wget -q --show-progress -O "$file" "$url"
|
|
fi
|
|
}
|
|
|
|
# Download both images if needed
|
|
check_and_download "$LXC_FILE" "$LXC_URL" "LXC template"
|
|
# check_and_download "$VM_FILE" "$VM_URL" "VM backup"
|
|
# TODO: fix the VM download url
|