Skip to content

Commit eacceac

Browse files
authored
Use shellcheck and shfmt to format install script (gobackup#286)
While trying to use the project's install script, I noticed that the install script could use some optimization, so I formatted the script with [shfmt](https://github.com/mvdan/sh), as well as eliminating several warnings generated by [shellcheck](https://github.com/koalaman/shellcheck). Here is the output of shellcheck on the install script before this commit, ``` $ shellcheck install In install line 10: local repo="$1" ^--------^ SC3043 (warning): In POSIX sh, 'local' is undefined. In install line 27: platform="$(uname | tr "[A-Z]" "[a-z]")" # Linux => linux ^-----^ SC2021 (info): Don't use [] around classes in tr, it replaces literal square brackets. ^-----^ SC2021 (info): Don't use [] around classes in tr, it replaces literal square brackets. In install line 36: trap "rm -r ${tmp_dir}" EXIT ^--------^ SC2064 (warning): Use single quotes, otherwise this expands now rather than when signalled. In install line 50: if test $(id -u) -eq 0; then ^------^ SC2046 (warning): Quote this to prevent word splitting. For more information: https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt... https://www.shellcheck.net/wiki/SC2064 -- Use single quotes, otherwise this... https://www.shellcheck.net/wiki/SC3043 -- In POSIX sh, 'local' is undefined. ```
1 parent 3aeb4c6 commit eacceac

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

install

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@
22

33
set -u
44

5-
type curl > /dev/null || { echo "curl: not found"; exit 1; }
5+
type curl >/dev/null || {
6+
echo "curl: not found"
7+
exit 1
8+
}
69

710
set -e
811

912
get_latest_release() {
10-
local repo="$1"
11-
curl -sSL "https://api.github.com/repos/${repo}/releases/latest" | \
13+
repo="$1"
14+
curl -sSL "https://api.github.com/repos/${repo}/releases/latest" |
1215
awk 'BEGIN{FS=": |,|\""}; /tag_name/{print $5}'
1316
}
1417

1518
repo="gobackup/gobackup"
16-
version="$(get_latest_release "${repo}")" # v1.2.0
19+
version="$(get_latest_release "${repo}")" # v1.2.0
1720

1821
# if args has version override it and not eq "latest"
19-
if test $# -eq 1; then
22+
if test "$#" -eq 1; then
2023
if test "$1" != "latest"; then
2124
version="$1"
2225

2326
echo "Install ${version}"
2427
fi
2528
fi
2629

27-
platform="$(uname | tr "[A-Z]" "[a-z]")" # Linux => linux
30+
platform="$(uname | tr "[:upper:]" "[:lower:]")" # Linux => linux
2831
arch="$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')" # x86_64 => amd64, aarch64 => arm64
2932
package="gobackup-${platform}-${arch}.tar.gz"
3033
package_url="https://github.com/${repo}/releases/download/${version}/${package}"
@@ -33,6 +36,7 @@ dest_dir="/usr/local/bin"
3336
bin_path="${dest_dir}/${bin}"
3437
tmp_dir="$(mktemp -d)"
3538

39+
# shellcheck disable=SC2064
3640
trap "rm -r ${tmp_dir}" EXIT
3741

3842
if test -e "${bin_path}"; then
@@ -47,7 +51,7 @@ fi
4751
cd "${tmp_dir}"
4852
curl -sSL "${package_url}" | tar xzf -
4953

50-
if test $(id -u) -eq 0; then
54+
if test "$(id -u)" -eq 0; then
5155
mv "${bin}" "${dest_dir}"
5256
else
5357
sudo mv "${bin}" "${dest_dir}"

0 commit comments

Comments
 (0)