2021-06-26 02:26:27 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
|
2022-07-06 06:07:34 +02:00
|
|
|
version=1.22.19
|
|
|
|
sha256=732620bac8b1690d507274f025f3c6cfdc3627a84d9642e38a07452cc00e0f2e
|
2021-06-26 02:26:27 +02:00
|
|
|
tarball="yarn-$version.tgz"
|
|
|
|
|
|
|
|
check_version() {
|
|
|
|
# Reading the version of Yarn from its package.json is much faster
|
|
|
|
# than running yarn --version.
|
|
|
|
link="$(command -v yarn)" \
|
2021-12-28 20:57:15 +01:00
|
|
|
&& [ "$link" -ef /srv/zulip-yarn/bin/yarn ] \
|
2021-11-03 22:19:43 +01:00
|
|
|
&& current_version="$(jq -r '.version' /srv/zulip-yarn/package.json)" \
|
2021-06-26 02:26:27 +02:00
|
|
|
&& [ "$current_version" = "$version" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if ! check_version; then
|
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
trap 'rm -r "$tmpdir"' EXIT
|
|
|
|
cd "$tmpdir"
|
2022-11-07 22:50:24 +01:00
|
|
|
curl -fLO --retry 3 "https://registry.npmjs.org/yarn/-/$tarball"
|
2021-06-26 02:26:27 +02:00
|
|
|
sha256sum -c <<<"$sha256 $tarball"
|
|
|
|
rm -rf /srv/zulip-yarn
|
|
|
|
mkdir /srv/zulip-yarn
|
|
|
|
tar -xzf "$tarball" --no-same-owner --strip-components=1 -C /srv/zulip-yarn
|
|
|
|
ln -nsf /srv/zulip-yarn/bin/yarn /usr/bin/yarn
|
|
|
|
check_version
|
|
|
|
fi
|