pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / servers / authelia / update.sh
bloba7f56fc6c5710d125af97e1978e59c119eab16e7
1 #! /usr/bin/env nix-shell
2 #! nix-shell -I nixpkgs=./. -i bash -p coreutils gnused curl nix jq nodejs
3 set -euo pipefail
5 DRV_DIR="$(dirname "${BASH_SOURCE[0]}")"
6 DRV_DIR=$(realpath "$DRV_DIR")
7 NIXPKGS_ROOT="$DRV_DIR/../../.."
8 NIXPKGS_ROOT=$(realpath "$NIXPKGS_ROOT")
10 instantiateClean() {
11 nix-instantiate --eval --strict -E "with import ./. {}; $1" | cut -d\" -f2
13 fetchNewHash() {
14 set +eo pipefail
15 HASH="$(nix-build -A "$1" 2>&1 >/dev/null | grep "got:" | cut -d':' -f2 | sed 's| ||g')"
16 set -eo pipefail
17 if [ -z "$HASH" ]; then
18 echo "Could not generate hash" >&2
19 exit 1
20 else
21 echo "$HASH"
24 replace() {
25 sed -i "s@$1@$2@g" "$3"
28 # provide a github token so you don't get rate limited
29 # if you use gh cli you can use:
30 # `export GITHUB_TOKEN="$(cat ~/.config/gh/config.yml | yq '.hosts."github.com".oauth_token' -r)"`
31 # or just set your token by hand:
32 # `read -s -p "Enter your token: " GITHUB_TOKEN; export GITHUB_TOKEN`
33 # (we use read so it doesn't show in our shell history and in secret mode so the token you paste isn't visible)
34 if [ -z "${GITHUB_TOKEN:-}" ]; then
35 echo "no GITHUB_TOKEN provided - you could meet API request limiting" >&2
38 OLD_VERSION=$(instantiateClean "authelia.version")
40 LATEST_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/authelia/authelia/releases/latest | jq -r '.tag_name')
41 NEW_VERSION=$(echo ${LATEST_TAG} | sed 's/^v//')
43 if [[ "$OLD_VERSION" == "$NEW_VERSION" ]]; then
44 echo "already up to date"
45 exit
48 TMP_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
49 echo "New version $NEW_VERSION"
50 replace "$OLD_VERSION" "$NEW_VERSION" "$DRV_DIR/sources.nix"
51 OLD_SRC_HASH="$(instantiateClean authelia.src.outputHash)"
52 echo "Old src hash $OLD_SRC_HASH"
53 replace "$OLD_SRC_HASH" "$TMP_HASH" "$DRV_DIR/sources.nix"
54 NEW_SRC_HASH="$(fetchNewHash authelia.src)"
55 echo "New src hash $NEW_SRC_HASH"
56 replace "$TMP_HASH" "$NEW_SRC_HASH" "$DRV_DIR/sources.nix"
58 OLD_PNPM_DEPS_HASH="$(instantiateClean authelia.web.pnpmDeps.outputHash)"
59 echo "Old pnpm deps hash $OLD_PNPM_DEPS_HASH"
60 replace "$OLD_PNPM_DEPS_HASH" "$TMP_HASH" "$DRV_DIR/sources.nix"
61 NEW_PNPM_DEPS_HASH="$(fetchNewHash authelia.web)"
62 echo "New pnpm deps hash $NEW_PNPM_DEPS_HASH"
63 replace "$TMP_HASH" "$NEW_PNPM_DEPS_HASH" "$DRV_DIR/sources.nix"
65 OLD_GO_VENDOR_HASH="$(instantiateClean authelia.vendorHash)"
66 echo "Old go vendor hash $OLD_GO_VENDOR_HASH"
67 replace "$OLD_GO_VENDOR_HASH" "$TMP_HASH" "$DRV_DIR/sources.nix"
68 NEW_GO_VENDOR_HASH="$(fetchNewHash authelia.goModules)"
69 echo "New go vendor hash $NEW_GO_VENDOR_HASH"
70 replace "$TMP_HASH" "$NEW_GO_VENDOR_HASH" "$DRV_DIR/sources.nix"