@cryptotaxi247 / netdata-1 / commits / 07060aec6

added edit-config (#4338)

Costa Tsaousis committed Oct 1, 2018 at 23:24 UTC 07060aec6f3d8a73cd38399dee6f441f90f0592e
4 files changed +115
.gitignore
+1
@@ -75,6 +75,7 @@ system/netdata.service
75 system/netdata.plist
76 system/netdata-freebsd
77
78 +conf.d/edit-config
79 plugins.d/alarm-notify.sh
80 plugins.d/cgroup-name.sh
81 plugins.d/charts.d.plugin
conf.d/Makefile.am
+19
@@ -3,6 +3,21 @@
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 #
5 MAINTAINERCLEANFILES= $(srcdir)/Makefile.in
6 +CLEANFILES = \
7 + edit-config \
8 + $(NULL)
9 +
10 +include $(top_srcdir)/build/subst.inc
11 +
12 +SUFFIXES = .in
13 +
14 +dist_config_SCRIPTS = \
15 + edit-config \
16 + $(NULL)
17 +
18 +dist_noinst_DATA = \
19 + edit-config.in \
20 + $(NULL)
21
22 dist_libconfig_DATA = \
23 apps_groups.conf \
@@ -17,6 +32,10 @@ dist_libconfig_DATA = \
32
33 nodeconfigdir=$(libconfigdir)/node.d
34 dist_nodeconfig_DATA = \
35 + $(NULL)
36 +
37 +usernodeconfigdir=$(configdir)/node.d
38 +dist_usernodeconfig_DATA = \
39 node.d/README.md \
40 node.d/fronius.conf.md \
41 node.d/named.conf.md \
conf.d/edit-config.in new
+94
@@ -0,0 +1,94 @@
1 +#!/usr/bin/env sh
2 +
3 +[ -f /etc/profile ] && source /etc/profile
4 +
5 +file="${1}"
6 +
7 +EDITOR="${EDITOR-vi}"
8 +[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
9 +[ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
10 +
11 +if [ -z "${file}" ]
12 +then
13 + cat <<USAGE
14 +
15 +USAGE:
16 + ${0} FILENAME
17 +
18 + Find the stock config file named FILENAME and edit it.
19 +
20 + Stock config files at: '${NETDATA_STOCK_CONFIG_DIR}'
21 + User config files at: '${NETDATA_USER_CONFIG_DIR}'
22 +
23 + Available files in '${NETDATA_STOCK_CONFIG_DIR}' to copy and edit:
24 +
25 +USAGE
26 +
27 + cd "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
28 + ls >&2 -R *.conf */*.conf
29 + exit 1
30 +
31 +fi
32 +
33 +file_is_in_path() {
34 + local file path real
35 + file="${1}"
36 + path="${2}"
37 +
38 + real="$(readlink -f "${file}")"
39 +
40 + # we don't have working readlink
41 + [ -z "${real}" ] && return 0
42 +
43 + if [ ! -z "${real}" ] && [ -z "$(echo "${real}" | grep -E "^${path}.*$")" ]
44 + then
45 + echo >&2 "File '${file}' is physically at '${real}', which is not in '${path}'. Aborting."
46 + exit 1
47 + fi
48 +
49 + return 0
50 +}
51 +
52 +edit() {
53 + echo >&2 "Editing '${1}' ..."
54 +
55 + # check we can edit
56 + file_is_in_path "${1}" "${NETDATA_USER_CONFIG_DIR}" || exit 1
57 +
58 + "${EDITOR}" "${1}"
59 + exit $?
60 +}
61 +
62 +copy_and_edit() {
63 + # check we can copy
64 + file_is_in_path "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
65 +
66 + if [ ! -f "${NETDATA_USER_CONFIG_DIR}/${1}" ]
67 + then
68 + echo >&2 "Copying '${NETDATA_STOCK_CONFIG_DIR}/${1}' to '${NETDATA_USER_CONFIG_DIR}/${1}' ... "
69 + cp -p "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_USER_CONFIG_DIR}/${1}" || exit 1
70 + fi
71 +
72 + edit "${NETDATA_USER_CONFIG_DIR}/${1}"
73 +}
74 +
75 +# make sure it is not absolute filename
76 +c1="$(echo "${file}" | cut -b 1)"
77 +if [ "${c1}" = "/" ] || [ "${c1}" = "." ]
78 +then
79 + echo >&2 "Please don't use filenames starting with '/' or '.'"
80 + exit 1
81 +fi
82 +
83 +# already exists
84 +if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]
85 +then
86 + echo >&2 "Editing existing file '${NETDATA_USER_CONFIG_DIR}/${file}' ... "
87 + edit "${NETDATA_USER_CONFIG_DIR}/${file}"
88 +fi
89 +
90 +[ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ] && edit "${NETDATA_USER_CONFIG_DIR}/${file}"
91 +[ -f "${NETDATA_STOCK_CONFIG_DIR}/${file}" ] && copy_and_edit "${file}"
92 +
93 +echo >&2 "File '${file}' is not found in '${NETDATA_STOCK_CONFIG_DIR}'"
94 +exit 1
netdata-installer.sh
+1
@@ -745,6 +745,7 @@ done
745 run chown -R "${ROOT_USER}:${NETDATA_GROUP}" "${NETDATA_USER_CONFIG_DIR}"
746 run find "${NETDATA_USER_CONFIG_DIR}" -type f -exec chmod 0640 {} \;
747 run find "${NETDATA_USER_CONFIG_DIR}" -type d -exec chmod 0755 {} \;
748 +run chmod 755 "${NETDATA_USER_CONFIG_DIR}/edit-config"
749
750 # --- stock conf dir ----
751