forked from Cross-PLN-Technical-Working-Group/adpn-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadpn-do-setup
executable file
·436 lines (358 loc) · 16.7 KB
/
adpn-do-setup
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
#!/bin/bash
#
# adpn-do-setup: script to handle adpn setup commands, which cover different
# aspects of initial setup for the adpn-cli tools
#
# @version 2021.0807
SCRIPTPATH="$(which "$0")"
SCRIPTPATH="$( readlink --canonicalize "${SCRIPTPATH}" )"
SCRIPTDIR="$(dirname "${SCRIPTPATH}")"
SCRIPT="$(basename "${SCRIPTPATH}")"
ME="${SCRIPTPATH}"
source "${SCRIPTDIR}/adpn-define-aliases"
__USAGE__="Usage: ${SCRIPT} [--version] [--help] <CMD> [<ARGS>]"
__HELP__="[${SCRIPT}] Try '${SCRIPT} help' for more information."
__DOC__="""${__USAGE__}
--version Display the version of the script
--help Display these usage notes
The most commonly used ${SCRIPT} commands are:
dependencies a
path Set up the script location and system PATH
settings Set up the configuration file with appropriate settings
backups Set up the directory paths for backups stored by script
Exit codes:
0 = success (successful operation and expected result)
1-254 = error in executing command
255 = command not supported
"""
##########################################################################################
### COMMAND LINE: loop through switches ##################################################
##########################################################################################
declare -a _ARGV ; _ARGV=("$0")
declare -a _CMDLINE ; _CMDLINE=("$0")
declare -A _PARAM=()
shopt -s lastpipe
declare -a SWITCHFILES ; SWITCHFILES=()
if [[ -r "${CONFFILE}" ]] ; then
SWITCHFILES+=(${CONFFILE})
fi
CMDLINETXT=$(mktemp)
until [[ "$#" -lt 1 ]] ; do
_CMDLINE+=("$1")
printf "%s\n" "$1" >> "${CMDLINETXT}"
shift
done
SWITCHFILES+=(${CMDLINETXT})
adpn_command_line "${SWITCHFILES[@]}"
rm "${CMDLINETXT}"
##########################################################################################
### SCRIPT: DETERMINE COMMAND, THEN EXECUTE PIPELINE ####################################
##########################################################################################
EXITCODE=0
CMD="${_ARGV[1]}"
ADPNPATH="$( adpn_parameter_from "--script" "\\${SCRIPTPATH}" )"
ADPN="$( basename "${ADPNPATH}" )"
adpn_set_display_parameters
if [[ ! -z "${_PARAM[version]}" ]] ; then
VERSION=$(grep "^# @version" $0 | head --lines=1 | cut --only-delimited --fields=3- --delimiter=" ")
echo "${SCRIPT_CMD_NAME} version ${VERSION}"
CMD="version"
fi
adpn_debug 10 "${LINENO}" "entered, cmd=%s, cmdline='%s'" "${CMD}" "$( join_by "', '" "${_CMDLINE[@]:2}" )" 1>&2
if [[ ! -z "${_PARAM[help]}" ]] ; then
echo "${__DOC__}"
CMD="help"
fi
case "${CMD}" in
""|"all")
# @method adpn setup
# Proceed through all the appropriate setup steps.
#
# Usage: adpn setup [all] [--for=<PURPOSE>]
#
# --for=<PURPOSE> the command setup is setting up for
# options: preserve|verify|accept|promote
#
# @version 2021.0714
declare -a ADS_SW=()
[[ "${_SWITCHES[for]}" ]] && ADS_SW+=( "${_SWITCHES[for]}" )
[[ "${_SWITCHES[context]}" ]] && ADS_SW+=( "${_SWITCHES[context]}" )
[[ "${_SWITCHES[verbose]}" ]] && ADS_SW+=( "${_SWITCHES[verbose]}" )
[[ "${_SWITCHES[quiet]}" ]] && ADS_SW+=( "${_SWITCHES[quiet]}" )
[[ "${_SWITCHES[script]}" ]] && ADS_SW+=( "${_SWITCHES[script]}" )
[[ "${DDBG}" ]] && ADS_SW+=( "${DDBG}" )
"${ME}" dependencies "${ADS_SW[@]}" &&
"${ME}" path "${ADS_SW[@]}" &&
"${ME}" settings "${ADS_SW[@]}" &&
"${ME}" backups "${ADS_SW[@]}"
EXITCODE="$?"
;;
"context")
PUBLISHER_CONTEXTS=""
NODE_MANAGER_CONTEXTS="verify"
PROPS_MANAGER_CONTEXTS="accept|post|ingest|promote|publish"
TECH_CONTEXTS="${NODE_MANAGER_CONTEXTS}|${PROPS_MANAGER_CONTEXTS}"
ALL_CONTEXTS="${PUBLISHER_CONTEXTS}|${NODE_MANAGER_CONTEXTS}|${PROPS_MANAGER_CONTEXTS}"
declare -a CONTEXTS=()
declare -a PUBLISHER_CONTEXTS=( package stage preserve )
declare -a NODE_MANAGER_CONTEXTS=( verify )
declare -a CONFIG_MANAGER_CONTEXTS=( accept post ingest promote publish )
declare -a NOT_NODE_CONTEXTS=( "${PUBLISHER_CONTEXTS[@]}" "${CONFIG_MANAGER_CONTEXTS[@]}" )
declare -a NOT_CONFIG_CONTEXTS=( "${PUBLISHER_CONTEXTS[@]}" "${NODE_MANAGER_CONTEXTS[@]}" )
declare -a TECH_CONTEXTS=( "${NODE_MANAGER_CONTEXTS[@]}" "${CONFIG_MANAGER_CONTEXTS[@]}" )
declare -a ALL_CONTEXTS=( "${PUBLISHER_CONTEXTS[@]}" "${NODE_MANAGER_CONTEXTS[@]}" "${CONFIG_MANAGER_CONTEXTS[@]}" )
if [[ -n "${_PARAM[publisher]}" ]] ; then
CONTEXTS+=( "${PUBLISHER_CONTEXTS[@]}" )
fi
if [[ -n "${_PARAM[node-manager]}" ]] ; then
CONTEXTS+=( "${NODE_MANAGER_CONTEXTS[@]}" )
fi
if [[ -n "${_PARAM[config-manager]}" ]] ; then
CONTEXTS+=( "${CONFIG_MANAGER_CONTEXTS[@]}" )
fi
if [[ -n "${_PARAM[all]}" ]] ; then
CONTEXTS+=( "${ALL_CONTEXTS[@]}" )
fi
REGEX="^($( join_by "|" "${CONTEXTS[@]}" ))$"
if [[ -n "${_PARAM[covers]}" ]] ; then
[[ "${_PARAM[covers]}" =~ $REGEX ]] && EXITCODE=0 || EXITCODE=1
else
printf "%s" "${REGEX}"
fi
;;
"dependencies")
# @method adpn setup dependencies
# Check external dependencies and offer to install if necessary and possible.
#
# Usage: adpn setup dependencies --for=<PURPOSE>
#
# @version 2021.0730
DEPENDENCIES="""
curl %s command-line tool apt install curl yum install curl
unzip %s command-line tool apt install unzip yum install unzip
python3 %s scripting environment apt install python3 yum install python3
apt:python3-dev %s system module apt install python3-dev
yum:python3-devel %s system module yum install python3-devel
python3 %s scripting environment apt install python3 yum install python3
python:pip %s package management tool apt install python3-pip
python:bs4 %s Python module apt install python3-bs4 python3 -m pip install bs4
python:socks %s Python module apt install python3-socks python3 -m pip install pysocks #preserve
mysql_config %s development tool apt install libmysqlclient-dev yum install mysql-devel #accept
python:MySQLdb %s Python module python3 -m pip install mysqlclient #accept
python:cryptography %s Python module python3 -m pip install cryptography #preserve
python:pysftp %s Python module python3 -m pip install pysftp #preserve
python:paramiko %s Python module python3 -m pip install paramiko #preserve
python:pykeepass %s Python module python3 -m pip install pykeepass
python:Cryptodome %s Python module python3 -m pip install pycryptodomex
"""
printf "* DEPENDENCIES: checking for dependencies.\n"
declare -a ACD_SW=( "-" )
[[ -z "${_SWITCHES[batch]}" ]] && ACD_SW+=( "--interactive" )
[[ -n "${_SWITCHES[for]}" ]] && ACD_SW+=( "${_SWITCHES[for]}" )
printf "%s\n" "${DEPENDENCIES}" | adpn_check_dependencies "${ACD_SW[@]}"
EXITCODE="$?"
;;
"path")
# @method adpn setup path
# Set up a symbolic link to place adpn in the user's private bin dir
#
# @version 2021.0714
MY_BINDIR="${HOME}/bin"
printf "* PATH: Ensure that ${ADPN} is accessible through ${MY_BINDIR}\n" 1>&2
if [[ ! -d "${MY_BINDIR}" ]] ; then
printf "\n"
mkdir -v "${MY_BINDIR}"
EXITCODE="$?"
printf "\n"
fi
if [[ "${SCRIPTDIR}" != "${MY_BINDIR}" ]] ; then
ADPNALIAS="${MY_BINDIR}/${ADPN}"
if [[ ! -x "${MY_BINDIR}/${ADPN}" ]] ; then
printf "\n"
ln --verbose --symbolic --logical --backup "${ADPNPATH}" "${ADPNALIAS}"
EXITCODE="$?"
printf "\n"
fi
fi
;;
"settings")
# @method adpn setup settings
# Generate an adpnet.json file in the user's home dir, then place a symlink in the bindir
#
# @version 2021.0714
MY_CONFDIR="${HOME}/.adpn"
JSONFILENAME="$( basename "${JSONCONFFILE}" )"
printf "* SETTINGS: Ensure that ${JSONFILENAME} is accessible through ${MY_CONFDIR}\n" 1>&2
if [[ ! -d "${MY_CONFDIR}" ]] ; then
printf "\n"
mkdir -v "${MY_CONFDIR}"
printf "\n"
fi
if [[ ! -r "${JSONCONFFILE}" ]] ; then
MY_CONFFILE="${MY_CONFDIR}/${JSONFILENAME}"
if [[ ! -r "${MY_CONFFILE}" ]] ; then
printf "%s\n" "{}" > "${MY_CONFFILE}"
ln --verbose --symbolic --logical --backup "${MY_CONFFILE}" "${JSONCONFFILE}"
EXITCODE="$?"
declare -A AS_PROPS=()
declare -A AS_KDBX_KEYS=()
printf "* SETTINGS: Let's set up some properties for ${MY_CONFFILE}.\n" 1>&2
printf " N.B.: Not all of these settings need to be filled in on all systems.\n" 1>&2
printf "\n" 1>&2
AS_CONTEXT="$( [[ -z "${_PARAM[for]}" ]] && echo "preserve" || echo "${_PARAM[for]}" )"
AS_CONTEXT="$( printf "%s" "${AS_CONTEXT}" | tr "[:upper:]" "[:lower:]" )"
PUBLISHER_CONTEXTS="package|stage|preserve"
NODE_MANAGER_CONTEXTS="verify"
PROPS_MANAGER_CONTEXTS="accept|post|ingest|promote|publish"
TECH_CONTEXTS="${NODE_MANAGER_CONTEXTS}|${PROPS_MANAGER_CONTEXTS}"
ALL_CONTEXTS="${PUBLISHER_CONTEXTS}|${NODE_MANAGER_CONTEXTS}|${PROPS_MANAGER_CONTEXTS}"
IFS=""
MAKEMANIFEST_API="https://archives.alabama.gov/Services/ADPNet/MakeManifest/"
PLUGINS_SOURCE_API="${MAKEMANIFEST_API}?%(encoded)s"
if ( "${ME}" context --publisher --covers="${AS_CONTEXT}" ) ; then
read -ep "Institution: " AS_PROPS[institution]
read -ep "Publisher Code (ADAH, AUB, ...): " AS_PROPS[publisher]
KEY="api/makemanifest" DEFAULT="${MAKEMANIFEST_API}"
read -ep "MakeManifest API Endpoint [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="plugins/source" DEFAULT="${PLUGINS_SOURCE_API}"
read -ep "Plugins Source API Endpoint [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
if ( "${ME}" context --all --covers="${AS_CONTEXT}" ) ; then
USER_FULLNAME="$( getent passwd "${USER}" | cut -d ":" -f 5 -s | cut -d "," -f 1 -s )"
[[ -n "${USER_FULLNAME}" ]] || USER_FULLNAME="${USER}"
KEY="user/realname" DEFAULT="${USER_FULLNAME}"
read -ep "User Full Name [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
USER_EMAIL="${USER}@$( hostname )"
KEY="user/email" DEFAULT="${USER_EMAIL}"
read -ep "User E-mail [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
if ( "${ME}" context --node-manager --config-manager --covers="${AS_CONTEXT}" ) ; then
read -ep "LOCKSS Daemon URL: " AS_PROPS[daemon]
if [[ -n "${AS_PROPS[daemon]}" ]] ; then
read -ep "LOCKSS Daemon User: " AS_PROPS[daemon/user]
if [[ -n "${AS_PROPS[daemon/user]}" ]] ; then
read -sep "LOCKSS Daemon Password: " DAEMON_PASS
printf "\n"
[[ -n "${DAEMON_PASS}" ]] && AS_KDBX_KEYS["ADPNet-LOCKSS-Daemon:daemon/pass"]="${DAEMON_PASS}"
fi
fi
fi
if ( "${ME}" context --all --covers="${AS_CONTEXT}" ) ; then
KEY="stage/jar" DEFAULT="http://configuration.adpn.org/overhead/takeover/plugins/AuburnDirectoryPlugin.jar"
read -ep "Default Plugin JAR [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
DROP_SERVER="drop.adpn.org" ; DROP_HERE="drop_au_content_in_here"
if ( "${ME}" context --publisher --covers="${AS_CONTEXT}" ) ; then
DROP_SERVER_USER="$( printf "%s" "${AS_PROPS[publisher]}" | tr '[:upper:]' '[:lower:]' )"
KEY="stage/host" DEFAULT="${DROP_SERVER}"
read -ep "Drop Server [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="stage/user" DEFAULT="${DROP_SERVER_USER}"
read -ep "Drop Server Account [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="stage/base" DEFAULT="sftp://${DROP_SERVER_USER}@${DROP_SERVER}/${DROP_HERE}/"
read -ep "Staging Area Base [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="stage/base_url" DEFAULT="http://${DROP_SERVER}/drop-server/${DROP_SERVER_USER}/${DROP_HERE}/"
read -ep "Staging Area Base URL [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
if ( "${ME}" context --all --covers="${AS_CONTEXT}" ) ; then
KEY="preserve/admin-email" DEFAULT="ADPNet TPC <[email protected]>"
read -ep "Staging Admin E-mail [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
if ( "${ME}" context --node-manager --covers="${AS_CONTEXT}" ) ; then
read -ep "Peer Node (ADAH, AUB1, AUB2, ...): " AS_PROPS[peer]
fi
if ( "${ME}" context --publisher --config-manager --covers="${AS_CONTEXT}" ) ; then
KEY="node-server/ssh" DEFAULT="" PROMPT_DEFAULT="(e.g.: user@host)"
if [[ -n "${AS_PROPS[daemon]}" ]] ; then
NODE_SERVER="$( printf "%s" "${AS_PROPS[daemon]}" | cut --delimiter=":" --field=1 )"
DEFAULT="${USER}@${NODE_SERVER}"
PROMPT_DEFAULT="[${DEFAULT}]"
fi
read -ep "Node Server SSH Identity ${PROMPT_DEFAULT}: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
PROPS_SERVER="configuration.adpn.org"
if ( "${ME}" context --config-manager --covers="${AS_CONTEXT}" ) ; then
KEY="props-server" DEFAULT="http://${PROPS_SERVER}/"
read -ep "Props Server URL [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="mysql/host" DEFAULT="localhost"
read -ep "[titlesdb] MySQL Server [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
if [[ -n "${AS_PROPS[mysql/host]}" ]] ; then
KEY="mysql/db" DEFAULT="adpn"
read -ep "[titlesdb] MySQL Database [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
if [[ -n "${AS_PROPS[mysql/db]}" ]] ; then
KEY="mysql/user" DEFAULT="${USER}"
read -ep "[titlesdb] MySQL User [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
if [[ -n "${AS_PROPS[mysql/user]}" ]] ; then
read -sep "[titlesdb] MySQL Password: " AS_PROPS[mysql/password]
printf "\n"
fi
fi
fi
KEY="props/titlesdb.xml" DEFAULT="/var/www/html/overhead/takeover/lockss/titlesdb.xml"
read -ep "[titlesdb] TitlesDB XML Location [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="xmldir" DEFAULT="${HOME}/titlesdb-xml"
read -ep "[titlesdb] XML Working Directory [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
if ( "${ME}" context --publisher --node-manager --covers="${AS_CONTEXT}" ) ; then
KEY="props-server/ssh" DEFAULT="${USER}@${PROPS_SERVER}"
read -ep "Props Server SSH Identity [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
fi
if ( "${ME}" context --all --covers="${AS_CONTEXT}" ) ; then
KEY="gitlab/base" DEFAULT="https://gitlab.com/api/v4/%s"
read -ep "Gitlab API URL [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="gitlab/repository" DEFAULT="adpnet/adpn---general"
read -ep "Gitlab Repository [${DEFAULT}]: " AS_PROPS[$KEY] ; AS_PROPS[$KEY]="${AS_PROPS[$KEY]:-$DEFAULT}"
KEY="gitlab/token" DEFAULT=""
read -ep "Gitlab Personal Access Token (see <https://gitlab.com/-/profile/personal_access_tokens>): " GITLAB_TOKEN
[[ -n "${GITLAB_TOKEN}" ]] && AS_KDBX_KEYS["ADPNet-Gitlab-Token:gitlab/token"]="${GITLAB_TOKEN}"
fi
declare -a AS_KEYS=()
IFS="" printf "%s\n" "${!AS_PROPS[@]}" | sort | while read -r KEY ; do
if [[ -n "${AS_PROPS[$KEY]}" ]] ; then
printf "%s property set %s '%s'\n" "\$ adpn" "${KEY}" "${AS_PROPS[$KEY]}" 1>&2
adpn property set "${KEY}" "${AS_PROPS[$KEY]}" --quiet
EXITCODE="$?"
fi
done
KDBX="${MY_CONFDIR}/adpnet.kdbx"
IFS="" printf "%s\n" "${!AS_KDBX_KEYS[@]}" | sort | while read -r KEY ; do
if [[ -n "${KEY}" ]] ; then
KEYNAME="$( printf "%s" "${KEY}" | cut --delimiter=":" --field=1 )"
PROPERTY="$( printf "%s" "${KEY}" | cut --delimiter=":" --field=2 )"
ENCODED_KEYNAME="$( rawurlencode "${KEYNAME}" )"
adpn property set "${PROPERTY}" "keepass://${KDBX}?title=${ENCODED_KEYNAME}"
printf "%s" "${AS_KDBX_KEYS[${KEY}]}" | adpn-get-keepass.py --database="${KDBX}" --set --create --title="${KEYNAME}"
fi
done
fi
printf "\n"
fi
;;
"backups")
# @method adpn setup backups
# If we are setting up a props node, and we set a work directory for XML diffs, go ahead and create it.
#
# @version 2021.0714
xmldir="$(adpnprop xmldir)"
if [[ -n "${xmldir}" ]] ; then
printf "* XML PATH: Ensure that working directory is available at ${xmldir}\n" 1>&2
if [[ ! -d "${xmldir}" ]] ; then
printf "\n"
mkdir --verbose --parents "${xmldir}"
EXITCODE="$?"
printf "\n"
fi
fi
;;
"version"|"help")
EXITCODE=0
;;
*)
echo "[${SCRIPT_CMD_NAME}] '${CMD}' command not understood." 1>&2
echo "${__HELP__}" 1>&2
EXITCODE=255
;;
esac
##########################################################################################
### CLEANUP: remove temporary output file. ###############################################
##########################################################################################
exit ${EXITCODE}