-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgms-build
More file actions
executable file
·132 lines (97 loc) · 3.11 KB
/
gms-build
File metadata and controls
executable file
·132 lines (97 loc) · 3.11 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
131
132
#!/bin/bash
# as an error when substituting.
set -o nounset
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
}
ex_err() {
err "$@"
exit 100
}
function _check_required_programs() {
# Required program(s)
req_progs=(envsubst)
for p in ${req_progs[@]}; do
hash "${p}" 2>&- || \
{ echo >&2 " Required program \"${p}\" not installed or in search PATH.";
exit 1;
}
done
}
function cleanup() {
rm -f ${TMP_FILE_PREFIX}.*
#echo "always implement this" && exit 100
}
# declare -r CONSTANT_VARIABLE='value'
declare -r TMP_FILE_PREFIX=${TMPDIR:-/tmp}/prog.$$
declare -r SCRIPT_PATH=$( cd $(dirname ${BASH_SOURCE[0]}) > /dev/null; pwd -P )
# expect APP_DIR from env, otherwise same as where script is
WORK_DIR=${APP_DIR:=$SCRIPT_PATH}
function usage() {
cat <<EOF
Usage: $0
-b build dir: Directory where files get created
-c PotsgreSQL conenction string using mapserver syntax
-d the internet domain url under which this instance will be accesible.
By default http://localhost
-h this help
EOF
}
# Single main function
function main() {
#Parse command line flags If an option should be followed by an
#argument, it should be followed by a ":". Notice there is no ":"
#after "h". The leading ":" suppresses error messages from
#getopts. This is required to get unrecognized option code to
#work.
local -r OPTS=':hb:c:d:'
declare -g BUILD_DIR=${WORK_DIR}/build
declare -g PG_CONNECTION=""
declare -gx DOMAIN_URL="http://localhost"
while builtin getopts ${OPTS} opt "${@}"; do
case $opt in
b) [[ -w "${OPTARG}" ]] || ex_err "Could not access directory ${OPTARG}";
declare -gr BUILD_DIR="${OPTARG}"
;;
c) #also exporting to env for envsubst
declare -grx PG_CONNECTION=${OPTARG}
[[ -n ${OPTARG} ]] \
|| ex_err "You have to define PostgreSQL database conenction using same syntax as mapserver requires"
;;
d) declare -grx DOMAIN_URL=${OPTARG}
[[ -n ${OPTARG} ]] \
|| ex_err "You have to define the domain url"
;;
h) usage ; exit 0
;;
\?)
echo ${opt} ${OPTIND} 'is an invalid option' >&2 ;
usage;
exit ${INVALID_OPTION}
;;
:)
echo 'required argument not found for option -'${OPTARG} >&2;
usage;
exit ${INVALID_OPTION}
;;
*) echo "Too many options. Can not happen actually :)"
;;
esac
done
[[ -n ${PG_CONNECTION} ]] || ex_err "You have to define PostgreSQL database conenction using same syntax as mapserver requires";
mkdir -p ${BUILD_DIR}
#rsync -zvr data "${BUILD_DIR}"/data
cp -R etc/ layer/ template/ doc-root/ "${BUILD_DIR}"
envsubst < postgis-connection.inc > "${BUILD_DIR}"/postgis-connection.inc
echo "url=${DOMAIN_URL}"
for file in *.map; do
envsubst < "${file}" > "${BUILD_DIR}"/"${file}"
done
cleanup
exit 0
}
# set a trap for (calling) cleanup all stuff before process
# termination by SIGHUBs
trap "cleanup; exit 1" 1 2 3 13 15
# this is the main executable function at end of script
main "$@"