summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/al/alist/update.nix
blob: e32f0c3e6c8d6e976fb65cdb31500577e000557c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{
  writeShellApplication,
  nix,
  nix-update,
  curl,
  jq,
  common-updater-scripts,
}:

writeShellApplication {
  name = "update-alist";
  runtimeInputs = [
    curl
    jq
    nix
    common-updater-scripts
    nix-update
  ];

  text = ''
    # get old info
    oldVersion=$(nix-instantiate --eval --strict -A "alist.version" | jq -e -r)

    get_latest_release() {
        local repo=$1
        curl --fail ''${GITHUB_TOKEN:+ -H "Authorization: bearer $GITHUB_TOKEN"} \
             -s "https://api.github.com/repos/AlistGo/$repo/releases/latest" | jq -r ".tag_name"
    }

    version=$(get_latest_release "alist")
    version="''${version#v}"
    webVersion=$(get_latest_release "alist-web")

    if [[ "$oldVersion" == "$version" ]]; then
        echo "Already up to date!"
        exit 0
    fi

    update-source-version alist "$webVersion" --source-key=web --version-key=webVersion

    nix-update alist --version="$version"
  '';
}