2020-10-15 04:56:18 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
|
2023-07-21 22:56:45 +02:00
|
|
|
version=3.7.0
|
2021-05-27 09:16:55 +02:00
|
|
|
arch="$(uname -m)"
|
|
|
|
|
|
|
|
case $arch in
|
|
|
|
"x86_64")
|
|
|
|
binary="shfmt_v${version}_linux_amd64"
|
2023-07-21 22:56:45 +02:00
|
|
|
sha256=0264c424278b18e22453fe523ec01a19805ce3b8ebf18eaf3aadc1edc23f42e3
|
2021-05-27 09:16:55 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
"aarch64")
|
|
|
|
binary="shfmt_v${version}_linux_arm64"
|
2023-07-21 22:56:45 +02:00
|
|
|
sha256=111612560d15bd53d8e8f8f85731176ce12f3b418ec473d39a40ed6bbec772de
|
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
|