-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.brio-br
237 lines (231 loc) · 7.79 KB
/
install.brio-br
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
#!/bin/bash
# 'install.brio-br' - A script to install 'brio-br' and associated links to '/usr/local/bin' as root (default)
##
#########################
### Declare variables ###
#########################
##
APPL='install.brio-br'
APPLBR='brio-br'
BIN=${BIN:-/usr/local/bin}
BBRURL='https://raw.githubusercontent.com/DennisLfromGA/brunch-things/main/brio-br'
CWD="$(pwd)"
IBBRURL='https://raw.githubusercontent.com/DennisLfromGA/brunch-things/main/install.brio-br'
INSTRUCTIONS="
IMPORTANT: To initially download, install & run this script enter:
cd /tmp &&\\
curl -LO ${IBBRURL} &&\\
sudo install -Dt /usr/local/bin -m 755 ${APPL} && ${BIN}/${APPL}
Once installed the script will autoupdate if needed when it's run.
"
PERM=${PERM:-755}
OPTIONS="\
Options:
-h Displays help message for options (this blurb)
-i Displays instructions for initial download, install and running this script
-l Lists installed files & links under ${BIN}
-u Displays usage for backup and restore
-f Force update of brio-br & install.brio-br
-c Check if installed versions of '${APPL}' & '${APPLBR}' are up-to-date
-v Displays the current version of '${APPL}'
-V Displays version number plus version history
"
SUDO=${SUDO:-sudo}
UPDATE="${UPDATE:-n}"
USAGE="
'${APPL}': A script to install '${APPLBR}' and associated links to '/usr/local/bin' as root (default)
${INSTRUCTIONS}
Will link: 'brio-b' & 'brio-backup' to '${APPLBR}' which forces those scripts to run the 'backup' option.
Will link: 'brio-r' & 'brio-restore' to '${APPLBR}' which forces those scripts to run the 'restore' option.
Usage: '${APPL}' [-h|-i|-l|-u|-f|-c|-v|-V] (see Help/Options)
Note: To replace the install PATH (default: /usr/local/bin) prepend '${APPL}' with BIN=your/path
To replace the file permissions (default 755) prepend '${APPL}' with PERM=nnn
To execute '${APPL}' as user '${USER}' instead of 'root' (default) prepend '${APPL}' with SUDO=' '
(I.E.) BIN=~/bin PERM=775 SUDO=' ' ${APPL}
"
# VERSION format: "n.n.$(date +%Y%m%d%H%M)"
VERSION='3.1.0.202109111642'
VERHIST="\
${APPL}-3.1.0.202109111642 : Added option '-f' to force update of brio-br & install.brio-br
${APPL}-3.0.0.202109071554 : Added autoupdate feature for install.brio-br
${APPL}-2.0.2.202109061732 : Changed URLS from gists to a repo for install.brio-br & brio-br
${APPL}-2.0.1.202109061542 : Added option to force an update of brio-br
${APPL}-2.0.0.202109061536 : Added update check of both install.brio-br & brio-br
${APPL}-1.6.1.202109061244 : Made mostly minor cosmetic changes to display
${APPL}-1.6.0.202109061236 : Added 3rd digit to VERSION for minor tweaks
${APPL}-1.5.202109051624 : Added 'list files' to options
${APPL}-1.5.202109051624 + Misc. tweaks to functions, clarified file listing location, etc.
${APPL}-1.4.202109051455 : Minor tweak to 'valid responses' for instructions - duh!
${APPL}-1.3.202109051436 : Tweaked to include instructions option throughout
${APPL}-1.2.202109051325 : Added instructions to download, install & execute this script
${APPL}-1.1.202109051151 : Added raw link to download 'brio-br' and command-line options
${APPL}-1.0.202109041942 : Initial script to install 'brio-br' and associated links"
##
#######################
### Setup functions ###
#######################
##
## exit with exit code $1, spitting out message $@ to stderr
echo_e='/bin/echo -e'
error() {
local ecode="${1}"
shift
${echo_e} "${*}" 1>&2
exit "${ecode}"
}
##
check_for_opts() {
## Get command line parameters
local OPTIND
while getopts hoilufcvV OPT; do
case ${OPT} in
h|o) error 0 "${OPTIONS}";;
i) error 0 "${INSTRUCTIONS}";;
l) cd ${BIN} 1>/dev/null
echo; echo "File listing under ${BIN}:"
ls -li ${APPLBR} brio-b brio-backup brio-r brio-restore ${APPL}
exit 0;;
u) error 0 "${USAGE}";;
c) check_versions; exit;;
f) UPDATE=y; echo "Updates requested ...";;
v) echo "${VERHIST}" | grep ${VERSION}; exit 0 ;;
V) error 0 "VERSION:${VERSION}\n${VERHIST}" ;;
\?) error 1 "${USAGE}\n${OPTIONS}";;
esac
done
shift "$((OPTIND-1))"
if [ "${#}" -gt 0 ]; then
echo "${APPL}: invalid option -- ${1}"
error 1 "${USAGE}\n${OPTIONS}"
fi
}
##
check_versions() {
cd /tmp 1>/dev/null
if curl -sLO ${BBRURL} && diff -qw ${APPLBR} /usr/local/bin; then
echo "Your installed version of '${APPLBR}' is up-to-date and good to go ..."
else
echo "Your installed version of '${APPLBR}' is missing or NOT up-to-date, update requested ..."
UPDATE=b
fi
if curl -sLO ${IBBRURL} && diff -qw ${APPL} /usr/local/bin; then
echo "Your installed version of '${APPL}' is up-to-date and good to go ..."
else
echo "Your installed version of '${APPL}' is missing or NOT up-to-date, an update will be done now ..."
UPDATE=i
fi
echo
}
##
ask_nicely() {
local REPLY=''
if [ "${UPDATE}" = "b" -o "${UPDATE}" = "y" ]; then
echo "Install '${APPLBR}' and associated links to '${BIN}' as root (default) [Ysilhq] ?"
read -s -n 1 -p "Enter 'y' to install, 'i' for installation instructions, 'l' to list, 'c' check versions, 'h' for help, or 'q' to quit ? "
echo
case ${REPLY:-Y} in
[yY])
echo; echo "Installing '${APPLBR}' and links to ${BIN} ..."
;;
[iI])
error 0 "${INSTRUCTIONS}"
;;
[lL])
cd ${BIN} 1>/dev/null
echo; echo "File listing under ${BIN}:"
ls -li ${APPLBR} brio-b brio-backup brio-r brio-restore ${APPL}
echo; ask_nicely
;;
[hH]|[oO])
echo "${OPTIONS}"
ask_nicely
;;
[uU])
echo "${USAGE}"
ask_nicely
;;
[cC])
check_versions
ask_nicely
;;
[qQ]|[aA])
echo; error 0 "Aborting/Quitting ..."
;;
v)
echo; echo "${VERHIST}" | grep ${VERSION}
echo; ask_nicely
;;
V)
echo; echo "VERSION:${VERSION}"
echo "${VERHIST}"
echo; ask_nicely
;;
*)
echo "Sorry, valid responses are:"
echo; echo " 'y' to install, 'i' for installation instructions, 'l' to list, 'h' for help, or 'q' to quit."
echo; ask_nicely
;;
esac
else
error 0 "No updates needed or requested, exiting ..."
fi
}
##
install_brio-br() {
cd /tmp 1>/dev/null
echo "Downloading '${APPLBR}' ..."
curl -sLO --progress-bar ${BBRURL} || \
error 2 "Cannot download '${APPLBR}'"
echo "Removing installed '${APPLBR}', if any ..."
${SUDO} rm -f ${BIN}/${APPLBR} 2>/dev/null || \
error 2 "Cannot remove existing '${APPLBR}'"
echo "Installing an updated '${APPLBR}' ..."
${SUDO} install -Dt ${BIN} -m 755 /tmp/${APPLBR} || \
error 3 "Cannot install '${APPLBR}'"
## Using hard links to avoid 'nosymfollow'
echo "Linking apps to '${APPLBR}' ..."
${SUDO} ln -fT ${BIN}/${APPLBR} ${BIN}/brio-b || \
error 4 "Cannot link '${APPLBR}' as 'brio-b'"
${SUDO} ln -fT ${BIN}/${APPLBR} ${BIN}/brio-backup || \
error 4 "Cannot link '${APPLBR}' as 'brio-backup'"
${SUDO} ln -fT ${BIN}/${APPLBR} ${BIN}/brio-r || \
error 4 "Cannot link '${APPLBR}' as 'brio-r'"
${SUDO} ln -fT ${BIN}/${APPLBR} ${BIN}/brio-restore || \
error 4 "Cannot link '${APPLBR}' as 'brio-restore'"
}
##
install_installer() {
if [ "${UPDATE}" = "i" -o "${UPDATE}" = "y" ]; then
cd /tmp 1>/dev/null
echo "Downloading '${APPL}' ..."
curl -sLO --progress-bar ${IBBRURL} || \
error 2 "Cannot download '${APPL}'"
echo "Removing installed '${APPL}', if any ..."
${SUDO} rm -f ${BIN}/${APPL} 2>/dev/null ||
error 2 "Cannot remove existing '${APPL}'"
echo "Installing an updated '${APPL}' ..."
sudo install -Dt /usr/local/bin -m 755 ${APPL} || \
error 3 "Cannot install '${APPL}'"
echo "'${APPL}' updated and installed, now launching it ..."
echo; exec ${BIN}/${APPL} || \
error 4 "Cannot execute '${APPL}'"
exit
fi
}
##
###########################
### Main section ###
###########################
##
if [ $(id -u) -eq 0 ]; then
echo
echo "ERROR: ${APPL} must NOT be run as root!"
error 1 "${USAGE}"
fi
check_for_opts "${@}"
check_versions
ask_nicely
install_brio-br
install_installer
cd ${CWD} 1>/dev/null
error 0 "'${APPL}' successful, exiting."