2020-10-15 04:56:18 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
|
2024-02-22 21:04:46 +01:00
|
|
|
version=3.8.0
|
2021-05-27 09:16:55 +02:00
|
|
|
arch="$(uname -m)"
|
|
|
|
|
|
|
|
case $arch in
|
|
|
|
"x86_64")
|
|
|
|
binary="shfmt_v${version}_linux_amd64"
|
2024-02-22 21:04:46 +01:00
|
|
|
sha256=27b3c6f9d9592fc5b4856c341d1ff2c88856709b9e76469313642a1d7b558fe0
|
2021-05-27 09:16:55 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
"aarch64")
|
|
|
|
binary="shfmt_v${version}_linux_arm64"
|
2024-02-22 21:04:46 +01:00
|
|
|
sha256=27e1f69b0d57c584bcbf5c882b4c4f78ffcf945d0efef45c1fbfc6692213c7c3
|
2021-05-27 09:16:55 +02:00
|
|
|
;;
|
|
|
|
esac
|
2020-10-15 04:56:18 +02:00
|
|
|
|
|
|
|
check_version() {
|
2022-11-03 18:15:10 +01:00
|
|
|
out="$(shfmt --version)" && [ "$out" = "v$version" ]
|
2020-10-15 04:56:18 +02:00
|
|
|
}
|
|
|
|
|
2022-11-03 18:15:10 +01:00
|
|
|
if ! check_version 2>/dev/null; then
|
2023-05-10 20:32:00 +02:00
|
|
|
set -x
|
2020-10-15 04:56:18 +02:00
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
trap 'rm -r "$tmpdir"' EXIT
|
|
|
|
cd "$tmpdir"
|
2022-11-07 22:50:24 +01:00
|
|
|
curl -fLO --retry 3 "https://github.com/mvdan/sh/releases/download/v$version/$binary"
|
2020-10-15 04:56:18 +02:00
|
|
|
sha256sum -c <<<"$sha256 $binary"
|
|
|
|
chmod +x "$binary"
|
|
|
|
mv "$binary" /usr/local/bin/shfmt
|
|
|
|
check_version
|
|
|
|
fi
|