Fixes support for editing configuration when NetData is installed to a symlinked /opt (#7933)
* Re-formated ./system/edit-config.in with shfmt -w -i 2 -ci -sr * Fixed and cleaned up ./system/edit-config to work correctly with symlinks
James Mills committed
Feb 5, 2020 at 08:10 UTC
742f4c9840eee5ede44f31dcff0b36c06241c19a
1 file changed
+12
-25
system/edit-config.in
+12
-25
@@ -32,34 +32,19 @@ USAGE:
32
EOF
33
34
cd "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
35
- ls >&2 -R *.conf */*.conf
35
+ ls >&2 -R ./*.conf ./*/*.conf
36
exit 1
37
38
fi
39
40
-file_is_in_path() {
41
- local file path real
42
- file="${1}"
43
- path="${2}"
44
-
45
- real="$(readlink -f "${file}")"
46
-
47
- # we don't have working readlink
48
- [ -z "${real}" ] && return 0
49
-
50
- if [ ! -z "${real}" ] && [ -z "$(echo "${real}" | grep -E "^${path}.*$")" ]; then
51
- echo >&2 "File '${file}' is physically at '${real}', which is not in '${path}'. Aborting."
52
- exit 1
53
- fi
54
-
55
- return 0
56
-}
57
-
40
edit() {
41
echo >&2 "Editing '${1}' ..."
42
43
# check we can edit
62
- file_is_in_path "${1}" "${NETDATA_USER_CONFIG_DIR}" || exit 1
44
+ if [ ! -w "${1}" ]; then
45
+ echo >&2 "Cannot write to ${1}! Aborting ..."
46
+ exit 1
47
+ fi
48
49
"${EDITOR}" "${1}"
50
exit $?
@@ -67,7 +52,10 @@ edit() {
52
53
copy_and_edit() {
54
# check we can copy
70
- file_is_in_path "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
55
+ if [ ! -w "${NETDATA_USER_CONFIG_DIR}" ]; then
56
+ echo >&2 "Cannot write to ${NETDATA_USER_CONFIG_DIR}! Aborting ..."
57
+ exit 1
58
+ fi
59
60
if [ ! -f "${NETDATA_USER_CONFIG_DIR}/${1}" ]; then
61
echo >&2 "Copying '${NETDATA_STOCK_CONFIG_DIR}/${1}' to '${NETDATA_USER_CONFIG_DIR}/${1}' ... "
@@ -85,12 +73,11 @@ if [ "${c1}" = "/" ] || [ "${c1}" = "." ]; then
73
fi
74
75
# already exists
88
-if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]; then
89
- edit "${NETDATA_USER_CONFIG_DIR}/${file}"
90
-fi
91
-
76
[ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ] && edit "${NETDATA_USER_CONFIG_DIR}/${file}"
77
+
78
+# stock config is valid, copy and edit
79
[ -f "${NETDATA_STOCK_CONFIG_DIR}/${file}" ] && copy_and_edit "${file}"
80
81
+# no such config found
82
echo >&2 "File '${file}' is not found in '${NETDATA_STOCK_CONFIG_DIR}'"
83
exit 1