summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--conf.d/Makefile.am19
-rwxr-xr-xconf.d/edit-config.in94
-rwxr-xr-xnetdata-installer.sh1
4 files changed, 115 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index da1f165ae6..c6e6c870b1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,6 +75,7 @@ system/netdata.service
system/netdata.plist
system/netdata-freebsd
+conf.d/edit-config
plugins.d/alarm-notify.sh
plugins.d/cgroup-name.sh
plugins.d/charts.d.plugin
diff --git a/conf.d/Makefile.am b/conf.d/Makefile.am
index 5b705a5945..5021e7f97f 100644
--- a/conf.d/Makefile.am
+++ b/conf.d/Makefile.am
@@ -3,6 +3,21 @@
# SPDX-License-Identifier: GPL-3.0-or-later
#
MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
+CLEANFILES = \
+ edit-config \
+ $(NULL)
+
+include $(top_srcdir)/build/subst.inc
+
+SUFFIXES = .in
+
+dist_config_SCRIPTS = \
+ edit-config \
+ $(NULL)
+
+dist_noinst_DATA = \
+ edit-config.in \
+ $(NULL)
dist_libconfig_DATA = \
apps_groups.conf \
@@ -17,6 +32,10 @@ dist_libconfig_DATA = \
nodeconfigdir=$(libconfigdir)/node.d
dist_nodeconfig_DATA = \
+ $(NULL)
+
+usernodeconfigdir=$(configdir)/node.d
+dist_usernodeconfig_DATA = \
node.d/README.md \
node.d/fronius.conf.md \
node.d/named.conf.md \
diff --git a/conf.d/edit-config.in b/conf.d/edit-config.in
new file mode 100755
index 0000000000..7f11193493
--- /dev/null
+++ b/conf.d/edit-config.in
@@ -0,0 +1,94 @@
+#!/usr/bin/env sh
+
+[ -f /etc/profile ] && source /etc/profile
+
+file="${1}"
+
+EDITOR="${EDITOR-vi}"
+[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
+[ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
+
+if [ -z "${file}" ]
+then
+ cat <<USAGE
+
+USAGE:
+ ${0} FILENAME
+
+ Find the stock config file named FILENAME and edit it.
+
+ Stock config files at: '${NETDATA_STOCK_CONFIG_DIR}'
+ User config files at: '${NETDATA_USER_CONFIG_DIR}'
+
+ Available files in '${NETDATA_STOCK_CONFIG_DIR}' to copy and edit:
+
+USAGE
+
+ cd "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
+ 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
+
+ "${EDITOR}" "${1}"
+ exit $?
+}
+
+copy_and_edit() {
+ # check we can copy
+ file_is_in_path "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
+
+ if [ ! -f "${NETDATA_USER_CONFIG_DIR}/${1}" ]
+ then
+ echo >&2 "Copying '${NETDATA_STOCK_CONFIG_DIR}/${1}' to '${NETDATA_USER_CONFIG_DIR}/${1}' ... "
+ cp -p "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_USER_CONFIG_DIR}/${1}" || exit 1
+ fi
+
+ edit "${NETDATA_USER_CONFIG_DIR}/${1}"
+}
+
+# make sure it is not absolute filename
+c1="$(echo "${file}" | cut -b 1)"
+if [ "${c1}" = "/" ] || [ "${c1}" = "." ]
+then
+ echo >&2 "Please don't use filenames starting with '/' or '.'"
+ exit 1
+fi
+
+# already exists
+if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]
+then
+ echo >&2 "Editing existing file '${NETDATA_USER_CONFIG_DIR}/${file}' ... "
+ edit "${NETDATA_USER_CONFIG_DIR}/${file}"
+fi
+
+[ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ] && edit "${NETDATA_USER_CONFIG_DIR}/${file}"
+[ -f "${NETDATA_STOCK_CONFIG_DIR}/${file}" ] && copy_and_edit "${file}"
+
+echo >&2 "File '${file}' is not found in '${NETDATA_STOCK_CONFIG_DIR}'"
+exit 1
diff --git a/netdata-installer.sh b/netdata-installer.sh
index 21765b0f25..448a0422a1 100755
--- a/netdata-installer.sh
+++ b/netdata-installer.sh
@@ -745,6 +745,7 @@ done
run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_USER_CONFIG_DIR}"
run find "${NETDATA_USER_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
run find "${NETDATA_USER_CONFIG_DIR}" -type d -exec chmod 0755 {} \;
+run chmod 755 "${NETDATA_USER_CONFIG_DIR}/edit-config"
# --- stock conf dir ----