-
Notifications
You must be signed in to change notification settings - Fork 3
/
dexec-script.sh
executable file
·51 lines (42 loc) · 1.19 KB
/
dexec-script.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
#!/bin/bash
set -e
dexec_script_name=$(basename ${0}); pushd $(dirname ${0}) >/dev/null
dexec_script_path=$(pwd -P); popd >/dev/null
source "${dexec_script_path}/dexec-common.sh"
dexec_interpreter="${1}"; shift
function dexec_validate() {
if [ ${#dexec_sources[@]} -gt 1 ]; then
>&2 echo "Error: only one source file supported"
exit 1
fi
}
function dexec_setup() {
pushd ${dexec_build_path} >/dev/null
tmp_dir=/tmp/$(dexec_uuid)
mkdir -p ${tmp_dir}
shopt -s dotglob
cp -r ${dexec_build_path}/* ${tmp_dir}
shopt -u dotglob
pushd ${tmp_dir} >/dev/null
for source in "${dexec_sources[@]}"; do
sed -Ee '/^#!.*dexec/d' "${source}" > "${source}_tmp" && mv "${source}_tmp" "${source}"
done
}
function dexec_run() {
${dexec_interpreter} ${dexec_sources[*]} "${dexec_args[@]}"
}
function dexec_cleanup() {
popd >/dev/null
if [ -w "${dexec_build_path}" ]; then
for source in "${dexec_sources[@]}"; do
cp "${source}" "${tmp_dir}"
done
diff -Naur "${dexec_build_path}" ${tmp_dir} | patch >/dev/null
fi
popd >/dev/null
}
dexec_parse_params "${@}"
dexec_validate
dexec_setup
dexec_run
dexec_cleanup