-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild
More file actions
executable file
·93 lines (80 loc) · 2.38 KB
/
build
File metadata and controls
executable file
·93 lines (80 loc) · 2.38 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
#!/usr/bin/env bash
LOG_LEVEL_ERROR="0"
LOG_LEVEL_INFO="1"
VERBOSE="${VERBOSE:-${LOG_LEVEL_ERROR}}"
function printError {
if (( "${VERBOSE}" >= "${LOG_LEVEL_ERROR}" )); then
>&2 echo "error: ${@}"
fi
}
function printInfo {
if (( "${VERBOSE}" >= "${LOG_LEVEL_INFO}" )); then
>&2 echo "info: ${@}"
fi
}
function printDisclaimer {
cat << EOF
# This file is managed within ${CI_PROJECT_URL:-a git} repository.
# Do not edit.
#
# See https://github.com/vbouchaud/configuration-builder
# for details about the supported operations.
EOF
}
declare -A registry=()
function registerFile {
local filename="$(realpath "${1}")"
if [[ -d "${filename}" ]]; then
for subfile in ${filename}/*.cfg; do
if [[ -f "${subfile}" ]]; then
registerFile "${subfile}"
fi
done
elif [[ -f "${filename}" ]]; then
if [[ -z "${registry[${filename}]}" ]]; then
registry["${filename}"]="$(cat "${filename}")"
for file in $(grep -Po 'include\("\K.*?(?=")' "${filename}"); do
registerFile "$(dirname "${filename}")/${file}"
done
else
printInfo "file '${filename}' already registered"
fi
else
printError "file '${filename}' not found"
fi
}
function printFile {
local file="$(realpath "${1}")"
local spacer="${2}"
if [[ -d "${file}" ]]; then
for subfile in ${file}/*.cfg; do
if [[ -f "${subfile}" ]]; then
printFile "${subfile}" "${spacer}"
fi
done
else
echo "${spacer}## Source: $(realpath --relative-to="${PWD}" "${file}")"
while IFS= read -r line; do
local include="$(grep -Po 'include\("\K.*?(?=")' <<< "${line}")"
if [[ ! -z "${include}" ]]; then
local nsp="${spacer}$(echo "${line}" | cut -d'i' -f1)"
local fullpathname="$(realpath "$(dirname "${file}")/${include}")"
printFile "${fullpathname}" "${nsp}"
else
echo "${spacer}${line}"
fi
done <<< "${registry[$file]}"
fi
}
function main {
if [[ -z "${1}" ]] || [[ ! -f "${1}" ]]; then
printError "no file '${filename}'"
exit 1
fi
registerFile "${1}"
if [[ ! -z "${PRINT_DISCLAIMER}" ]]; then
printDisclaimer
fi
printFile "${1}" ""
}
main $*