forked from Cross-PLN-Technical-Working-Group/adpn-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadpn-workflow-do
executable file
·119 lines (89 loc) · 3.49 KB
/
adpn-workflow-do
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
#!/bin/bash
#
# adpn-workflow-do: script to handle adpn workflow commands
#
# @version 2021.0918
SCRIPTPATH="$(which "$0")"
SCRIPTPATH="$( readlink --canonicalize "${SCRIPTPATH}" )"
SCRIPTDIR="$(dirname "${SCRIPTPATH}")"
SCRIPT="$(basename "${SCRIPTPATH}")"
source "${SCRIPTDIR}/adpn-define-aliases"
source "${SCRIPTDIR}/adpn-workflow-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:
verify Verify that an AU's parameters are complete and correct
and its start URL is accessible to the LOCKSS workflow.
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 _CMDLINE ; _CMDLINE=("$0")
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]}"
adpn_set_display_settings # V, VV, Q, QQ, DBG, DBGLEVEL, DDBG, SCRIPT_CMD_NAME / @see adpn-define-aliases
adpn_script_handle_version_or_help
if [[ ! -z "${_PARAM[remote]}" ]] ; then
adpn_script_handle_remote_execution -t "workflow" "${_CMDLINE[@]:1}"
EXITCODE="$?"
else
case "${CMD}" in
"step")
[[ -n "${_PARAM[next]}" ]] && STEP_VERB="$( ${ADPN} workflow next -- "${_ARGV[@]:2}" )" || STEP_VERB="${_ARGV[2]}"
[[ -n "${_PARAM[next]}" ]] && declare -a STEP_OBJECTS=( "${_ARGV[@]:2}" ) || declare -a STEP_OBJECTS=( "${_ARGV[@]:3}" )
declare -a STEP_SW=()
for _SW in "${_SWITCHES[@]}" ; do
[[ "${_SW}" =~ ^--next$ ]] || STEP_SW+=( "${_SW}" )
done
STEP="$( adpn_workflow_get_step "${STEP_VERB}" "${_STEP_SW[@]}" "--" "${STEP_OBJECTS[@]}" )"
adpn_notice "${LINENO}" '$ %s%s' "${STEP}" "$( [[ -n "${_PARAM[dry-run]}" ]] && printf " (dry-run)" )"
[[ -z "${_PARAM[dry-run]}" ]] && eval "${STEP}"
;;
"next")
_TEMP_FILE="$( mktemp )"
if [[ "${_ARGV[2]}" =~ ^gitlab:(.*)$ ]] ; then
"${ADPN}" gitlab get labels "${BASH_REMATCH[1]}" | grep -E "^(TODO|WAITING)[:]" > "${_TEMP_FILE}"
fi
IFS=$'\r\n' cat "${_TEMP_FILE}" | while read -r LINE ; do
printf -- "-%s\n" "${LINE}"
done
rm "${_TEMP_FILE}"
;;
"version"|"help")
EXITCODE=0
;;
*)
echo "[${SCRIPT_CMD_NAME}] '${CMD}' command not understood." 1>&2
echo "${__HELP__}" 1>&2
EXITCODE=255
;;
esac
fi
##########################################################################################
### CLEANUP: exit with settled exit code. ################################################
##########################################################################################
exit ${EXITCODE}