infrastructure/nixos/pkgs/plex-pass/update.sh
Vivian 6bb6d4ae91
All checks were successful
Lint / lint (push) Successful in 1m8s
Plex Update / update (push) Successful in 1m48s
fix ci (#200)
Reviewed-on: #200
Co-authored-by: Victor <victor@xirion.net>
Co-committed-by: Victor <victor@xirion.net>
2023-09-09 16:18:16 +02:00

34 lines
958 B
Bash
Executable file

#! /usr/bin/env nix-shell
#! nix-shell -i bash -p vault curl jq
shopt -s extglob
set -eu -o pipefail
path="$(realpath "$(dirname "$0")")"
declare -A platforms=(
[linux-x86_64]=x86_64-linux
[linux-aarch64]=aarch64-linux
)
token=$(vault kv get -field=plex_token hades_secrets/nixos/plex)
manifest=$(curl -s "https://plex.tv/api/downloads/5.json?channel=plexpass" -H "X-Plex-Token: ${token}")
version=$(echo "$manifest" | jq -r '.computer.Linux.version | split("-") | .[0]')
tmp="$path/sources.tmp.json"
echo '' >$tmp
for arch in "${!platforms[@]}"; do
url="$(echo "$manifest" | jq --arg arch "$arch" -r '.computer.Linux.releases[] | select(.distro == "debian" and .build == $arch) .url')"
hash="$(nix-prefetch-url "$url")"
nixPlatform=${platforms[$arch]}
jq --arg version $version \
--arg platform $nixPlatform \
--arg url "$url" \
--arg hash $hash \
-n '$ARGS.named' >>$tmp
done
jq -s '.' $tmp >"$path/sources.json"
rm $tmp