]> Untitled Git - awful.systems.git/blob - lemmy/update.sh
Initial commit
[awful.systems.git] / lemmy / update.sh
1 #! /usr/bin/env nix-shell
2 #! nix-shell -i oil -p oil jq sd nix-prefetch-github ripgrep moreutils
3
4 # TODO set to `verbose` or `extdebug` once implemented in oil
5 shopt --set xtrace
6 # we need failures inside of command subs to get the correct dependency sha256
7 shopt --unset inherit_errexit
8
9 const directory = $(dirname $0 | xargs realpath)
10 const owner = "LemmyNet"
11 const ui_repo = "lemmy-ui"
12 const server_repo = "lemmy"
13 const latest_rev = $(curl -q https://api.github.com/repos/${owner}/${server_repo}/releases/latest | \
14   jq -r '.tag_name')
15 const latest_version = $(echo $latest_rev)
16 const current_version = $(jq -r '.version' $directory/pin.json)
17 echo "latest version: $latest_version, current version: $current_version"
18 if ("$latest_version" === "$current_version") {
19   echo "lemmy is already up-to-date"
20   return 0
21 } else {
22   # for some strange reason, hydra fails on reading upstream package.json directly
23   const source = "https://raw.githubusercontent.com/$owner/$ui_repo/$latest_version"
24   const package_json = $(curl -qf $source/package.json)
25   echo $package_json > $directory/package.json
26
27   const server_tarball_meta = $(nix-prefetch-github $owner $server_repo --rev $latest_rev --fetch-submodules)
28   const server_tarball_hash = "sha256-$(echo $server_tarball_meta | jq -r '.sha256')"
29   const ui_tarball_meta = $(nix-prefetch-github $owner $ui_repo --rev $latest_rev --fetch-submodules)
30   const ui_tarball_hash = "sha256-$(echo $ui_tarball_meta | jq -r '.sha256')"
31
32   jq ".version = \"$latest_version\" | \
33       .\"serverSha256\" = \"$server_tarball_hash\" | \
34       .\"uiSha256\" = \"$ui_tarball_hash\" | \
35       .\"serverCargoSha256\" = \"\" | \
36       .\"uiYarnDepsSha256\" = \"\"" $directory/pin.json | sponge $directory/pin.json
37
38   const new_cargo_sha256 = $(nix-build $directory/../../../.. -A lemmy-server 2>&1 | \
39     tail -n 2 | \
40     head -n 1 | \
41     sd '\s+got:\s+' '')
42
43   const new_offline_cache_sha256 = $(nix-build $directory/../../../.. -A lemmy-ui 2>&1 | \
44     tail -n 2 | \
45     head -n 1 | \
46     sd '\s+got:\s+' '')
47
48   jq ".\"serverCargoSha256\" = \"$new_cargo_sha256\" | \
49       .\"uiYarnDepsSha256\" = \"$new_offline_cache_sha256\"" \
50     $directory/pin.json | sponge $directory/pin.json
51 }