-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig-manipulators.sh
executable file
·39 lines (33 loc) · 998 Bytes
/
config-manipulators.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
#!/usr/bin/env sh
#
# WARNING: this file is also embedded in the post-init patcher, so don't go to crazy with the syntax/tools as it must
# be able to execute in the initramfs/preboot environment (so no bashism etc)
# All comments will be stripped, functions here should NOT start with brp_ as they're not part of the builder
if [ -z "${SED_PATH+x}" ]; then
echo "Your SED_PATH variable is not set/is empty!"
exit 1
fi
##$1 from, $2 to, $3 file to path
_replace_in_file() {
if grep -q "${1}" "${3}"; then
"${SED_PATH}" -i "s#${1}#${2}#" "${3}" 2>/dev/null
fi
}
# Replace/remove/add values in .conf K=V file
#
# Args: $1 name, $2 new_val, $3 path
_set_conf_kv() {
# Delete
if [ -z "${2}" ]; then
"${SED_PATH}" -i "/^${1}=/d" "${3}" 2>/dev/null
return 0
fi
# Replace
if grep -q "^${1}=" "${3}"; then
"${SED_PATH}" -i "s#^${1}=.*#${1}=\"${2}\"#" "${3}" 2>/dev/null
return 0
fi
# Add if doesn't exist
echo "${1}=\"${2}\"" >>"${3}"
return 0
}