update-nixos.sh (2271B) - Raw
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 # Script to get latest NixOS netboot file hashes from nix-community/nixos-images 5 # Usage: ./update-nixos.sh [version] 6 # version: 25.11, unstable, etc. (default: 25.11) 7 8 VERSION="${1:-25.11}" 9 BASE_URL="https://github.com/nix-community/nixos-images/releases/download/nixos-${VERSION}" 10 MIRROR_BASE="https://dl.jakstys.lt/boot" 11 12 echo "Fetching NixOS netboot files for version: ${VERSION}" >&2 13 14 # Fetch kernel hash 15 KERNEL_URL="${BASE_URL}/bzImage-x86_64-linux" 16 echo "Downloading kernel from: $KERNEL_URL" >&2 17 KERNEL_HASH_B32=$(nix-prefetch-url "$KERNEL_URL" 2>/dev/null) 18 KERNEL_HASH_HEX=$(nix-hash --type sha256 --to-base16 "$KERNEL_HASH_B32") 19 KERNEL_HASH_SRI=$(nix-hash --type sha256 --to-sri "$KERNEL_HASH_HEX") 20 21 # Fetch initrd hash 22 INITRD_URL="${BASE_URL}/initrd-x86_64-linux" 23 echo "Downloading initrd from: $INITRD_URL" >&2 24 INITRD_HASH_B32=$(nix-prefetch-url "$INITRD_URL" 2>/dev/null) 25 INITRD_HASH_HEX=$(nix-hash --type sha256 --to-base16 "$INITRD_HASH_B32") 26 INITRD_HASH_SRI=$(nix-hash --type sha256 --to-sri "$INITRD_HASH_HEX") 27 28 echo "" 29 echo "Update pkgs/mrescue-nixos.nix with:" 30 echo "" 31 echo " version = \"${VERSION}\";" 32 echo "" 33 echo " kernel hash = \"${KERNEL_HASH_SRI}\";" 34 echo " initrd hash = \"${INITRD_HASH_SRI}\";" 35 echo "" 36 37 # Check mirror availability 38 KERNEL_MIRROR="${MIRROR_BASE}/nixos-${VERSION}-bzImage-x86_64-linux" 39 INITRD_MIRROR="${MIRROR_BASE}/nixos-${VERSION}-initrd-x86_64-linux" 40 41 echo "Checking mirror availability..." >&2 42 KERNEL_EXISTS=$(curl -sI "$KERNEL_MIRROR" | head -1 | grep -q "200" && echo "yes" || echo "no") 43 INITRD_EXISTS=$(curl -sI "$INITRD_MIRROR" | head -1 | grep -q "200" && echo "yes" || echo "no") 44 45 if [[ "$KERNEL_EXISTS" == "no" ]] || [[ "$INITRD_EXISTS" == "no" ]]; then 46 echo "" 47 echo "⚠ Warning: Files not found on mirror!" >&2 48 echo "" 49 echo "To upload to mirror, run:" >&2 50 echo "" 51 if [[ "$KERNEL_EXISTS" == "no" ]]; then 52 echo " ssh fwminex sh -c 'cd /var/www/dl/boot && wget -O nixos-${VERSION}-bzImage-x86_64-linux ${KERNEL_URL}'" >&2 53 fi 54 if [[ "$INITRD_EXISTS" == "no" ]]; then 55 echo " ssh fwminex sh -c 'cd /var/www/dl/boot && wget -O nixos-${VERSION}-initrd-x86_64-linux ${INITRD_URL}'" >&2 56 fi 57 echo "" 58 else 59 echo "✓ All files available on mirror" >&2 60 fi