#!/bin/bash

# Line to search for
LINE_TO_CHECK="NTFY_ACCESS_TOKEN=\"tk_nsui9xi73r9ev1jdp76pddk0y4f5v\""
# File to which lines will be added
FILE_PATH="health_alarm_notify.conf"
LINE_TO_ADD=$(cat <<EOF
SEND_NTFY="YES"
NTFY_ACCESS_TOKEN="tk_nsui9xi73r9ev1jdp76pddk0y4f5v"
DEFAULT_RECIPIENT_NTFY="https://ntfy.inxs.me/netdata"
EOF
)
$MY_TEMPLATE="/mypool1/data/shared/etc/netdata/$FILE_PATH"

# Enter the config dir
cd /etc/netdata 2>/dev/null || cd /opt/netdata/etc/netdata

# Check if the file exists
if [ -f "$FILE_PATH" ]; then
  # Check if the line exists in the file
  if grep -Fxq "$LINE_TO_CHECK" "$FILE_PATH"; then
    echo "The line exists in the file."
  else
    # Append lines to the file
    echo "$LINE_TO_ADD" >> "$FILE_PATH"
  fi    
else
  sudo rsync -avP -e "ssh -o StrictHostKeyChecking=no" dbi@vmx-nas.swallow-grue.ts.net:"$MY_TEMPLATE" .
fi


