2021-06-10 08:10:06 +02:00
|
|
|
#!/usr/bin/env nix-shell
|
2022-12-16 15:27:57 +01:00
|
|
|
#!nix-shell -p nix -p coreutils -p bash -p gh -i bash
|
2021-06-10 09:30:10 +02:00
|
|
|
# shellcheck shell=bash
|
2021-06-10 08:10:06 +02:00
|
|
|
set -xeuo pipefail
|
2022-12-13 10:42:30 +01:00
|
|
|
shopt -s lastpipe
|
2021-06-10 08:10:06 +02:00
|
|
|
|
|
|
|
build_netboot_image() {
|
2021-06-10 09:30:10 +02:00
|
|
|
declare -r tag=$1 arch=$2 tmp=$3
|
2023-08-04 22:47:00 +02:00
|
|
|
img=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.netboot-${tag//./}")
|
2021-06-12 09:00:47 +02:00
|
|
|
ln -s "$img/bzImage" "$tmp/bzImage-$arch"
|
2021-06-10 09:02:41 +02:00
|
|
|
echo "$tmp/bzImage-$arch"
|
2021-06-12 09:00:47 +02:00
|
|
|
ln -s "$img/initrd" "$tmp/initrd-$arch"
|
2021-06-10 09:02:41 +02:00
|
|
|
echo "$tmp/initrd-$arch"
|
2021-06-13 09:04:19 +02:00
|
|
|
sed -e "s!^kernel bzImage!kernel https://github.com/nix-community/nixos-images/releases/download/${tag}/bzImage-${arch}!" \
|
|
|
|
-e "s!^initrd initrd!initrd https://github.com/nix-community/nixos-images/releases/download/${tag}/initrd-${arch}!" \
|
2021-06-16 21:48:38 +02:00
|
|
|
-e "s!initrd=initrd!initrd=initrd-${arch}!" \
|
2023-08-04 22:47:00 +02:00
|
|
|
<"$img/netboot.ipxe" \
|
|
|
|
>"$tmp/netboot-$arch.ipxe"
|
2021-06-12 09:00:47 +02:00
|
|
|
echo "$tmp/netboot-$arch.ipxe"
|
2021-06-10 08:10:06 +02:00
|
|
|
}
|
|
|
|
|
2022-09-04 14:57:14 +02:00
|
|
|
build_kexec_installer() {
|
2023-05-07 20:55:45 +02:00
|
|
|
declare -r tag=$1 arch=$2 tmp=$3 variant=$4
|
2023-08-04 22:47:00 +02:00
|
|
|
out=$(nix build --print-out-paths --option accept-flake-config true -L ".#packages.${arch}.kexec-installer-${tag//./}${variant}")
|
2023-05-07 21:06:12 +02:00
|
|
|
echo "$out/nixos-kexec-installer${variant}-$arch.tar.gz"
|
2022-09-04 14:57:14 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 08:10:06 +02:00
|
|
|
main() {
|
2021-06-10 09:30:10 +02:00
|
|
|
declare -r tag=${1:-nixos-unstable} arch=${2:-x86_64-linux}
|
2021-06-10 08:10:06 +02:00
|
|
|
tmp="$(mktemp -d)"
|
|
|
|
trap 'rm -rf -- "$tmp"' EXIT
|
2022-12-13 10:42:30 +01:00
|
|
|
(
|
2023-05-07 20:55:45 +02:00
|
|
|
build_kexec_installer "$tag" "$arch" "$tmp" ""
|
|
|
|
build_kexec_installer "$tag" "$arch" "$tmp" "-noninteractive"
|
2021-06-10 10:06:41 +02:00
|
|
|
build_netboot_image "$tag" "$arch" "$tmp"
|
2022-12-13 10:42:30 +01:00
|
|
|
) | readarray -t assets
|
2021-06-10 08:10:06 +02:00
|
|
|
for asset in "${assets[@]}"; do
|
2021-06-10 09:30:10 +02:00
|
|
|
pushd "$(dirname "$asset")"
|
2023-08-04 22:47:00 +02:00
|
|
|
sha256sum "$(basename "$asset")" >>"$TMP/sha256sums"
|
2021-06-10 08:10:06 +02:00
|
|
|
popd
|
|
|
|
done
|
|
|
|
assets+=("$TMP/sha256sums")
|
|
|
|
|
2023-08-04 22:47:00 +02:00
|
|
|
if ! gh release view "$tag"; then
|
|
|
|
gh release create --title "$tag (build $(date +"%Y-%m-%d"))" "$tag"
|
|
|
|
fi
|
|
|
|
gh release upload --clobber "$tag" "${assets[@]}"
|
|
|
|
|
|
|
|
gh release view --json assets | jq -r ".assets | map(.name) | .[] | select(test(\"$arch\"))" >"$TMP/existing-assets"
|
|
|
|
|
|
|
|
for asset in "${assets[@]}"; do
|
|
|
|
basename "$asset" >>"$TMP/uploaded-assets"
|
|
|
|
done
|
|
|
|
sort "$TMP/uploaded-assets" "$TMP/existing-assets" | uniq -u | xargs --no-run-if-empty -I{} gh release delete-asset --yes "$tag" {}
|
2021-06-10 08:10:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|