2020-10-15 04:56:18 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
|
2022-07-06 06:10:28 +02:00
|
|
|
version=3.5.1
|
2021-05-27 09:16:55 +02:00
|
|
|
arch="$(uname -m)"
|
|
|
|
|
|
|
|
case $arch in
|
|
|
|
"x86_64")
|
|
|
|
binary="shfmt_v${version}_linux_amd64"
|
2022-07-06 06:10:28 +02:00
|
|
|
sha256=56099a689b68534f98e1f8f05d3df6750ab53e3db68f514ee45595bf5b79d158
|
2021-05-27 09:16:55 +02:00
|
|
|
;;
|
|
|
|
|
|
|
|
"aarch64")
|
|
|
|
binary="shfmt_v${version}_linux_arm64"
|
2022-07-06 06:10:28 +02:00
|
|
|
sha256=09d7902de04d52ebe0b332d84a9746d195f7e930806bdc2436f84d0de6a2d368
|
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
|
2020-10-15 04:56:18 +02:00
|
|
|
tmpdir="$(mktemp -d)"
|
|
|
|
trap 'rm -r "$tmpdir"' EXIT
|
|
|
|
cd "$tmpdir"
|
2021-07-13 21:00:50 +02:00
|
|
|
curl -fLO "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
|