-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmobala.sh
More file actions
executable file
·130 lines (107 loc) · 3.79 KB
/
mobala.sh
File metadata and controls
executable file
·130 lines (107 loc) · 3.79 KB
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
#!/usr/bin/env bash
# shellcheck disable=SC1090
set -euo pipefail
script_path="$(realpath "$0")"
script_dirname="$(dirname "$script_path")"
# mobala_dirname="$(dirname "$BASH_SOURCE")"
echo "[info] Library in '${script_dirname}/mobala-lib.sh'"
echo "[info] Script in '${script_path}'"
export MOBALA_PATH=${MOBALA_PATH:-"${script_dirname}"}
export MOBALA_SUBDIR_NAME=${MOBALA_SUBDIR_NAME:-".mobala"}
export MOBALA_SUBDIR=${MOBALA_SUBDIR:-"${MOBALA_PATH}/${MOBALA_SUBDIR_NAME}"}
export MOBALA_KEEP=${MOBALA_KEEP:-"${MOBALA_SUBDIR}/keep.env"}
export MOBALA_ENV=${MOBALA_ENV:-"${MOBALA_SUBDIR}/env.sh"}
export MOBALA_MODS=${MOBALA_MODS:-"${MOBALA_SUBDIR}/mods"}
export MOBALA_STEPS=${MOBALA_STEPS:-"${MOBALA_SUBDIR}/steps"}
export MOBALA_FLOWS=${MOBALA_FLOWS:-"${MOBALA_SUBDIR}/flows"}
export MOBALA_PARAMS=${MOBALA_PARAMS:-"${MOBALA_SUBDIR}/params"}
export LANG="C.UTF-8"
export VERBOSE_LEVEL=${VERBOSE_LEVEL:-0}
source "${script_dirname}/mobala-lib.sh"
echo "[info] Working in '${MOBALA_PATH}'."
cd "$MOBALA_PATH"
# parse command line and execute modes
idx=0
arguments=("$@")
arguments_length="${#arguments[@]}"
while [[ $idx -lt $arguments_length ]] ; do
arg="${arguments[idx]}"
case "$arg" in
--nix)
idx=$((idx+1))
shift && nixify "default" "$@"
;;
--nix=*)
dev_shell="${arg#--nix=}"
shift && nixify "$dev_shell" "$@"
;;
--help)
idx=$((idx+1))
print-help
exit 0
;;
-v|--verbose)
idx=$((idx+1))
set -x
export DO_VERBOSE=1
export VERBOSE_LEVEL=1
;;
-vv|--very-verbose)
idx=$((idx+1))
set -x
export DO_VERBOSE=1
export VERBOSE_LEVEL=2
;;
-e|--env)
arg="${arguments[$((idx+1))]}"
idx=$((idx+2))
export "$(echo "${arg}" | xargs)"
;;
--*=*)
idx=$((idx+1))
# set build parameter
build_param=$(echo "${arg:2}" | cut -d "=" -f 1)
build_arg=$(echo "${arg:2}" | cut -d "=" -f 2)
if [[ -f "${MOBALA_PARAMS}/$build_param.sh" ]]; then
echo "[info] Setting build parameter: $build_param=$build_arg"
function run-param() { source "${MOBALA_PARAMS}/$build_param.sh" $build_arg ; } ; run-param
fi
;;
--*)
idx=$((idx+1))
# apply build parameter
build_param="${arg:2}"
if [[ -f "${MOBALA_PARAMS}/$build_param.sh" ]]; then
echo "[info] Applying build parameter: $build_param"
function run-param() { source "${MOBALA_PARAMS}/$build_param.sh" ; } ; run-param
fi
;;
:*)
idx=$((idx+1))
# parse build mode arguments
build_mode="${arg:1}"
build_mode_args=()
while [[ $idx -lt $arguments_length ]] && ! [[ "${arguments[idx]}" =~ ^:.* ]] ; do
build_mode_args+=("${arguments[idx]}")
idx=$((idx+1))
done
# run build mode
if [[ -f "${MOBALA_MODS}/$build_mode.sh" ]]; then
echo "[info] Applying mode $build_mode: '${MOBALA_MODS}/$build_mode.sh ${build_mode_args[*]}'"
function run-mode() { source "${MOBALA_MODS}/$build_mode.sh" "${build_mode_args[@]}" ; } ; run-mode
else
echo "[info] There is no launcher file for $build_mode, activating step run-${build_mode}"
step_enable "run-${build_mode}"
fi
;;
*)
idx=$((idx+1))
;;
esac
done
{ echo "Done processing arguments" ; } 2>/dev/null
source "${MOBALA_ENV}" "$@"
invoke_quiet steps_register
invoke_quiet flows_register
invoke_quiet steps_report
invoke_quiet flows_run