update-alpine.sh (1897B) - Raw
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 # Script to get latest Alpine version and hash 5 # Usage: ./update-alpine.sh 6 7 # Get the latest Alpine version by checking the releases page 8 # Alpine versions are in format like "3.23.2" under v3.23 directory 9 LATEST_MINOR=$(curl -s https://dl-cdn.alpinelinux.org/alpine/ | \ 10 grep -oP 'v\d+\.\d+' | \ 11 sort -V | \ 12 tail -n1) 13 14 if [[ -z "$LATEST_MINOR" ]]; then 15 echo "Error: Could not determine latest Alpine minor version" >&2 16 exit 1 17 fi 18 19 # Get the latest patch version from that minor version 20 VERSION=$(curl -s "https://dl-cdn.alpinelinux.org/alpine/${LATEST_MINOR}/releases/x86_64/" | \ 21 grep -oP 'alpine-netboot-\K[\d.]+(?=-x86_64\.tar\.gz)' | \ 22 sort -V | \ 23 tail -n1) 24 25 if [[ -z "$VERSION" ]]; then 26 echo "Error: Could not determine latest Alpine version" >&2 27 exit 1 28 fi 29 30 # Download the .sha256 checksum file 31 CHECKSUM_URL="https://dl-cdn.alpinelinux.org/alpine/${LATEST_MINOR}/releases/x86_64/alpine-netboot-${VERSION}-x86_64.tar.gz.sha256" 32 HASH_HEX=$(curl -s "$CHECKSUM_URL" | awk '{print $1}') 33 34 if [[ -z "$HASH_HEX" ]]; then 35 echo "Error: Could not download checksum from $CHECKSUM_URL" >&2 36 exit 1 37 fi 38 39 # Convert hex hash to SRI format 40 HASH_SRI=$(nix-hash --type sha256 --to-sri "$HASH_HEX") 41 42 # Output version and hash 43 echo "version: $VERSION" 44 echo "hash: $HASH_SRI" 45 echo "" 46 47 # Check mirror availability 48 echo "Checking mirror availability..." >&2 49 MIRROR_URL="https://dl.jakstys.lt/boot/alpine-netboot-${VERSION}-x86_64.tar.gz" 50 if curl -sI "$MIRROR_URL" | head -1 | grep -q "200"; then 51 echo "✓ File available on mirror" >&2 52 else 53 echo "⚠ Warning: File not found on mirror!" >&2 54 echo "" 55 echo "To upload to mirror, run:" >&2 56 echo " ssh fwminex sh -c 'cd /var/www/dl/boot && wget https://dl-cdn.alpinelinux.org/alpine/${LATEST_MINOR}/releases/x86_64/alpine-netboot-${VERSION}-x86_64.tar.gz'" >&2 57 echo "" 58 fi