zulip/tools/setup/install-shfmt

33 lines
779 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -eu
version=3.4.1
arch="$(uname -m)"
case $arch in
"x86_64")
binary="shfmt_v${version}_linux_amd64"
sha256=0c321e80a97cee3ffbff0579ad9f79805f622b306b507d674da00e3caedb8714
;;
"aarch64")
binary="shfmt_v${version}_linux_arm64"
sha256=dc8e0524ab9fc11bca3a363fef62dd8ffd3c2b3f04d780e46b349b7917a8f187
;;
esac
check_version() {
out="$(shfmt --version 2>/dev/null)" && [ "$out" = "v$version" ]
}
if ! check_version; then
tmpdir="$(mktemp -d)"
trap 'rm -r "$tmpdir"' EXIT
cd "$tmpdir"
curl -fLO "https://github.com/mvdan/sh/releases/download/v$version/$binary"
sha256sum -c <<<"$sha256 $binary"
chmod +x "$binary"
mv "$binary" /usr/local/bin/shfmt
check_version
fi