-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·284 lines (239 loc) · 5.16 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/usr/bin/env sh
set -e
ARCH=`uname -m`
OS=`uname -s`
VERSION="0.19.6"
# Note: Should we be proactive and use /var/tmp instead?
TMP_PATH=/tmp/ferret
INSTALL_DIR=/opt/ferret
OPT_BIN_FILE=/opt/ferret/bin/ferret
USR_BIN_FILE=/usr/bin/ferret
DEB_FILE="ferret_$VERSION-1_amd64.deb"
RPM_FILE="ferret-$VERSION-1.x86_64.rpm"
LIN_DIR="ferret-$VERSION-linux-x86_64"
LIN_FILE="$LIN_DIR.tar.gz"
MAC_DIR="ferret-$VERSION-mac-x86_64"
MAC_FILE="$MAC_DIR.tar.gz"
SUM_FILE=sha256_sums.txt
RELEASE_URL="https://github.com/forthright/ferret_temp/releases/download/$VERSION"
DOWNLOAD=""
PACKAGER=""
cleanup() {
if [ -d "$TMP_PATH" ]; then
rm -rf "$TMP_PATH"
fi
}
trap cleanup EXIT
as_root() {
UID=`id -u`
if [ $UID -eq 0 ]; then
"$@"
else
echo "We need to run a few commands as root..."
if [ ! -z $(command -v sudo) ]; then
sudo -k "$@"
elif [ ! -z $(command -v su) ]; then
su root -c "$@"
else
echo "Can't continue without sudo/su." && exit 1
fi
fi
}
get_shasums() {
"$DOWNLOAD $RELEASE_URL/$SUM_FILE" > "$TMP_PATH/$SUM_FILE"
}
check_arch() {
case $ARCH in
x86_64)
echo " -> $ARCH: ok"
;;
*)
echo ""
echo "$ARCH not supported" && exit 1
;;
esac
}
check_packager() {
if [ ! -z "$(command -v pacman)" ]; then
PACKAGER="pacman"
elif [ ! -z "$(command -v yast)" ]; then
PACKAGER="yast"
elif [ ! -z "$(command -v dnf)" ]; then
PACKAGER="dnf"
elif [ ! -z "$(command -v yum)" ]; then
PACKAGER="yum"
# TODO
#elif [ ! -z "$(command -v add-apt-repository)" ]; then
#PACKAGER="add-apt-repository"
#elif [ ! -z "$(command -v apt)" ]; then
elif [ ! -z "$(command -v dpkg)" ]; then
PACKAGER="dpkg"
elif [ "$OS" = "Darwin" ] && [ ! -z "$(command -v brew)" ]; then
PACKAGER="brew"
fi
}
check_for_shasum() {
if [ -z "$(command -v shasum)" ]; then
echo ""
echo "Need shasum installed"
exit 1
fi
}
check_can_download() {
if [ ! -z "$(command -v curl)" ]; then
DOWNLOAD="curl -fL "
elif [ ! -z "$(command -v wget)" ]; then
DOWNLOAD="wget -qO- "
else
echo ""
echo "Need wget or curl installed"
exit 1
fi
}
check_sums() {
cd $TMP_PATH
shasum -a 256 -c $SUM_FILE
cd -
}
get_rpm() {
$URL="$RELEASE_URL/$RPM_FILE"
echo "==> Downloding $URL"
"$DOWNLOAD $URL" > "$TMP_PATH/$RPM_FILE"
check_sums
}
get_deb() {
$URL="$RELEASE_URL/$DEB_FILE"
echo "==> Downloding $URL"
"$DOWNLOAD $URL" > "$TMP_PATH/$DEB_FILE"
check_sums
}
extract_tarball() {
echo "==> Extracting $TARBALL"
TARBALL=$0
cd $TMP_PATH
shasum -a 256 -c $SUM_FILE
tar -xvf "$TARBALL"
cd -
}
get_tarball() {
$FILE_NAME=$0
$URL="$RELEASE_URL/$FILE_NAME"
echo "==> Downloading $FILE_NAME"
"$DOWNLOAD $URL" > "$TMP_PATH/$FILE_NAME"
}
install_files() {
$PKGDIR=$0
echo "==> Installing files..."
if [ -d "$INSTALL_DIR" ]; then
# in case we have a previous install
as_root rm -rf $INSTALL_DIR
fi
as_root mkdir -p $INSTALL_DIR
as_root cp -r $PKGDIR/* $INSTALL_DIR
as_root ln -s $OPT_BIN_FILE $USR_BIN_FILE
}
install_mac_tarball() {
get_tarball $MAC_FILE
extract_tarball $MAC_FILE
as_root install_files $MAC_DIR
}
install_linux_tarball() {
get_tarball $LIN_FILE
extract_tarball $LIN_FILE
as_root install_files $LIN_DIR
}
install_via_tarball() {
if [ $OS = "Darwin" ]; then
install_mac_tarball
elif [ $OS = "Linux" ]; then
install_linux_tarball
else
echo "$OS-$ARCH not supported. Please see manual instructions:"
echo " https://docs.ferretci.com/start"
exit 0
fi
}
install_via_pacman() {
echo " -> Installing pacaur for AUR support"
as_root pacman -S pacaur --noconfirm
as_root pacaur -S ferret-bin --noconfirm
}
install_via_yast() {
get_rpm
as_root yast -i -y "$TMP_PATH/$RPM_FILE"
}
install_via_dnf() {
get_rpm
as_root dnf install -y "$TMP_PATH/$RPM_FILE"
}
install_via_yum() {
get_rpm
as_root yum install -y "$TMP_PATH/$RPM_FILE"
}
install_via_dpkg() {
get_deb
as_root dpkg -i -y "$TMP_PATH/$DEB_FILE"
}
install_via_homebrew() {
brew tap forthright/ferret
brew install -y ferret
}
configure() {
mkdir -p "$TMP_PATH"
check_arch
check_for_shasum
echo " -> shasum: ok"
echo " -> curl/wget: ok"
check_can_download
echo "==> Getting checksums"
get_shasums
echo "==> Checking for local package managers"
check_packager
if [ -z "$PACKAGER" ]; then
echo " -> No supported package manager detected"
echo " -> Falling back to manual install method"
else
echo " -> Using $PACKAGER"
fi
}
install() {
case $PACKAGER in
pacman)
install_via_pacman
;;
yast)
install_via_yast
;;
dnf)
install_via_dnf
;;
yum)
install_via_yum
;;
# TODO: detect + install via ppa/apt/add-apt-repository
# apt)
dpkg)
install_via_dpkg
;;
brew)
install_via_homebrew
;;
*)
install_via_tarball
;;
esac
}
install() {
echo "==> Configuring environment"
configure
echo "==> Installing package"
install
echo ""
if [ ! -z "$(command -v ferret)" ]; then
echo "Success! Run \`ferret -h\` for usage."
exit 1
else
echo "Fail! Can't detect $USR_BIN_FILE?"
fi
}
install