Browse Source

Add support for libmosquitto to netdata-installer.sh for ACLK support. (#8025)

* Add initial libmosquitto install support.

THis adds initial support for pulling in our custom version of
libmosquitto during the install process and using it with Netdata.

This can be manually disabled by specifying `--disable-libmosquitto` on
the install command-line.

* Extract the libmosquitto sources in the right place.

* Fix error message to be more generic.

* Fix handling of temporary directory.

* Only pull in required headers.

* Correct new help text.

* Change option naming to disable ACLK.

* Use correct name for configure option.

* Adjust target directory for libs.

* Properly include OpenSSL on macOS.

* Change references to ACLK to Netdata Cloud.

* Update version of libmosquitto being used.
Austin S. Hemmelgarn 5 years ago
parent
commit
e96c122958
3 changed files with 79 additions and 3 deletions
  1. 77 3
      netdata-installer.sh
  2. 1 0
      packaging/mosquitto.checksums
  3. 1 0
      packaging/mosquitto.version

+ 77 - 3
netdata-installer.sh

@@ -25,6 +25,12 @@ if [ "${NETDATA_SOURCE_DIR}" != "${INSTALLER_DIR}" ] && [ "${INSTALLER_DIR}" !=
   echo >&2 "Warning: you are currently in '${NETDATA_SOURCE_DIR}' but the installer is in '${INSTALLER_DIR}'."
 fi
 
+# -----------------------------------------------------------------------------
+# Pull in OpenSSL properly if on macOS
+if [ "$(uname -s)" = 'Darwin' ] && [ -d /usr/local/opt/openssl/include ] ; then
+    export C_INCLUDE_PATH="/usr/local/opt/openssl/include"
+fi
+
 # -----------------------------------------------------------------------------
 # reload the user profile
 
@@ -45,9 +51,11 @@ else
   source "${NETDATA_SOURCE_DIR}/packaging/installer/functions.sh" || exit 1
 fi
 
-download_go() {
+download_tarball() {
   url="${1}"
   dest="${2}"
+  name="${3}"
+  opt="${4}"
 
   if command -v curl > /dev/null 2>&1; then
     run curl -sSL --connect-timeout 10 --retry 3 "${url}" > "${dest}"
@@ -55,14 +63,18 @@ download_go() {
     run wget -T 15 -O - "${url}" > "${dest}"
   else
     echo >&2
-    echo >&2 "Downloading go.d plugin from '${url}' failed because of missing mandatory packages."
-    echo >&2 "Either add packages or disable it by issuing '--disable-go' in the installer"
+    echo >&2 "Downloading ${name} from '${url}' failed because of missing mandatory packages."
+    echo >&2 "Either add packages or disable it by issuing '--disable-${opt}' in the installer"
     echo >&2
 
     run_failed "I need curl or wget to proceed, but neither is available on this system."
   fi
 }
 
+download_go() {
+  download_tarball "${1}" "${2}" "go.d plugin" "go"
+}
+
 # make sure we save all commands we run
 run_logfile="netdata-installer.log"
 
@@ -157,6 +169,7 @@ USAGE: ${PROGRAM} [options]
   --nightly-channel          Use most recent nightly udpates instead of GitHub releases.
                              This results in more frequent updates.
   --disable-go               Disable installation of go.d.plugin.
+  --disable-cloud            Disable the agent-cloud link, required for Netdata Cloud functionality.
   --enable-plugin-freeipmi   Enable the FreeIPMI plugin. Default: enable it when libipmimonitoring is available.
   --disable-plugin-freeipmi
   --disable-https            Explicitly disable TLS support
@@ -241,6 +254,7 @@ while [ -n "${1}" ]; do
     "--disable-x86-sse") NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-x86-sse/} --disable-x86-sse" ;;
     "--disable-telemetry") NETDATA_DISABLE_TELEMETRY=1 ;;
     "--disable-go") NETDATA_DISABLE_GO=1 ;;
