Merge pull request #329823 from ExpidusOS/fix/pkgsllvm/elfutils
[NixPkgs.git] / pkgs / servers / adguardhome / update.sh
blob4e3ecfbfaca44163691a0e712ad7a12b11bb707d
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i bash -p curl gnugrep nix-prefetch jq
4 # This file is based on /pkgs/servers/gotify/update.sh
6 set -euo pipefail
8 dirname="$(dirname "$0")"
9 bins="$dirname/bins.nix"
11 latest_release=$(curl --silent https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest)
12 version=$(jq -r '.tag_name' <<<"$latest_release")
14 echo "got version $version"
16 schema_version=$(curl --silent "https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/${version}/internal/configmigrate/configmigrate.go" \
17 | grep -Po '(?<=const LastSchemaVersion uint = )[[:digit:]]+$')
19 echo "got schema_version $schema_version"
21 declare -A systems
22 systems[linux_386]=i686-linux
23 systems[linux_amd64]=x86_64-linux
24 systems[linux_arm64]=aarch64-linux
25 systems[linux_armv6]=armv6l-linux
26 systems[linux_armv7]=armv7l-linux
27 systems[darwin_amd64]=x86_64-darwin
28 systems[darwin_arm64]=aarch64-darwin
30 echo '{ fetchurl, fetchzip }:' > "$bins"
31 echo '{' >> "$bins"
33 for asset in $(curl --silent https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest | jq -c '.assets[]') ; do
34 url="$(jq -r '.browser_download_url' <<< "$asset")"
35 adg_system="$(grep -Eo '(darwin|linux)_(386|amd64|arm64|armv6|armv7)' <<< "$url" || true)"
36 if [ -n "$adg_system" ]; then
37 fetch="$(grep '\.zip$' <<< "$url" > /dev/null && echo fetchzip || echo fetchurl)"
38 nix_system=${systems[$adg_system]}
39 nix_src="$(nix-prefetch -s --output nix $fetch --url $url)"
40 echo "$nix_system = $fetch $nix_src;" >> $bins
42 done
44 echo '}' >> "$bins"
46 sed -i -r -e "s/version\s*?=\s*?.*?;/version = \"${version#v}\";/" "$dirname/default.nix"
47 sed -i -r -e "s/schema_version\s*?=\s*?.*?;/schema_version = ${schema_version};/" "$dirname/default.nix"