-
Notifications
You must be signed in to change notification settings - Fork 0
/
shellshoccar.sh
317 lines (297 loc) · 9.64 KB
/
shellshoccar.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/sh
######################################################################
#
# SHELLSHOCCAR.SH : A Installer of Shellshoccar Command set
#
# What is Shellshoccar command set?
#
# It is an additional set of commands for shellscript-programming.
# It makes shellscript programming more powerful!
# All of the commands are written within the POSIX specification.
# It means that the commands and the programs using only that get
# STRONGLY COMPATIBLITY and PORTABILITY and SUSTAINABILITY!!!
#
# Usage : shellshoccar.sh [--prefix=/PATH/TO/INSTALL/DIR] <install|uninstall>
#
# Written by Rich Mikan (richmikan[at]richlab.org) at 2019-05-22
#
# This is a public-domain software. It measns that all of the people
# can use this with no restrictions at all. By the way, I am fed up
# the side effects which are broght about by the major licenses.
#
######################################################################
######################################################################
# Initial Configuration
######################################################################
# === Initialize shell environment ===================================
set -u
umask 0022
export LC_ALL=C
type command >/dev/null 2>&1 && type getconf >/dev/null 2>&1 &&
export PATH="$(command -p getconf PATH)${PATH+:}${PATH-}"
export POSIXLY_CORRECT=1 # to make Linux comply with POSIX
export UNIX_STD=2003 # to make HP-UX comply with POSIX
# === Define the functions for printing usage and error message ======
print_usage_and_exit () {
cat <<-USAGE 1>&2
Usage : ${0##*/} [--prefix=/PATH/TO/INSTALL/DIR] <install|uninstall>
Version : 2019-05-22 21:32:36 JST
USAGE
exit 1
}
######################################################################
# Parse arguments
######################################################################
# === Get the options ================================================
# --- initialize option parameters -----------------------------------
Dir_prefix='/usr/local/shellshoccar'
mode=''
#
# --- get them -------------------------------------------------------
while [ $# -gt 0 ]; do
case "${1:-}" in
--prefix=*) Dir_prefix=$(printf '%s' "${1#--prefix=}" | tr -d '\n')
shift
;;
install) mode='install'
shift
;;
uninstall) mode='uninstall'
shift
;;
*) print_usage_and_exit
;;
esac
done
case "$mode" in '') print_usage_and_exit;; esac
######################################################################
# Main
######################################################################
# === Prepare ========================================================
case "$Dir_prefix" in /*) :;; */) Dir_prefix=${Dir_prefix%/};; esac
case "$Dir_prefix" in
/*) : ;;
*/*) s=$(eval cd "${Dir_prefix%/*}" && pwd)
case "$s" in '')
echo "${0##*/}: directory by --prefix is not proper" 1>&2
exit 1 ;;
esac
Dir_prefix="$s/${Dir_prefix##*/}" ;;
*) s=$(pwd)
Dir_prefix="$s/$Dir_prefix" ;;
esac
File_instlog="${Dir_prefix%/}/log/shellshoccar_inst.log"
# === MAIN (for uninstaill) ==========================================
#
# --- start of the block ---------------------------------------------
case "$mode" in uninstall)
#
# --- confirm --------------------------------------------------------
[ -f "$File_instlog" ] || {
echo "${0##*/}: No installing record! (make sure the directory)" 1>&2
exit 1
}
#
# --- uninstall ------------------------------------------------------
(cd "$Dir_prefix/.." && rm -rf "$Dir_prefix") || {
echo "${0##*/}: Failed to uninstall" 1>&2
exit 1
}
exit 0
#
# --- end of the block -----------------------------------------------
;; esac
# ===== MAIN (for instaill) ==========================================
#
# --- start of the block ---------------------------------------------
case "$mode" in install)
#
# --- make target directories ----------------------------------------
mkdir -p "${Dir_prefix%/}/bin" "${Dir_prefix%/}/log" "${Dir_prefix%/}/tmp" || {
echo "${0##*/}: Cannot make the directory of Shellshoccar" 1>&2
exit 1
}
cd "${Dir_prefix%/}/tmp" || {
echo "${0##*/}: Not enough permission to install this to $Dir_prefix" 1>&2
exit 1
}
File_instlog="$(cd "../log"; pwd)/${File_instlog##*/}"
echo 1 > 'permissioncheck' 2>/dev/null || {
echo "${0##*/}: Not enough permission to install this to $Dir_prefix" 1>&2
exit 1
}
rm -rf *
#
# --- A) if git command is ready, install with it --------------------
if type git >/dev/null 2>&1; then
# A-01) prepare
ok=0
ng=0
# A-11) install "Open usp Tukubai clone"
fSuccess=0
while :; do
git clone --depth=1 https://github.com/ShellShoccar-jpn/Open-usp-Tukubai.git || break
rm -rf Open-usp-Tukubai/COMMANDS.SH/previous.ver
mv -f Open-usp-Tukubai/COMMANDS.SH/* ../bin || break
fSuccess=1
break; done
case $fSuccess in
0) echo "${0##*/}: Failed to install \"Open usp Tukubai clone\"" 1>&2
ng=$((ng+1));;
*) ok=$((ok+1));;
esac
rm -rf "${Dir_prefix%/}/tmp/"*
# A-12) install "misc-tools"
fSuccess=0
while :; do
git clone --depth=1 https://github.com/ShellShoccar-jpn/misc-tools.git || break
misc-tools/C_SRC/MAKE.sh -u || {
echo "${0##*/}: Some C-prog couldn't be compiled" 1>&2
}
mv -f misc-tools/[a-z0-9]* ../bin || break
fSuccess=1
break; done
case $fSuccess in
0) echo "${0##*/}: Failed to install \"misc-tools\"" 1>&2
ng=$((ng+1));;
*) ok=$((ok+1));;
esac
rm -rf "${Dir_prefix%/}/tmp/"*
# A-13) install "Parsrs"
fSuccess=0
while :; do
git clone --depth=1 https://github.com/ShellShoccar-jpn/Parsrs.git || break
mv -f Parsrs/[a-z0-9]* ../bin || break
fSuccess=1
break; done
case $fSuccess in
0) echo "${0##*/}: Failed to install \"Parsrs\"" 1>&2
ng=$((ng+1));;
*) ok=$((ok+1));;
esac
rm -rf "${Dir_prefix%/}/tmp/"*
# A-99) finish with reporting
cd ../bin
rm -rf "${Dir_prefix%/}/tmp"
case $ng in
0) s='All command sets are installed successfully'
ret=0
;;
*) s="$ng command set(s) is/are failed to install"
ret=1
;;
esac
echo "*** $s" 1>&2
date "+%Y/%m/%d-%H:%M:%S $s" >> "$File_instlog"
case $ret in 0)
echo "Finally, Add the directory \"$(pwd)\" to \$PATH" 1>&2;;
esac
exit $ret
fi
#
# --- B) if unzip and (curl || wget) commands are ready, install with them
while type unzip >/dev/null 2>&1; do
# B-01) prepare
ok=0
ng=0
type curl >/dev/null 2>&1 || type wget >/dev/null 2>&1 || break
# B-11) install "Open usp Tukubai clone"
fSuccess=0
while :; do
s='https://github.com/ShellShoccar-jpn/Open-usp-Tukubai/archive/master.zip'
if type curl >/dev/null 2>&1; then
curl -f -L "$s" > dlfile.zip
else
wget -O - "$s" > dlfile.zip
fi
case $? in [!0]*) break;; esac
unzip dlfile.zip || break
rm -rf Open-usp-Tukubai-master/COMMANDS.SH/previous.ver
chmod +x Open-usp-Tukubai-master/COMMANDS.SH/*
mv -f Open-usp-Tukubai-master/COMMANDS.SH/* ../bin || break
fSuccess=1
break; done
case $fSuccess in
0) echo "${0##*/}: Failed to install \"Open usp Tukubai clone\"" 1>&2
ng=$((ng+1));;
*) ok=$((ok+1));;
esac
rm -rf "${Dir_prefix%/}/tmp/"*
# B-12) install "misc-tools"
fSuccess=0
while :; do
s='https://github.com/ShellShoccar-jpn/misc-tools/archive/master.zip'
if type curl >/dev/null 2>&1; then
curl -f -L "$s" > dlfile.zip
else
wget -O - "$s" > dlfile.zip
fi
case $? in [!0]*) break;; esac
unzip dlfile.zip || break
chmod +x misc-tools-master/[a-z0-9]* misc-tools-master/C_SRC/MAKE.sh
misc-tools-master/C_SRC/MAKE.sh -u || {
echo "${0##*/}: Some C-prog couldn't be compiled" 1>&2
}
mv -f misc-tools-master/[a-z0-9]* ../bin || break
fSuccess=1
break; done
case $fSuccess in
0) echo "${0##*/}: Failed to install \"misc-tools\"" 1>&2
ng=$((ng+1));;
*) ok=$((ok+1));;
esac
rm -rf "${Dir_prefix%/}/tmp/"*
# B-13) install "Parsrs"
fSuccess=0
while :; do
s='https://github.com/ShellShoccar-jpn/Parsrs/archive/master.zip'
if type curl >/dev/null 2>&1; then
curl -f -L "$s" > dlfile.zip
else
wget -O - "$s" > dlfile.zip
fi
case $? in [!0]*) break;; esac
unzip dlfile.zip || break
chmod +x Parsrs-master/[a-z0-9]*
mv -f Parsrs-master/[a-z0-9]* ../bin || break
fSuccess=1
break; done
case $fSuccess in
0) echo "${0##*/}: Failed to install \"Parsrs\"" 1>&2
ng=$((ng+1));;
*) ok=$((ok+1));;
esac
rm -rf "${Dir_prefix%/}/tmp/"*
# A-99) finish with reporting
cd ../bin
rm -rf "${Dir_prefix%/}/tmp"
case $ng in
0) s='All command sets are installed successfully'
ret=0
;;
*) s="$ng command set(s) is/are failed to install"
ret=1
;;
esac
echo "*** $s" 1>&2
date "+%Y/%m/%d-%H:%M:%S $s" >> "$File_instlog"
case $ret in 0)
echo "Finally, Add the directory \"$(pwd)\" to \$PATH" 1>&2;;
esac
exit $ret
break; done
#
# --- C) Show error message when could not install -------------------
cat <<-ERRORMESSAGE 1>&2
*** To install this, it is required the following commands
(A) "git" command, otherwise
(B) "unzip" command and either "curl" or "wget" command
ERRORMESSAGE
exit 1
#
# --- end of the block -----------------------------------------------
;; esac
######################################################################
# Finish
######################################################################
exit 0