This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
configure.sh
executable file
·79 lines (56 loc) · 1.88 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
74
75
76
77
78
79
#!/usr/bin/env bash
#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.env`.
#/
#/ Arguments: None.
# Shell setup
# ===========
# Bash options for strict error checking.
set -o errexit -o errtrace -o pipefail -o nounset
shopt -s inherit_errexit 2>/dev/null || true
# Trace all commands (to stderr).
#set -o xtrace
# Help message.
# Extracts and prints text from special comments in the script header.
function usage { grep '^#/' "${BASH_SOURCE[-1]}" | cut -c 4-; exit 0; }
if [[ "${1:-}" =~ ^(-h|--help)$ ]]; then usage; fi
# Log function.
BASENAME="$(basename "$0")" # Complete file name
log() { echo "[$BASENAME] $*"; }
# Load VERSIONS file
# ==================
BASEPATH="$(cd -P -- "$(dirname -- "$0")" && pwd -P)" # Absolute canonical path
CONF_FILE="$BASEPATH/VERSIONS.env"
[[ -f "$CONF_FILE" ]] || {
log "ERROR: Shell config file not found: $CONF_FILE"
exit 1
}
# shellcheck source=VERSIONS.env
source "$CONF_FILE"
# Replace 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]}"
# Use long option names for readability. Equivalent to this:
# 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