summaryrefslogtreecommitdiffstats
path: root/makeself
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-04-01 19:05:12 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-04-01 19:05:12 +0300
commitf3cce1e472a4204d5bc99eb9eeabba1d8d85bb0a (patch)
tree5d7d27aa7051bb039f9c9ce1056b063f5b70232f /makeself
parentf207ae117ccbdc099936b65367b80ef8b57448cf (diff)
protected configuration on updates; use supplied commands by default
Diffstat (limited to 'makeself')
-rwxr-xr-xmakeself/functions.sh11
-rwxr-xr-xmakeself/install-or-update.sh67
-rwxr-xr-xmakeself/jobs/70-netdata-git.install.sh21
-rwxr-xr-xmakeself/jobs/80-netdata-links.install.sh13
-rwxr-xr-xmakeself/jobs/99-makeself.install.sh63
-rwxr-xr-xmakeself/post-installer.sh7
6 files changed, 145 insertions, 37 deletions
diff --git a/makeself/functions.sh b/makeself/functions.sh
index 4ff439fb9f..48835f0f5b 100755
--- a/makeself/functions.sh
+++ b/makeself/functions.sh
@@ -11,8 +11,19 @@
[ -z "${PROCESSORS}" -o $((PROCESSORS)) -lt 1 ] && export PROCESSORS=1
export NULL=
+# make sure the path does not end with /
+if [ "${NETDATA_INSTALL_PATH:$(( ${#NETDATA_INSTALL_PATH} - 1)):1}" = "/" ]
+ then
+ export NETDATA_INSTALL_PATH="${NETDATA_INSTALL_PATH:0:$(( ${#NETDATA_INSTALL_PATH} - 1))}"
+fi
+
+# find the parent directory
+export NETDATA_INSTALL_PARENT="$(dirname "${NETDATA_INSTALL_PATH}")"
+
+
# debug
echo "ME=${0}"
+echo "NETDATA_INSTALL_PARENT=${NETDATA_INSTALL_PARENT}"
echo "NETDATA_INSTALL_PATH=${NETDATA_INSTALL_PATH}"
echo "NETDATA_MAKESELF_PATH=${NETDATA_MAKESELF_PATH}"
echo "NETDATA_SOURCE_PATH=${NETDATA_SOURCE_PATH}"
diff --git a/makeself/install-or-update.sh b/makeself/install-or-update.sh
index 114d42ff61..8afa08ad7a 100755
--- a/makeself/install-or-update.sh
+++ b/makeself/install-or-update.sh
@@ -2,6 +2,49 @@
. $(dirname "${0}")/functions.sh
+# -----------------------------------------------------------------------------
+progress "Checking new configuration files"
+
+declare -A configs_signatures=()
+. system/configs.signatures
+
+if [ ! -d etc/netdata ]
+ then
+ mkdir -p etc/netdata
+fi
+
+for x in $(find etc/netdata.new -name '*.conf' -type f)
+do
+ # find it relative filename
+ f="${x/*etc\/netdata.new\//}"
+ t="${x/*etc\/netdata.new\/etc\/netdata/}"
+ d=$(dirname "${d}")
+
+ if [ ! -d "${d}" ]
+ then
+ run mkdir -p "${d}"
+ fi
+
+ if [ ! -f "${t}" ]
+ then
+ run cp "${x}" "${t}"
+ continue
+ fi
+
+ # find the checksum of the existing file
+ md5="$(cat "${t}" | ${md5sum} | cut -d ' ' -f 1)"
+
+ # check if it matches
+ if [ "${configs_signatures[${md5}]}" = "${f}" ]
+ then
+ run cp "${x}" "${t}"
+ else
+ run cp "${x}" "${t}.orig"
+ fi
+done
+
+
+# -----------------------------------------------------------------------------
progress "Add user netdata to required user groups"
NETDATA_ADDED_TO_DOCKER=0
@@ -25,28 +68,38 @@ else
run_failed "The installer does not run as root."
fi
+
# -----------------------------------------------------------------------------
progress "Install logrotate configuration for netdata"
if [ ${UID} -eq 0 ]
then
- if [ -d /etc/logrotate.d -a ! -f /etc/logrotate.d/netdata ]
+ if [ -d /etc/logrotate.d ]
then
- run cp system/netdata.logrotate /etc/logrotate.d/netdata
- fi
+ if [ ! -f /etc/logrotate.d/netdata ]
+ then
+ run cp system/netdata.logrotate /etc/logrotate.d/netdata
+ fi
- if [ -f /etc/logrotate.d/netdata ]
- then
- run chmod 644 /etc/logrotate.d/netdata
+ if [ -f /etc/logrotate.d/netdata ]
+ then
+ run chmod 644 /etc/logrotate.d/netdata
+ fi
+ else
+ run_failed "logrotate dir /etc/logrotate.d is not available."
fi
+else
+ run_failed "The installer does not run as root."
fi
+
# -----------------------------------------------------------------------------
progress "Install netdata at system init"
if [ "${UID}" -eq 0 ]
then
install_netdata_service
+else
+ run_failed "The installer does not run as root."
fi
-
diff --git a/makeself/jobs/70-netdata-git.install.sh b/makeself/jobs/70-netdata-git.install.sh
index acfa374414..74346254e1 100755
--- a/makeself/jobs/70-netdata-git.install.sh
+++ b/makeself/jobs/70-netdata-git.install.sh
@@ -2,23 +2,12 @@
. ${NETDATA_MAKESELF_PATH}/functions.sh "${@}" || exit 1
-cd .. || exit 1
+cd "${NETDATA_SOURCE_PATH}" || exit 1
export CFLAGS="-O3 -static"
-run ./netdata-installer.sh --install /opt --dont-wait --dont-start-it
-mkdir -p "${NETDATA_INSTALL_PATH}/system"
+run ./netdata-installer.sh --install "${NETDATA_INSTALL_PARENT}" \
+ --dont-wait \
+ --dont-start-it \
+ ${NULL}
-cp \
- system/netdata-init-d \
- system/netdata-lsb \
- system/netdata-openrc \
- system/netdata.logrotate \
- system/netdata.service \
- "${NETDATA_INSTALL_PATH}/system/"
-
-cp \
- makeself/post-installer.sh \
- makeself/install-or-update.sh \
- installer/functions.sh \
- "${NETDATA_INSTALL_PATH}/system/"
diff --git a/makeself/jobs/80-netdata-links.install.sh b/makeself/jobs/80-netdata-links.install.sh
deleted file mode 100755
index 373a2c852d..0000000000
--- a/makeself/jobs/80-netdata-links.install.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-. ${NETDATA_MAKESELF_PATH}/functions.sh "${@}" || exit 1
-
-run cd "${NETDATA_INSTALL_PATH}"
-run ln -s etc/netdata netdata-configs
-run ln -s usr/share/netdata/web netdata-web-files
-run ln -s usr/libexec/netdata netdata-plugins
-run ln -s var/lib/netdata netdata-dbs
-run ln -s var/cache/netdata netdata-metrics
-run ln -s var/log/netdata netdata-logs
-
-
diff --git a/makeself/jobs/99-makeself.install.sh b/makeself/jobs/99-makeself.install.sh
index b7193d90e5..db65678631 100755
--- a/makeself/jobs/99-makeself.install.sh
+++ b/makeself/jobs/99-makeself.install.sh
@@ -3,6 +3,68 @@
. $(dirname "${0}")/../functions.sh "${@}" || exit 1
+# -----------------------------------------------------------------------------
+# create a few quick links
+
+run cd "${NETDATA_INSTALL_PATH}"
+run ln -s etc/netdata netdata-configs
+run ln -s usr/share/netdata/web netdata-web-files
+run ln -s usr/libexec/netdata netdata-plugins
+run ln -s var/lib/netdata netdata-dbs
+run ln -s var/cache/netdata netdata-metrics
+run ln -s var/log/netdata netdata-logs
+
+
+# -----------------------------------------------------------------------------
+# copy the files needed by makeself installation
+
+run mkdir -p "${NETDATA_INSTALL_PATH}/system"
+run cd "${NETDATA_SOURCE_PATH}" || exit 1
+
+cp \
+ makeself/post-installer.sh \
+ makeself/install-or-update.sh \
+ installer/functions.sh \
+ configs.signatures \
+ system/netdata-init-d \
+ system/netdata-lsb \
+ system/netdata-openrc \
+ system/netdata.logrotate \
+ system/netdata.service \
+ "${NETDATA_INSTALL_PATH}/system/"
+
+
+# -----------------------------------------------------------------------------
+# create a wrapper to start our netdata with a modified path
+
+mv "${NETDATA_INSTALL_PATH}/bin/netdata" \
+ "${NETDATA_INSTALL_PATH}/bin/netdata.bin" || exit 1
+
+cat >"${NETDATA_INSTALL_PATH}/bin/netdata" <<EOF
+#!${NETDATA_INSTALL_PATH}/bin/bash
+export PATH="${NETDATA_INSTALL_PATH}/bin:${PATH}"
+exec "${NETDATA_INSTALL_PATH}/bin/netdata.bin" "${@}"
+EOF
+chmod 755 "${NETDATA_INSTALL_PATH}/bin/netdata"
+
+
+# -----------------------------------------------------------------------------
+# move etc to protect the destination when unpacked
+
+if [ -d "${NETDATA_INSTALL_PATH}/etc/netdata" ]
+ then
+ if [ -d "${NETDATA_INSTALL_PATH}/etc/netdata.new" ]
+ then
+ rm -rf "${NETDATA_INSTALL_PATH}/etc/netdata.new" || exit 1
+ fi
+
+ mv "${NETDATA_INSTALL_PATH}/etc/netdata" \
+ "${NETDATA_INSTALL_PATH}/etc/netdata.new" || exit 1
+fi
+
+
+# -----------------------------------------------------------------------------
+# create the makeself archive
"${NETDATA_MAKESELF_PATH}/makeself.sh" \
--gzip \
@@ -17,4 +79,3 @@
./system/post-installer.sh \
${NULL}
-
diff --git a/makeself/post-installer.sh b/makeself/post-installer.sh
index f969c24913..10f9863b9a 100755
--- a/makeself/post-installer.sh
+++ b/makeself/post-installer.sh
@@ -1,3 +1,10 @@
#!/bin/sh
+# This script is started using the shell of the system
+# and executes our 'install-or-update.sh' script
+# using the netdata supplied, statically linked BASH
+#
+# so, at 'install-or-update.sh' we are always sure
+# we run under BASH v4.
+
./bin/bash system/install-or-update.sh "${@}"