summary refs log tree commit diff
path: root/maintainers/scripts/update-discord
blob: b4c26b3bdefdd341462202ea8427dfbf33ec1f0e (plain) (blame)
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
#!/usr/bin/env bash
# script to generate `pkgs/networking/instant-messengers/discord/default.nix`

set -e
exec >${1:?usage: $0 <output-file>}

cat <<EOF
{ branch ? "stable", pkgs }:
# Generated by /maintainers/scripts/update-discord
let
  inherit (pkgs) callPackage fetchurl;
in {
EOF

for branch in "" ptb canary; do
    url=$(curl -sI "https://discordapp.com/api/download${branch:+/}${branch}?platform=linux&format=tar.gz" | grep -oP 'location: \K\S+')
    version=${url##https://dl*.discordapp.net/apps/linux/}
    version=${version%%/*.tar.gz}
    echo "  ${branch:-stable} = callPackage ./base.nix rec {"
    echo "    pname = \"discord${branch:+-}${branch}\";"
    case $branch in
        "") suffix="" ;;
        ptb) suffix="PTB" ;;
        canary) suffix="Canary" ;;
    esac
    echo "    binaryName = \"Discord${suffix}\";"
    echo "    desktopName = \"Discord${suffix:+ }${suffix}\";"
    echo "    version = \"${version}\";"
    echo "    src = fetchurl {"
    echo "      url = \"${url//${version}/\$\{version\}}\";"
    echo "      sha256 = \"$(nix-prefetch-url "$url")\";"
    echo "    };"
    echo "  };"
done

echo "}.\${branch}"