51 lines
1.7 KiB
Bash
Executable file
51 lines
1.7 KiB
Bash
Executable file
#!/usr/bin/env nix-shell
|
|
#!nix-shell -i bash -p curl jq nurl nix-prefetch-npm-deps cacert
|
|
# Update airdrome to the latest release from GitHub.
|
|
#
|
|
# Usage: ./update.sh # auto-detect latest tag
|
|
# ./update.sh 4.3 # pin to a specific tag
|
|
|
|
set -euo pipefail
|
|
|
|
REPO="JPGuillemin/Airdrome"
|
|
PKG_FILE="$(cd "$(dirname "$0")" && pwd)/package.nix"
|
|
|
|
# --- resolve version --------------------------------------------------------
|
|
if [[ $# -ge 1 ]]; then
|
|
VERSION="$1"
|
|
else
|
|
VERSION=$(curl -sL "https://api.github.com/repos/$REPO/releases/latest" \
|
|
| jq -r '.tag_name')
|
|
if [[ -z "$VERSION" || "$VERSION" == "null" ]]; then
|
|
echo "error: could not determine latest release" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
echo "version: $VERSION"
|
|
|
|
# --- source hash (via nurl) -------------------------------------------------
|
|
SRC_HASH=$(nurl "https://github.com/$REPO" "$VERSION" --hash)
|
|
echo "src hash: $SRC_HASH"
|
|
|
|
# --- npm deps hash -----------------------------------------------------------
|
|
# Prefetch source, install deps, and hash them
|
|
SRC_PATH=$(nix build --no-link --print-out-paths \
|
|
--impure --expr "
|
|
(builtins.getFlake \"nixpkgs\").legacyPackages.\${builtins.currentSystem}.fetchFromGitHub {
|
|
owner = \"JPGuillemin\";
|
|
repo = \"Airdrome\";
|
|
rev = \"$VERSION\";
|
|
hash = \"$SRC_HASH\";
|
|
}
|
|
")
|
|
NPM_DEPS_HASH=$(nix-prefetch-npm-deps "$SRC_PATH/package-lock.json")
|
|
echo "npm deps hash: $NPM_DEPS_HASH"
|
|
|
|
# --- patch package.nix -------------------------------------------------------
|
|
sed -i -E "
|
|
s|(version = \").*(\";)|\1${VERSION}\2|
|
|
s|(hash = \").*(\";)|\1${SRC_HASH}\2|
|
|
s|(npmDepsHash = \").*(\";)|\1${NPM_DEPS_HASH}\2|
|
|
" "$PKG_FILE"
|
|
|
|
echo "updated $PKG_FILE"
|