1 #!/usr/bin/env nix-shell
2 #! nix-shell -i bash -p curl jq git gnused gnugrep
5 # executing this script without arguments will
6 # - find the newest stable plex-desktop version avaiable on snapcraft (https://snapcraft.io/plex-desktop)
7 # - read the current plex-desktop version from the current nix expression
8 # - update the nix expression if the versions differ
9 # - try to build the updated version, exit if that fails
10 # - give instructions for upstreaming
12 # As an optional argument you can specify the snapcraft channel to update to.
13 # Default is `stable` and only stable updates should be pushed to nixpkgs. For
14 # testing you may specify `candidate` or `edge`.
17 channel
="${1:-stable}" # stable/candidate/edge
18 nixpkgs
="$(git rev-parse --show-toplevel)"
19 plex_nix
="$nixpkgs/pkgs/by-name/pl/plex-desktop/package.nix"
23 # find the newest stable plex-desktop version avaiable on snapcraft
26 # create bash array from snap info
28 curl
-s -H 'X-Ubuntu-Series: 16' \
29 "https://api.snapcraft.io/api/v1/snaps/details/plex-desktop?channel=$channel" \
31 '.revision,.download_sha512,.version,.last_updated'
34 # "revision" is the actual version identifier on snapcraft, the "version" is
35 # just for human consumption. Revision is just an integer that gets increased
36 # by one every (stable or unstable) release.
37 revision
="${snap_info[0]}"
38 # We need to escape the slashes
39 hash="$(nix-hash --to-sri --type sha512 ${snap_info[1]} | sed 's|/|\\/|g')"
40 upstream_version
="${snap_info[2]}"
41 last_updated
="${snap_info[3]}"
42 echo "Latest $channel release is $upstream_version from $last_updated."
44 # read the current plex-desktop version from the currently *committed* nix expression
48 grep 'version\s*=' "$plex_nix" \
49 |
sed -Ene 's/.*"(.*)".*/\1/p'
52 echo "Current version: $current_version"
55 # update the nix expression if the versions differ
58 if [[ "$current_version" == "$upstream_version" ]]; then
59 echo "Plex is already up-to-date"
63 echo "Updating from ${current_version} to ${upstream_version}, released on ${last_updated}"
65 # search-and-replace revision, hash and version
66 sed --regexp-extended \
67 -e 's/rev\s*=\s*"[0-9]+"\s*;/rev = "'"${revision}"'";/' \
68 -e 's/hash\s*=\s*"[^"]*"\s*;/hash = "'"${hash}"'";/' \
69 -e 's/version\s*=\s*".*"\s*;/version = "'"${upstream_version}"'";/' \
73 # try to build the updated version
76 export NIXPKGS_ALLOW_UNFREE
=1
77 if ! nix-build
-A plex-desktop
"$nixpkgs"; then
78 echo "The updated plex-desktop failed to build."
84 git commit
-m "plex-desktop: ${current_version} -> ${upstream_version}"