diff options
author | Paul Emm. Katsoulakis <34388743+paulkatsoulakis@users.noreply.github.com> | 2019-04-05 11:47:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-05 11:47:18 +0200 |
commit | e1f7a105c4a08cd7ae4bd6fc79f022d1d59dcd8a (patch) | |
tree | 74fa69f3965e16c6568cb8ecea0839fe6a0a4c73 | |
parent | 01b91117caecce0d50020a51673b9d3b3b0e01f0 (diff) |
netdata/packaging/installer: HoS situation - Fix broken install-or-update script (#5806)
During the last major installer refactoring, we managed to break (again) the static64 installer.
We modified the code that defines user/group ownerships for netdata installation,
forcing the install to end up with a process running as netdata and files set as root
To fix this, we re-instate default NETDATA_USER/NETDATA_GROUP to root, as it should be.
Then we attempt group netadata creation. If that succeeds, we attempt user netdata creation.
If that succeeds, we attempt secondary groups addition.
Report errors on all otherwise situations from each step.
-rw-r--r-- | packaging/installer/functions.sh | 18 | ||||
-rwxr-xr-x | packaging/makeself/install-or-update.sh | 35 |
2 files changed, 27 insertions, 26 deletions
diff --git a/packaging/installer/functions.sh b/packaging/installer/functions.sh index 1e83ab8265..4270c4ee05 100644 --- a/packaging/installer/functions.sh +++ b/packaging/installer/functions.sh @@ -614,11 +614,11 @@ portable_add_user() { portable_add_group() { local groupname="${1}" - # Check if group exist + # Check if group exist if cut -d ':' -f 1 </etc/group | grep "^${groupname}$" 1>/dev/null 2>&1; then - echo >&2 "Group '${groupname}' already exists." - return 0 - fi + echo >&2 "Group '${groupname}' already exists." + return 0 + fi echo >&2 "Adding ${groupname} user group ..." @@ -644,13 +644,13 @@ portable_add_group() { portable_add_user_to_group() { local groupname="${1}" username="${2}" - # Check if group exist + # Check if group exist if ! cut -d ':' -f 1 </etc/group | grep "^${groupname}$" >/dev/null 2>&1; then - echo >&2 "Group '${groupname}' does not exist." - return 1 - fi + echo >&2 "Group '${groupname}' does not exist." + return 1 + fi - # Check if user is in group + # Check if user is in group if [[ ",$(grep "^${groupname}:" </etc/group | cut -d ':' -f 4)," =~ ,${username}, ]]; then # username is already there echo >&2 "User '${username}' is already in group '${groupname}'." diff --git a/packaging/makeself/install-or-update.sh b/packaging/makeself/install-or-update.sh index 1c65533a7a..2ab50a17cf 100755 --- a/packaging/makeself/install-or-update.sh +++ b/packaging/makeself/install-or-update.sh @@ -69,27 +69,28 @@ then fi # ----------------------------------------------------------------------------- -progress "Add user netdata to required user groups" +progress "Attempt to create user/group netdata/netadata" NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody" NETDATA_ADDED_TO_GROUPS="" -if [ "${UID}" -eq 0 ]; then - if ! portable_add_group netdata; then - run_failed "Failed to add netdata group" - NETDATA_GROUP="root" - fi - if ! portable_add_user netdata "/opt/netdata"; then - run_failed "Failed to add netdata user" - NETDATA_USER="root" - fi - - for g in ${NETDATA_WANTED_GROUPS}; do - # shellcheck disable=SC2086 - portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}" || run_failed "Failed to add netdata user to secondary groups" - done +# Default user/group +NETDATA_USER="root" +NETDATA_GROUP="root" + +if portable_add_group netdata; then + if portable_add_user netdata "/opt/netdata"; then + progress "Add user netdata to required user groups" + for g in ${NETDATA_WANTED_GROUPS}; do + # shellcheck disable=SC2086 + portable_add_user_to_group ${g} netdata && NETDATA_ADDED_TO_GROUPS="${NETDATA_ADDED_TO_GROUPS} ${g}" || run_failed "Failed to add netdata user to secondary groups" + done + NETDATA_USER="netdata" + NETDATA_GROUP="netdata" + else + run_failed "I could not add user netdata, will be using root" + fi else - run_failed "Failed to add netdata user and group" - run_failed "The installer does not run as root." + run_failed "I could not add group netdata, so no user netdata will be created as well. Netdata run as root:root" fi # ----------------------------------------------------------------------------- |