forked from Kurento/doc-kurento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·73 lines (55 loc) · 1.75 KB
/
configure.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
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
# File checked with ShellCheck (https://www.shellcheck.net/)
#/ Initialization script for Kurento documentation.
#/
#/ This shell script prepares the sources for building. The main work done here
#/ is replacing all placeholder variables with their actual values, as defined
#/ in 'VERSIONS.conf.sh'.
#/
#/ Arguments: None.
# ------------ Shell setup ------------
# Shell options for strict error checking
set -o errexit -o errtrace -o pipefail -o nounset
# Help message (extracted from script headers)
usage() {
grep '^#/' "$0" | cut --characters=4-
exit 0
}
REGEX='^(-h|--help)$'
if [[ "${1:-}" =~ $REGEX ]]; then
usage
fi
# Log function
BASENAME="$(basename "$0")" # Complete file name
log() { echo "[$BASENAME] $*"; }
# ------------ Script start ------------
# ---- Load VERSIONS file ----
BASEPATH="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" # Absolute canonical path
CONF_FILE="$BASEPATH/VERSIONS.conf.sh"
[[ -f "$CONF_FILE" ]] || {
log "ERROR: Shell config file not found: $CONF_FILE"
exit 1
}
# shellcheck source=VERSIONS.conf.sh
source "$CONF_FILE"
# ---- Put actual values in their placeholders ----
# This expects a Bash Associative Array;
# enumerates all entries to use their name and values
for NAME in "${!PROJECT_VERSIONS[@]}"; do
VALUE="${PROJECT_VERSIONS[$NAME]}"
# grep -lIrZ -- '<OldPattern>' | xargs -0 -L1 -r sed -i -e 's/<OldPattern>/<NewPattern>/g'
grep \
--files-with-matches \
--binary-files=without-match \
--recursive \
--null \
"|$NAME|" "$BASEPATH" \
| xargs \
--null \
--max-lines=1 \
--no-run-if-empty \
sed \
--in-place --expression="s/|$NAME|/$VALUE/g"
done
log "Done!"
exit 0