|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -set -e |
| 3 | +set -euo pipefail |
4 | 4 |
|
5 |
| -name=$(basename $0) |
| 5 | +name=$(basename "$0") |
6 | 6 |
|
7 | 7 | usage() {
|
8 |
| - echo "$name - Tool used to validate and update the sbt nix build" |
9 |
| - echo "" |
10 |
| - echo "USAGE:" |
11 |
| - echo " $name [--check]" |
12 |
| - echo "" |
13 |
| - echo "OPTIONS:" |
14 |
| - echo -e " --check\t Check whether ./nix/pkgs/mantis.nix is up-to-date" |
| 8 | + echo "$name - Tool used to validate and update the sbt nix build" |
| 9 | + echo "" |
| 10 | + echo "USAGE:" |
| 11 | + echo " $name [--check]" |
| 12 | + echo "" |
| 13 | + echo "OPTIONS:" |
| 14 | + echo -e " --check\t Check whether ./nix/mantis.nix is up-to-date" |
15 | 15 | }
|
16 | 16 |
|
17 |
| -if [ "$1" == "-h" -o "$1" == "--help" ]; then |
18 |
| - usage |
19 |
| - exit 1 |
| 17 | +if [ "${1:-}" == "-h" ] || [ "${1:-}" == "--help" ]; then |
| 18 | + usage |
| 19 | + exit 1 |
20 | 20 | fi
|
21 | 21 |
|
22 | 22 | echo "Determining new sha for sbt build, this can take several minutes to do a 'sbt compile'"
|
23 | 23 |
|
24 |
| -NEW_SHA=$(nix-build -E 'with import ./. {}; deps.overrideAttrs( _: { outputHash = "0000000000000000000000000000000000000000000000000000"; })' 2>&1 | grep " got: " | head -n 1 | sed -r 's/\s+got:\s+//' | xargs nix-hash --to-base32 --type sha256 ) |
| 24 | +branch="$(git rev-parse --abbrev-ref HEAD)" |
| 25 | +revision="$(git rev-parse HEAD)" |
| 26 | + |
| 27 | +output="$( |
| 28 | +nix build \ |
| 29 | + --impure \ |
| 30 | + --expr " |
| 31 | + (builtins.getFlake (toString ./.)).legacyPackages.x86_64-linux.mantis-hash { |
| 32 | + ref = \"${branch}\"; |
| 33 | + rev = \"${revision}\"; |
| 34 | + } |
| 35 | + " 2>&1 || true |
| 36 | +)" |
| 37 | + |
| 38 | +NEW_SHA=$( |
| 39 | +echo "$output" \ |
| 40 | + | awk '/^\s+got: / { print $2 }' |
| 41 | +) |
| 42 | + |
| 43 | +if [ -z "$NEW_SHA" ]; then |
| 44 | + echo "$output" |
| 45 | + echo "calculating hash failed!" |
| 46 | + exit 1 |
| 47 | +fi |
25 | 48 |
|
26 | 49 | echo "Calculated sha: $NEW_SHA"
|
27 | 50 |
|
28 | 51 | update_sha() {
|
29 |
| - echo "Updating sha in ./nix/pkgs/mantis.nix" |
30 |
| - sed -r -i -e "s|depsSha256 = \"[^\"]+\";|depsSha256 = \"${NEW_SHA}\";|" ./nix/pkgs/mantis.nix |
31 |
| - echo "./nix/pkgs/mantis.nix has been updated" |
| 52 | + echo "Updating sha in ./nix/mantis.nix" |
| 53 | + sed -r -i -e "s|depsSha256 = \"[^\"]+\";|depsSha256 = \"${NEW_SHA}\";|" ./nix/mantis.nix |
| 54 | + echo "./nix/mantis.nix has been updated" |
32 | 55 | }
|
33 | 56 |
|
34 |
| -if [ $# == 1 -o "$1" == "--check" ]; then |
35 |
| - current_sha=$(cat ./nix/pkgs/mantis.nix | grep depsSha256 | sed 's/\s*depsSha256\s*=\s*//g' | sed -e 's/"//g' -e 's/;//g' | xargs nix-hash --to-base32 --type sha256 ) |
36 |
| - if [ "$current_sha" == "$NEW_SHA" ]; then |
37 |
| - echo "./nix/pkgs/mantis.nix is up-to-date" |
38 |
| - exit 0 |
39 |
| - else |
40 |
| - echo "wanted: $NEW_SHA" |
41 |
| - echo " got: $current_sha" |
42 |
| - update_sha |
43 |
| - exit 1 |
44 |
| - fi |
| 57 | +if [ $# == 1 ] || [ "${1:-}" == "--check" ]; then |
| 58 | + current_sha=$(grep depsSha256 ./nix/mantis.nix | sed 's/\s*depsSha256\s*=\s*//g' | sed -e 's/"//g' -e 's/;//g' | xargs nix-hash --to-base32 --type sha256 ) |
| 59 | + if [ "$current_sha" == "$NEW_SHA" ]; then |
| 60 | + echo "./nix/mantis.nix is up-to-date" |
| 61 | + exit 0 |
| 62 | + else |
| 63 | + echo "wanted: $NEW_SHA" |
| 64 | + echo " got: $current_sha" |
| 65 | + update_sha |
| 66 | + exit 1 |
| 67 | + fi |
45 | 68 | fi
|
46 | 69 |
|
47 | 70 | update_sha
|
48 |
| - |
49 |
| - |
50 |
| - |
|
0 commit comments