+    "--disable-cloud") NETDATA_DISABLE_LIBMOSQUITTO=1 ; NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS//--disable-aclk/} --disable-aclk" ;;
     "--install")
       NETDATA_PREFIX="${2}/netdata"
       shift 1
@@ -413,6 +427,66 @@ fi
 
 trap build_error EXIT
 
+# -----------------------------------------------------------------------------
+
+fetch_libmosquitto() {
+  download_tarball "${1}" "${2}" "libmosquitto" "cloud"
+}
+
+build_libmosquitto() {
+  run make -C "${1}/lib"
+}
+
+copy_libmosquitto() {
+  target_dir="${PWD}/externaldeps/mosquitto"
+
+  run mkdir -p "${target_dir}"
+
+  run cp "${1}/lib/libmosquitto.a" "${target_dir}"
+  run cp "${1}/lib/mosquitto.h" "${target_dir}"
+}
+
+bundle_libmosquitto() {
+  if [ -n "${NETDATA_DISABLE_LIBMOSQUITTO}" ] ; then
+    return 0
+  fi
+
+  progress "Prepare custom libmosquitto version"
+
+  MOSQUITTO_PACKAGE_VERSION="$(cat packaging/mosquitto.version)"
+
+  tmp=$(mktemp -d netdata-mosquitto-XXXXXX)
+  MOSQUITTO_PACKAGE_BASENAME="${MOSQUITTO_PACKAGE_VERSION}.tar.gz"
+
+  if [ -z "${NETDATA_LOCAL_TARBALL_OVERRIDE_MOSQUITTO}" ]; then
+    fetch_libmosquitto "https://github.com/netdata/mosquitto/archive/${MOSQUITTO_PACKAGE_BASENAME}" "${tmp}/${MOSQUITTO_PACKAGE_BASENAME}"
+  else
+    progress "Using provided mosquitto tarball ${NETDATA_LOCAL_TARBALL_OVERRIDE_MOSQUITTO}"
+    run cp "${NETDATA_LOCAL_TARBALL_OVERRIDE_MOSQUITTO}" "${tmp}/${MOSQUITTO_PACKAGE_BASENAME}"
+  fi
+
+  if [ ! -f "${tmp}/${MOSQUITTO_PACKAGE_BASENAME}" ] || [ ! -s "${tmp}/${MOSQUITTO_PACKAGE_BASENAME}" ]; then
+    run_failed "unable to find a usable libmosquitto source archive, Netdata Cloud will not be available"
+    return 0
+  fi
+
+  grep "${MOSQUITTO_PACKAGE_BASENAME}\$" "${INSTALLER_DIR}/packaging/go.d.checksums" >"${tmp}/sha256sums.txt" 2>/dev/null
+
+  cp packaging/mosquitto.checksums "${tmp}/sha256sums.txt"
+
+  # Checksum validation
+  if ! (cd "${tmp}" && safe_sha256sum -c "sha256sums.txt"); then
+    run_failed "mosquitto files checksum validation failed."
+    return 0
+  fi
+
+  run tar -xf "${tmp}/${MOSQUITTO_PACKAGE_BASENAME}" -C "${tmp}"
+
+  build_libmosquitto "${tmp}/mosquitto-${MOSQUITTO_PACKAGE_VERSION}" && copy_libmosquitto "${tmp}/mosquitto-${MOSQUITTO_PACKAGE_VERSION}" && rm "${tmp}"
+}
+
+bundle_libmosquitto
+
 # -----------------------------------------------------------------------------
 echo >&2
 progress "Run autotools to configure the build environment"

+ 1 - 0
packaging/mosquitto.checksums

@@ -0,0 +1 @@
+1bcf9caaaf28fcc3ede4bccca32c74db5d37139a1f1ba4c6cf1811722fde203b  v.1.6.8_Netdata-2.tar.gz

+ 1 - 0
packaging/mosquitto.version

@@ -0,0 +1 @@
+v.1.6.8_Netdata-2