forked from MontFerret/ferret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
171 lines (134 loc) · 3.7 KB
/
install.sh
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
defaultLocation="/usr/local/bin"
defaultVersion="latest"
location=${LAB_LOCATION:-$defaultLocation}
version=${LAB_VERSION:-$defaultVersion}
# Copyright MontFerret Team 2020
version=$(curl -sI https://github.com/MontFerret/ferret/releases/latest | awk '{print tolower($0)}' | grep location: | awk -F"/" '{ printf "%s", $NF }' | tr -d '\r')
echo "Installing Ferret $version to $location"
if [ ! $version ]; then
echo "Failed while attempting to install ferret-cli. Please manually install:"
echo ""
echo "1. Open your web browser and go to https://github.com/MontFerret/ferret/releases"
echo "2. Download the latest release for your platform."
echo "3. chmod +x ./ferret"
echo "4. mv ./ferret $location"
exit 1
fi
hasCli() {
has=$(which ferret)
if [ "$?" = "0" ]; then
echo
echo "You already have the ferret!"
export n=5
echo "Overwriting in $n seconds... Press Control+C to cancel."
echo
sleep $n
fi
hasCurl=$(which curl)
if [ "$?" = "1" ]; then
echo "You need curl to use this script."
exit 1
fi
hasTar=$(which tar)
if [ "$?" = "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
(cd $targetDir && curl -sSL $baseUrl/ferret_checksums.txt | $sha_cmd -c >/dev/null)
if [ "$?" != "0" ]; then
# rm $targetFile
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"
;;
esac
uname=$(uname -m)
arch=""
case $uname in
"x86_64")
arch="_x86_64"
;;
esac
case $uname in
"aarch64")
arch="_arm64"
;;
esac
if [ "$arch" = "" ]; then
echo "$arch is not supported. Exiting"
exit 1
fi
suffix=$platform$arch
targetDir="/tmp/ferret$suffix"
if [ "$userid" != "0" ]; then
targetDir="$(pwd)/ferret$suffix"
fi
if [ ! -d $targetDir ]; then
mkdir $targetDir
fi
targetFile="$targetDir/ferret"
if [ -e $targetFile ]; then
rm $targetFile
fi
echo
if [ $location = $defaultLocation ]; then
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 $location/ferret"
echo " rm -rf $targetDir"
echo
exit 1
fi
fi
if [ ! -d $location ]; then
mkdir $location
fi
baseUrl=https://github.com/MontFerret/ferret/releases/download/$version
url=$baseUrl/ferret$suffix.tar.gz
echo "Downloading package $url as $targetFile"
curl -sSL $url | tar xz -C $targetDir
if [ "$?" != "0" ]; then
echo "Failed to download file"
exit 1
fi
# checkHash
chmod +x $targetFile
echo "Download complete."
echo
echo "Attempting to move $targetFile to $location"
mv $targetFile "$location/ferret"
if [ "$?" = "0" ]; then
echo "New version of ferret installed to $location"
fi
if [ -d $targetDir ]; then
rm -rf $targetDir
fi
"$location/ferret" --version
}
hasCli
getPackage