-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sh
executable file
·36 lines (31 loc) · 1.32 KB
/
build.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
tmpl=${1:-src/ucsf-vpn.sh}
target=${2:-bin/ucsf-vpn}
echo "Building ${target} from ${tmpl} ..."
## Assert there are source statements
grep -q -F 'source "${incl}/' "${tmpl}"
{
while IFS= read -r line; do \
if [[ "${line}" == "source "* ]]; then \
file=$(sed -E 's/source "[$][{](incl)[}][/]([^.]+[.]sh)"/\1\/\2/' <<< "${line}")
cat "src/${file}"
echo
elif [[ "${line}" == *'cat "${vpnc}/ucsf-vpn-flavors.sh"'* ]]; then
echo 'cat << HOOK_SCRIPT_EOF'
sed -E 's/[$]/\\$/g' src/vpnc/ucsf-vpn-flavors.sh
echo 'HOOK_SCRIPT_EOF'
elif ! grep -q -E "^(# shellcheck source=|this=|vpnc=|incl=)" <<< "${line}"; then
echo "${line}"
if [[ "${line}" == "#! /usr/bin/env bash" ]]; then
echo "###################################################################"
echo "# DON'T EDIT: This file is automatically generated from src/ files"
echo "###################################################################"
fi
fi
done < "${tmpl}"
} > "${target}.tmp"
chmod ugo-w "${target}.tmp"
chmod ugo+x "${target}.tmp"
mv -f "${target}.tmp" "${target}"
ls -l "${target}"
echo "Version built: $(bash "${target}" --version)"
echo "Building ${target} from ${tmpl} ... done"