-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
142 lines (117 loc) · 3.29 KB
/
install.sh
File metadata and controls
142 lines (117 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Copyright Tim Voronov 2020
version=$(curl -sI https://github.com/go-waitfor/cli/releases/latest | grep Location | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
if [ ! "$version" ]; then
echo "Unable to detect latest version, falling back to 'latest'"
version="latest"
fi
hasCli() {
if which waitfor >/dev/null 2>&1; then
echo
echo "You already have waitfor!"
export n=3
echo "Overwriting in $n seconds.. Press Control+C to cancel."
echo
sleep $n
fi
if ! which curl >/dev/null 2>&1; then
echo "You need curl to use this script."
exit 1
fi
if ! which tar >/dev/null 2>&1; then
echo "You need tar to use this script."
exit 1
fi
}
checkHash(){
sha_cmd="sha256sum"
if [ ! -x "$(command -v "$sha_cmd")" ]; then
sha_cmd="shasum -a 256"
fi
if [ -x "$(command -v "$sha_cmd")" ]; then
if ! (cd "$targetDir" && curl -sSL "$baseUrl"/checksums.txt | "$sha_cmd" -c >/dev/null); then
echo "Binary checksum didn't match. Exiting"
exit 1
fi
fi
}
getPackage() {
uname=$(uname)
userid=$(id -u)
platform=""
case $uname in
"Darwin")
platform="_darwin"
;;
"Linux")
platform="_linux"
;;
*)
echo "Platform $uname is not supported. Exiting"
exit 1
;;
esac
uname_arch=$(uname -m)
arch=""
case $uname_arch in
"x86_64")
arch="_amd64"
;;
"aarch64"|"arm64")
arch="_arm64"
;;
*)
echo "Architecture $uname_arch is not supported. Exiting"
exit 1
;;
esac
suffix=$platform$arch
targetDir="/tmp/waitfor$suffix"
if [ "$userid" != "0" ]; then
targetDir="$(pwd)/waitfor$suffix"
fi
if [ ! -d "$targetDir" ]; then
mkdir "$targetDir"
fi
targetFile="$targetDir/waitfor"
if [ -e "$targetFile" ]; then
rm "$targetFile"
fi
if [ "$version" = "latest" ]; then
baseUrl=https://github.com/go-waitfor/cli/releases/latest/download
else
baseUrl=https://github.com/go-waitfor/cli/releases/download/$version
fi
url=$baseUrl/waitfor$suffix.tar.gz
echo "Downloading package $url as $targetFile"
if ! curl -sSL "$url" | tar xz -C "$targetDir"; then
echo "Failed to download or extract package"
exit 1
fi
checkHash
chmod +x "$targetFile"
echo "Download complete."
if [ "$userid" != "0" ]; then
echo
echo "========================================================="
echo "== As the script was run as a non-root user the =="
echo "== following commands may need to be run manually =="
echo "========================================================="
echo
echo " sudo cp \"$targetFile\" /usr/local/bin/waitfor"
echo " rm -rf \"$targetDir\""
echo
else
echo
echo "Running as root - Attempting to move \"$targetFile\" to /usr/local/bin"
if mv "$targetFile" /usr/local/bin/waitfor; then
echo "New version of waitfor installed to /usr/local/bin"
fi
if [ -d "$targetDir" ]; then
rm -rf "$targetDir"
fi
waitfor version
fi
}
hasCli
getPackage