plex: Add an updateScript

This commit is contained in:
Samir Hafez 2020-11-26 12:47:34 +00:00
parent 19908dd99d
commit 8a20b502c8
No known key found for this signature in database
GPG key ID: 95806A3539FE7066

View file

@ -1,6 +1,10 @@
{ stdenv
, fetchurl
, dpkg
, writeScript
, curl
, jq
, common-updater-scripts
}:
# The raw package that fetches and extracts the Plex RPM. Override the source
@ -52,6 +56,27 @@ stdenv.mkDerivation rec {
dontPatchELF = true;
dontAutoPatchelf = true;
passthru.updateScript = writeScript "${pname}-updater" ''
#!${stdenv.shell}
set -eu -o pipefail
PATH=${stdenv.lib.makeBinPath [curl jq common-updater-scripts]}:$PATH
plexApiJson=$(curl -sS https://plex.tv/api/downloads/5.json)
latestVersion="$(echo $plexApiJson | jq .computer.Linux.version | tr -d '"\n')"
for platform in ${stdenv.lib.concatStringsSep " " meta.platforms}; do
arch=$(echo $platform | cut -d '-' -f1)
dlUrl="$(echo $plexApiJson | jq --arg arch "$arch" -c '.computer.Linux.releases[] | select(.distro == "debian") | select(.build | contains($arch)) .url' | tr -d '"\n')"
latestSha="$(nix-prefetch-url $dlUrl)"
# The script will not perform an update when the version attribute is up to date from previous platform run
# We need to clear it before each run
update-source-version plexRaw 0 $(yes 0 | head -64 | tr -d "\n") --system=$platform
update-source-version plexRaw "$latestVersion" "$latestSha" --system=$platform
done
'';
meta = with stdenv.lib; {
homepage = "https://plex.tv/";
license = licenses.unfree;