-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathstep.sh
61 lines (48 loc) · 1.36 KB
/
step.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
#!/bin/bash
THIS_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CONFIG_tmp_script_file_path="${THIS_SCRIPT_DIR}/._script_cont"
if [ -z "${content}" ] ; then
echo " [!] => Failed: No script (content) defined for execution!"
exit 1
fi
if [ -z "${runner_bin}" ] ; then
echo " [!] => Failed: No script executor defined!"
exit 1
fi
function debug_echo {
local msg="$1"
if [[ "${is_debug}" == "yes" ]] ; then
echo "${msg}"
fi
}
debug_echo
debug_echo "==> Start"
if [ ! -z "${working_dir}" ] ; then
debug_echo "==> Switching to working directory: ${working_dir}"
cd "${working_dir}"
if [ $? -ne 0 ] ; then
echo " [!] Failed to switch to working directory: ${working_dir}"
exit 1
fi
fi
if [ ! -z "${script_file_path}" ] ; then
debug_echo "==> Script (tmp) save path specified: ${script_file_path}"
CONFIG_tmp_script_file_path="${script_file_path}"
fi
echo -n "${content}" > "${CONFIG_tmp_script_file_path}"
debug_echo
if [[ "$(basename "${runner_bin}")" == "bash" ]] ; then
# bash syntax check
${runner_bin} -n "${CONFIG_tmp_script_file_path}"
if [ $? -ne 0 ] ; then
echo " [!] Bash: Syntax Error!"
rm "${CONFIG_tmp_script_file_path}"
exit 1
fi
fi
${runner_bin} "${CONFIG_tmp_script_file_path}"
script_result=$?
debug_echo
debug_echo "==> Script finished with exit code: ${script_result}"
rm "${CONFIG_tmp_script_file_path}"
exit ${script_result}