python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / tools / admin / meshcentral / update.sh
blobf7f12078372ed3688cf314177ac278fe2433ef5c
1 #!/usr/bin/env nix-shell
2 #! nix-shell -i bash -p nodejs yarn yarn2nix jq rsync common-updater-scripts moreutils
4 set -exuo pipefail
6 expr_dir=$(cd "$(dirname "$0")"; pwd)
7 tmp=$(mktemp -dt update-meshcentral.XXXXXX)
9 npm show --json meshcentral > "$tmp/npm.json"
10 version=$(<"$tmp/npm.json" jq -r .version)
11 tarball=$(<"$tmp/npm.json" jq -r .dist.tarball)
13 prefetch=$(nix-prefetch-url --unpack --print-path "$tarball" | tr '\n' ' ')
14 read -r hash storePath <<<"$prefetch"
15 cd "$tmp"
16 rsync -r --chmod=u=rwX "$storePath/" package/
17 cd package
19 # Very crude way of discovering optional dependencies. These are
20 # fetched at runtime by stock upstream, but we don't allow that kind
21 # of thing in nix :)
22 awk <meshcentral.js "
23 BEGIN { RS=\"[\n;]\" }
24 match(\$0, /(modules|passport) = (\[.*\])$/, a) { print a[2] }
25 match(\$0, /(modules|passport).push\(('[^']+')\)/, a) { print a[2] }
26 " |
27 tr \' \" |
28 jq --slurp '[if type == "array" then .[] else . end] | flatten' |
29 # And an equally crude way of adding them to package.json. We
30 # can't use yarn add here, because that will blow up on
31 # dependencies which don't support the current platform. Even with
32 # --optional.
33 jq --slurpfile package package.json \
34 '(. | map(. | capture("(?<name>@?[^@]+)(@(?<version>.+))?") | { key: .name, value: (.version // "*")}) | from_entries) as $optionalDependencies | $package | .[] | .optionalDependencies |= . + $optionalDependencies' |
35 sponge package.json
37 # Fetch all the optional dependencies, so we have them available in
38 # yarn.lock/yarn.nix
39 yarn install --ignore-scripts
41 cp package.json "$expr_dir"
42 cp yarn.lock "$expr_dir/yarn.lock"
43 yarn2nix > "$expr_dir/yarn.nix"
45 cd "$expr_dir/../../../.."
46 update-source-version meshcentral "$version" "$hash" "$tarball"
48 # Only clean up if everything worked
49 cd /
50 rm -rf "$tmp"