@cryptotaxi247 / netdata-1 / commits / d20eaa58c

Re-formated ./system/edit-config.in with shfmt -w -i 2 -ci -sr (#7932)

James Mills committed Feb 5, 2020 at 07:45 UTC d20eaa58c1113baab06b0577cd34866d61609dbd
1 file changed +43 -48
system/edit-config.in
+43 -48
@@ -4,18 +4,17 @@
4
5 file="${1}"
6
7 -if [ "$(command -v editor)" ] ; then
8 - EDITOR="${EDITOR-editor}"
7 +if [ "$(command -v editor)" ]; then
8 + EDITOR="${EDITOR-editor}"
9 else
10 - EDITOR="${EDITOR-vi}"
10 + EDITOR="${EDITOR-vi}"
11 fi
12
13 -[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
13 +[ -z "${NETDATA_USER_CONFIG_DIR}" ] && NETDATA_USER_CONFIG_DIR="@configdir_POST@"
14 [ -z "${NETDATA_STOCK_CONFIG_DIR}" ] && NETDATA_STOCK_CONFIG_DIR="@libconfigdir_POST@"
15
16 -if [ -z "${file}" ]
17 -then
18 - cat <<USAGE
16 +if [ -z "${file}" ]; then
17 + cat << EOF
18
19 USAGE:
20 ${0} FILENAME
@@ -30,71 +29,67 @@ USAGE:
29
30 Available files in '${NETDATA_STOCK_CONFIG_DIR}' to copy and edit:
31
33 -USAGE
32 +EOF
33
35 - cd "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
36 - ls >&2 -R *.conf */*.conf
37 - exit 1
34 + cd "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
35 + ls >&2 -R *.conf */*.conf
36 + exit 1
37
38 fi
39
40 file_is_in_path() {
42 - local file path real
43 - file="${1}"
44 - path="${2}"
45 -
46 - real="$(readlink -f "${file}")"
47 -
48 - # we don't have working readlink
49 - [ -z "${real}" ] && return 0
50 -
51 - if [ ! -z "${real}" ] && [ -z "$(echo "${real}" | grep -E "^${path}.*$")" ]
52 - then
53 - echo >&2 "File '${file}' is physically at '${real}', which is not in '${path}'. Aborting."
54 - exit 1
55 - fi
56 -
57 - return 0
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
58 edit() {
61 - echo >&2 "Editing '${1}' ..."
59 + echo >&2 "Editing '${1}' ..."
60
63 - # check we can edit
64 - file_is_in_path "${1}" "${NETDATA_USER_CONFIG_DIR}" || exit 1
61 + # check we can edit
62 + file_is_in_path "${1}" "${NETDATA_USER_CONFIG_DIR}" || exit 1
63
66 - "${EDITOR}" "${1}"
67 - exit $?
64 + "${EDITOR}" "${1}"
65 + exit $?
66 }
67
68 copy_and_edit() {
71 - # check we can copy
72 - file_is_in_path "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
69 + # check we can copy
70 + file_is_in_path "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_STOCK_CONFIG_DIR}" || exit 1
71
74 - if [ ! -f "${NETDATA_USER_CONFIG_DIR}/${1}" ]
75 - then
76 - echo >&2 "Copying '${NETDATA_STOCK_CONFIG_DIR}/${1}' to '${NETDATA_USER_CONFIG_DIR}/${1}' ... "
77 - cp -p "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_USER_CONFIG_DIR}/${1}" || exit 1
78 - fi
72 + if [ ! -f "${NETDATA_USER_CONFIG_DIR}/${1}" ]; then
73 + echo >&2 "Copying '${NETDATA_STOCK_CONFIG_DIR}/${1}' to '${NETDATA_USER_CONFIG_DIR}/${1}' ... "
74 + cp -p "${NETDATA_STOCK_CONFIG_DIR}/${1}" "${NETDATA_USER_CONFIG_DIR}/${1}" || exit 1
75 + fi
76
80 - edit "${NETDATA_USER_CONFIG_DIR}/${1}"
77 + edit "${NETDATA_USER_CONFIG_DIR}/${1}"
78 }
79
80 # make sure it is not absolute filename
81 c1="$(echo "${file}" | cut -b 1)"
85 -if [ "${c1}" = "/" ] || [ "${c1}" = "." ]
86 -then
87 - echo >&2 "Please don't use filenames starting with '/' or '.'"
88 - exit 1
82 +if [ "${c1}" = "/" ] || [ "${c1}" = "." ]; then
83 + echo >&2 "Please don't use filenames starting with '/' or '.'"
84 + exit 1
85 fi
86
87 # already exists
92 -if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]
93 -then
94 - edit "${NETDATA_USER_CONFIG_DIR}/${file}"
88 +if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]; then
89 + edit "${NETDATA_USER_CONFIG_DIR}/${file}"
90 fi
91
97 -[ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ] && edit "${NETDATA_USER_CONFIG_DIR}/${file}"
92 +[ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ] && edit "${NETDATA_USER_CONFIG_DIR}/${file}"
93 [ -f "${NETDATA_STOCK_CONFIG_DIR}/${file}" ] && copy_and_edit "${file}"
94
95 echo >&2 "File '${file}' is not found in '${NETDATA_STOCK_CONFIG_DIR}'"