summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorJames Mills <prologic@shortcircuit.net.au>2020-02-05 08:10:03 +1000
committerGitHub <noreply@github.com>2020-02-05 08:10:03 +1000
commit742f4c9840eee5ede44f31dcff0b36c06241c19a (patch)
tree5660b3aa91f7a5859f5733ea090d1f2d60eefa9d /system
parentd20eaa58c1113baab06b0577cd34866d61609dbd (diff)
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
Diffstat (limited to 'system')
-rwxr-xr-xsystem/edit-config.in37
1 files changed, 12 insertions, 25 deletions
diff --git a/system/edit-config.in b/system/edit-config.in
index e97df99584..050d97cdef 100755
--- a/system/edit-config.in
+++ b/system/edit-config.in
@@ -32,34 +32,19 @@ USAGE:
EOF
cd "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
- ls >&2 -R *.conf */*.conf
+ ls >&2 -R ./*.conf ./*/*.conf
exit 1
fi
-file_is_in_path() {
- local file path real
- file="${1}"
- path="${2}"
-
- real="$(readlink -f "${file}")"
-
- # we don't have working readlink
- [ -z "${real}" ] && return 0
-
- if [ ! -z "${real}" ] && [ -z "$(echo "${real}" | grep -E "^${path}.*$")" ]; then
- echo >&2 "File '${file}' is physically at '${real}', which is not in '${path}'. Aborting."
- exit 1
- fi
-
- return 0
-}
-
edit() {
echo >&2 "Editing '${1}' ..."
# check we can edit
- file_is_in_path "${1}" "${NETDATA_USER_CONFIG_DIR}" || exit 1
+ if [ ! -w "${1}" ]; then
+ echo >&2 "Cannot write to ${1}! Aborting ..."
+ exit 1
+ fi
"${EDITOR}" "${1}"
exit $?
@@ -67,7 +52,10 @@ edit() {
copy_and_edit() {
# check we can copy
- file_is_in_path "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
+ if [ ! -w "${NETDATA_USER_CONFIG_DIR}" ]; then
+ echo >&2 "Cannot write to ${NETDATA_USER_CONFIG_DIR}! Aborting ..."
+ exit 1
+ fi
if [ ! -f "${NETDATA_USER_CONFIG_DIR}/${1}" ]; then
echo >&2 "Copying '${NETDATA_STOCK_CONFIG_DIR}/${1}' to '${NETDATA_USER_CONFIG_DIR}/${1}' ... "
@@ -85,12 +73,11 @@ if [ "${c1}" = "/" ] || [ "${c1}" = "." ]; then
fi
# already exists
-if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]; then
- edit "${NETDATA_USER_CONFIG_DIR}/${file}"
-fi
-
[ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ] && edit "${NETDATA_USER_CONFIG_DIR}/${file}"
+
+# stock config is valid, copy and edit
[ -f "${NETDATA_STOCK_CONFIG_DIR}/${file}" ] && copy_and_edit "${file}"
+# no such config found
echo >&2 "File '${file}' is not found in '${NETDATA_STOCK_CONFIG_DIR}'"
exit 1