diff --git a/INSTALL.sh b/INSTALL.sh new file mode 100644 index 0000000..41a54a7 --- /dev/null +++ b/INSTALL.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +echo "Installing bash monitoring script..." + +if [ ${UID} -ne 0 ]; then + echo "Even if the script itself doesn't need to run as root," + echo "the installer does need to be started with sudo or as root." + exit 1 +fi + +if [ -d /opt/bash-logging ]; then + echo "It seems like the script is already set up on this system." + echo "Do you want to overide the old version? Sensors will be kept" + + while true; do + read -p "[y/n] " -n 2 CHOICE + + if [ "${CHOICE}" = "y" ]; then + SENSORS_TEMP_DIR=$(mktemp -d) + mv /opt/bash-logging/sensors.d/ /opt/bash-logging/.env ${SENSORS_TEMP_DIR}/ + rm -rf /opt/bash-logging/ + mkdir -p /opt/bash-logging/ + mv ${SENSORS_TEMP_DIR}/sensors.d/ ${SENSORS_TEMP_DIR}/.env /opt/bash-logging/ + + break + elif [ "${CHOICE}" = "n" ]; then + exit 1 + fi + done +fi + +echo "Copying files..." +[ ! -d /opt/bash-logging ] && mkdir /opt/bash-logging +cp -r inc main.sh /opt/bash-logging/ + +if [ -f /opt/bash-logging/.env ]; then + echo "Not overwriting existing .env" +elif [ -f .env ]; then + echo "Copying local .env" + cp .env /opt/bash-logging/.env +else + echo "Copying template .env, be sure to adjust it!" + cp .env.example /opt/bash-logging/.env +fi + +if [ -d /opt/bash-logging/sensors.d ]; then + echo "Not overwriting existing sensors.d" +else + echo "Copying example sensors.d be sure to adjust it!" + cp -r sensors.d /opt/bash-logging/ +fi + +echo "Copying systemd script..." +cp systemd/bash-logging.service /etc/systemd/system/ +systemctl daemon-reload +systemctl enable --now bash-logging.service \ No newline at end of file diff --git a/systemd/bash-logging.service b/systemd/bash-logging.service new file mode 100644 index 0000000..1cc6ecb --- /dev/null +++ b/systemd/bash-logging.service @@ -0,0 +1,12 @@ +[Unit] +Description=BASH based InfluxDB logging script +After=network.target + +[Service] +ExecStart=/usr/bin/env bash main.sh +WorkingDirectory=/opt/bash-logging/ +Restart=always +RestartSec=3 + +[Install] +WantedBy=multi-user.target \ No newline at end of file