-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Install
executable file
·291 lines (273 loc) · 8.19 KB
/
Install
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
285
286
287
288
289
290
291
#!/bin/bash
#
# Usage: ./Install [package names]
# If no package names are specified then all currently
# supported packages will be installed
#
# Versions of apt prior to 1.1 do not support install by Debian filename
# You should probably be running a more recent version of apt
# On these early versions, install with the following:
#
# sudo dpkg -i "${PKG}"
# sudo apt-get install -f
#
# shellcheck disable=SC2001
PKG_NAMES="Asciiville asciiville"
DEB_ARCH=amd64
RPM_ARCH=x86_64
BOLD=$(tput bold)
NORMAL=$(tput sgr0)
PKG_AVAILABLE=
PKG_SELECTED=
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
[ -f "${SCRIPT_DIR}/VERSION" ] || {
echo "Missing VERSION file: ${SCRIPT_DIR}/VERSION"
echo "Exiting"
exit 1
}
. "${SCRIPT_DIR}/VERSION"
PKG_VER=${VERSION}
PKG_REL=${RELEASE}
platform=$(uname -s)
[ "${platform}" == "Darwin" ] && {
darwin_archive=
if [ -f releases/${PKG_VER}/Asciiville_${PKG_VER}-${PKG_REL}.Darwin.tgz ]; then
darwin_archive="releases/${PKG_VER}/Asciiville_${PKG_VER}-${PKG_REL}.Darwin.tgz"
else
# Look for other versions
for release in releases/*/Asciiville_*-*.Darwin.*; do
[ "${release}" == "releases/*/Asciiville_*-*.Darwin.*" ] && {
./mkpkg -i
for build in releases/*/Asciiville_*-*.Darwin.*; do
[ "${build}" == "releases/*/Asciiville_*-*.Darwin.*" ] && {
echo "No Darwin release archives located in ./releases/..."
echo "Download the latest Asciiville release archive for macOS at"
echo " https://github.com/doctorfree/Asciiville/releases/latest"
echo "Exiting"
exit 1
}
done
release="${build}"
darwin_archive="${release}"
}
echo "Located Asciiville release archive for macOS:"
echo " ${release}"
done
fi
if [ "${darwin_archive}" ]; then
sudo pkg/Install-bin.sh "${darwin_archive}"
exit 0
else
echo "Version and Release in VERSION do not match located release archive(s)"
echo "Install one of these located release archives manually with the command:"
echo " sudo pkg/Install-bin.sh releases/.../<archive_name>.Darwin.<suffix>"
echo "Exiting without installing"
exit 1
fi
}
get_available_packages() {
for pkgs in "${SCRIPT_DIR}"/releases/"${PKG_VER}"/*."${SUF}"; do
[ "${pkgs}" == "${SCRIPT_DIR}/releases/${PKG_VER}/*.${SUF}" ] || {
for pkg in ${pkgs}; do
if [ "${arch}" ]; then
pkgname=$(basename "${pkg}" | sed -e "s/-v${PKG_VER}r${PKG_REL}-${PACKAGE}-${ARCH}.${SUF}//")
else
pkgname=$(basename "${pkg}" | sed -e "s/_${PKG_VER}-${PKG_REL}.${SUF}//")
fi
PKG_AVAILABLE="${PKG_AVAILABLE} ${pkgname}"
done
}
done
PKG_AVAILABLE=$(echo "${PKG_AVAILABLE}" | sed -e "s/^ //")
}
install_selected() {
for pkg in ${PKG_AVAILABLE}; do
while true; do
read -r -p "Install ${pkg} ? ('Y'/'N'): " yn
case $yn in
[Yy]*)
PKG_SELECTED="${PKG_SELECTED} $pkg"
break
;;
[Nn]*)
break
;;
*)
echo "Please answer yes or no."
;;
esac
done
done
PKG_SELECTED=$(echo "${PKG_SELECTED}" | sed -e "s/^ //")
}
debian=
arch=
have_apt=$(type -p apt)
have_dpkg=$(type -p dpkg)
have_rpm=$(type -p rpm)
have_dnf=$(type -p dnf)
have_pac=$(type -p pacman)
[ -f /etc/os-release ] && . /etc/os-release
[ "${ID_LIKE}" == "debian" ] && debian=1
[ "${ID}" == "arch" ] || [ "${ID_LIKE}" == "arch" ] && arch=1
[ "${debian}" ] || [ -f /etc/debian_version ] && debian=1
[ "${arch}" ] || [ "${debian}" ] || {
echo "${ID_LIKE}" | grep debian >/dev/null && debian=1
}
if [ "${debian}" ]; then
SUF=deb
[ "${have_dpkg}" ] && {
dpkg_arch=$(dpkg --print-architecture)
[ "${dpkg_arch}" == "${DEB_ARCH}" ] || DEB_ARCH=${dpkg_arch}
}
ARCH=${DEB_ARCH}
else
if [ "${arch}" ]; then
SUF=zst
ARCH="any"
else
SUF=rpm
ARCH=${RPM_ARCH}
fi
fi
[ -d releases/${PKG_VER} ] || ./mkpkg -i
get_available_packages
[ "${PKG_AVAILABLE}" ] || {
system_archive=
if [ -f releases/${PKG_VER}/Asciiville_${PKG_VER}-${PKG_REL}.Linux.tgz ]; then
system_archive="releases/${PKG_VER}/Asciiville_${PKG_VER}-${PKG_REL}.Linux.tgz"
else
# Look for other versions
for release in releases/*/Asciiville_*-*.Linux.*; do
[ "${release}" == "releases/*/Asciiville_*-*.Linux.*" ] && {
./mkpkg -i
for build in releases/*/Asciiville_*-*.Linux.*; do
[ "${build}" == "releases/*/Asciiville_*-*.Linux.*" ] && {
echo "No Linux release archives located in ./releases/..."
echo "Download the latest Asciiville release archive for Linux at"
echo " https://github.com/doctorfree/Asciiville/releases/latest"
echo "Exiting"
exit 1
}
done
release="${build}"
system_archive="${release}"
}
echo "Located Asciiville release archive for Linux:"
echo " ${release}"
done
fi
if [ "${system_archive}" ]; then
sudo pkg/Install-bin.sh "${system_archive}"
exit 0
else
echo "Version and Release in VERSION do not match located release archive(s)"
echo "Install one of these located release archives manually with the command:"
echo " sudo pkg/Install-bin.sh releases/.../<archive_name>.Linux.<suffix>"
echo "Exiting without installing"
exit 1
fi
}
[ "$1" ] && {
# If invoked with -i argument, present a menu of options to select from
if [ "$1" == "-i" ]; then
shift
PKG_NAMES="$*"
[ "${PKG_AVAILABLE}" ] && {
echo "Currently available Asciiville packages:"
echo ""
for avaipkg in ${PKG_AVAILABLE}; do
echo "$avaipkg"
done
echo ""
}
while true; do
PS3="${BOLD}Please enter your desire (numeric or text): ${NORMAL}"
options=("Install All" "Install Selected" "Quit")
select opt in "${options[@]}"; do
case "$opt,$REPLY" in
"Install All",* | *,"Install All")
PKG_NAMES="${PKG_AVAILABLE}"
break 2
;;
"Install Selected",* | *,"Install Selected")
install_selected
PKG_NAMES="${PKG_SELECTED}"
break 2
;;
"Quit",* | *,"Quit" | "quit",* | *,"quit")
printf "\nExiting\n"
exit 0
;;
esac
done
done
else
PKG_NAMES="$*"
fi
}
[ "${PKG_NAMES}" ] || {
echo "No valid Package names specified. Exiting."
exit 1
}
for PKG_NAME in ${PKG_NAMES}; do
if [ "${arch}" ]; then
PKG="${SCRIPT_DIR}/releases/${PKG_VER}/${PKG_NAME}-v${PKG_VER}r${PKG_REL}-${PACKAGE}-${ARCH}.pkg.tar.${SUF}"
else
PKG="${SCRIPT_DIR}/releases/${PKG_VER}/${PKG_NAME}_${PKG_VER}-${PKG_REL}.${SUF}"
fi
[ -f "${PKG}" ] || {
if [ "${arch}" ]; then
echo "${PKG_NAME}-v${PKG_VER}r${PKG_REL}-${PACKAGE}-${ARCH}.pkg.tar.${SUF} not found."
for pkgs in "${SCRIPT_DIR}"/releases/*/"${PKG_NAME}"-*."${SUF}"; do
[ "${pkgs}" == "${SCRIPT_DIR}/releases/*/${PKG_NAME}-*.${SUF}" ] || {
echo "Found existing packages:"
echo "${pkgs}"
}
done
else
echo "${PKG_NAME}_${PKG_VER}-${PKG_REL}.${SUF} not found."
for pkgs in "${SCRIPT_DIR}"/releases/*/"${PKG_NAME}"_*."${SUF}"; do
[ "${pkgs}" == "${SCRIPT_DIR}/releases/*/${PKG_NAME}_*.${SUF}" ] || {
echo "Found existing packages:"
echo "${pkgs}"
}
done
fi
echo ""
continue
}
echo "Installing ${PKG}"
if [ "${debian}" ]; then
if [ "${have_apt}" ]; then
sudo apt update -y -qq
sudo apt install "${PKG}"
else
if [ "${have_dpkg}" ]; then
sudo dpkg -i "${PKG}"
else
echo "Cannot locate either apt or dpkg to install. Skipping."
fi
fi
else
if [ "${arch}" ]; then
if [ "${have_pac}" ]; then
sudo pacman -U "${PKG}"
else
echo "Cannot locate pacman to install. Skipping."
fi
else
if [ "${have_dnf}" ]; then
sudo dnf update -y -q
sudo dnf localinstall "${PKG}"
else
if [ "${have_rpm}" ]; then
sudo rpm -i "${PKG}"
else
echo "Cannot locate either dnf or rpm to install. Skipping."
fi
fi
fi
fi
break
done