zulip/tools/setup/install-shfmt

33 lines
779 B
Bash
Executable File

#!/usr/bin/env bash
set -eu
version=3.4.0
arch="$(uname -m)"
case $arch in
"x86_64")
binary="shfmt_v${version}_linux_amd64"
sha256=5cd7a2b57a0592f919ca2e4249bd567ae3426801a28ae94d0b26f8f2c4ce17f9
;;
"aarch64")
binary="shfmt_v${version}_linux_arm64"
sha256=c7a0fcd70f69ad136bee7352b42e0b52060c46bc547baf6e06926fcb0509c37e
;;
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