diff --git a/80-Deploy_Netdata.sh b/80-Deploy_Netdata.sh new file mode 100644 index 0000000..981a701 --- /dev/null +++ b/80-Deploy_Netdata.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +## Script Location +SCRIPTDIR=$(dirname $0) +source "$SCRIPTDIR/common/colors.sh" +source "$SCRIPTDIR/common/functions.sh" +source "$SCRIPTDIR/common/load-defaults.sh" + +printf "$COL_LIGHT_BLUE" "* Checking if system already has netdata installed" +install_netdata=0 +if [[ ! service_exists netdata ]] +then + printf "$COL_YELLOW" "** $HOSTNAME appears to not have the netdata service" + install_netdata=$netdata_install +else + printf "$COL_GREEN" "** $HOSTNAME appears to already have the netdata service" +fi + +if [ "$netdata_install" == "ask" ]; then + if (whiptail --title "Netdata Install" --yes-button "yes" --no-button "no" --yesno "Do You want to install netdata?" 10 80) + then + install_netdata=1 + else + install_netdata=0 + fi +fi + + +if [ "$install_netdata" == 1 ]; then + if [[ $HOSTNAME == *template* ]]; then + printf "$COL_RED" "** Hostname $HOSTNAME contains the word 'template', skipping netdata" + install_netdata=0 + fi +fi + +## netdata parent Join +if [ "$install_netdata" == 1 ]; then + printf "$COL_YELLOW" "** Setting up netdata." + # TODO deply a sed method to set the IP and API for the netdata parent + # netdata_parent_ip=$(whiptail --passwordbox "Please enter the ip address of the netdata parent." 8 78 --title "Netdata Parent Prompt" 3>&1 1>&2 2>&3) + # netdata_parent_api=$(whiptail --passwordbox "Please enter the api key of the netdata parent." 8 78 --title "Netdata Parent Prompt" 3>&1 1>&2 2>&3) + curl https://my-netdata.io/kickstart.sh > /tmp/netdata-kickstart.sh && sh /tmp/netdata-kickstart.sh + wget -O /etc/netdata/stream.conf http://10.0.69.250:89/stream.conf.hass + systemctl restart netdata +else + printf "$COL_CYAN" "** Skipping netdata setup" +fi diff --git a/common/defaults-blank b/common/defaults-blank index 761a750..07a693b 100644 --- a/common/defaults-blank +++ b/common/defaults-blank @@ -4,3 +4,4 @@ unattended_upgrades_priority="low" systemd_journaling="ask" freeipa_join_realm="ask" freeipa_ca="ask" +netdata_install="ask" diff --git a/common/defaults-dbb b/common/defaults-dbb index bf4afe6..135c308 100644 --- a/common/defaults-dbb +++ b/common/defaults-dbb @@ -4,3 +4,4 @@ unattended_upgrades_priority="medium" systemd_journaling_tweak=1 freeipa_join_realm=1 freeipa_ca=1 +netdata_install=1 diff --git a/common/functions.sh b/common/functions.sh index 2a63c70..52bcc96 100644 --- a/common/functions.sh +++ b/common/functions.sh @@ -87,3 +87,13 @@ install_pkg() { "${PKG_INSTALL[@]}" "${pkg_to_install}" } + + +service_exists() { + local n=$1 + if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then + return 0 + else + return 1 + fi +}