2020-10-15 04:56:18 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
|
2024-11-05 21:48:20 +01:00
|
|
|
version=3.10.0
|
2021-05-27 09:16:55 +02:00
|
|
|
arch="$(uname -m)"
|
|
|
|
|
|
|
|
case $arch in
|
|
|
|
"x86_64")
|
|
|
|
binary="shfmt_v${version}_linux_amd64"
|
2024-11-05 21:48:20 +01:00
|
|
|
sha256=1f57a384d59542f8fac5f503da1f3ea44242f46dff969569e80b524d64b71dbc
|
2021-05-27 09:16:55 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
"aarch64")
|
|
|
|
binary="shfmt_v${version}_linux_arm64"
|
2024-11-05 21:48:20 +01:00
|
|
|
sha256=9d23013d56640e228732fd2a04a9ede0ab46bc2d764bf22a4a35fb1b14d707a8
|
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
|