diff --git a/ct/garmin-grafana.sh b/ct/garmin-grafana.sh index 87236f2..fb0a5af 100644 --- a/ct/garmin-grafana.sh +++ b/ct/garmin-grafana.sh @@ -25,23 +25,19 @@ function update_script() { check_container_storage check_container_resources - # Check if installation is present | -f for file, -d for folder if [[ ! -d /opt/garmin-grafana/ ]]; then msg_error "No ${APP} Installation Found!" exit fi - # Crawling the new version and checking whether an update is required RELEASE=$(curl -fsSL https://api.github.com/repos/arpanghosh8453/garmin-grafana/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }') if [[ ! -d /opt/garmin-grafana/ ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then - # Stopping Services msg_info "Stopping $APP" systemctl stop garmin-grafana systemctl stop grafana-server systemctl stop influxdb msg_ok "Stopped $APP" - # Get required environment variables from the .env file if [[ ! -f /opt/garmin-grafana/.env ]]; then msg_error "No .env file found in /opt/garmin-grafana/.env" exit @@ -52,21 +48,17 @@ function update_script() { exit fi - # Creating Backup msg_info "Creating Backup" tar -czf "/opt/${APP}_backup_$(date +%F).tar.gz" /opt/garmin-grafana/.garminconnect /opt/garmin-grafana/.env mv /opt/garmin-grafana/ /opt/garmin-grafana-backup/ msg_ok "Backup Created" - # Execute Update msg_info "Updating $APP to v${RELEASE}" curl -fsSL -o "${RELEASE}.zip" "https://github.com/arpanghosh8453/garmin-grafana/archive/refs/tags/${RELEASE}.zip" unzip -q "${RELEASE}.zip" mv "garmin-grafana-${RELEASE}/" "/opt/garmin-grafana" rm -f "${RELEASE}.zip" - # Install python dependencies with uv $STD uv sync --locked --project /opt/garmin-grafana/ - # Setup grafana provisioning configs # shellcheck disable=SC2016 sed -i 's/\${DS_GARMIN_STATS}/garmin_influxdb/g' /opt/garmin-grafana/Grafana_Dashboard/Garmin-Grafana-Dashboard.json sed -i 's/influxdb:8086/localhost:8086/' /opt/garmin-grafana/Grafana_Datasource/influxdb.yaml @@ -81,19 +73,16 @@ function update_script() { cp -r /opt/garmin-grafana-backup/.garminconnect /opt/garmin-grafana/.garminconnect msg_ok "Updated $APP to v${RELEASE}" - # Starting Services msg_info "Starting $APP" systemctl start garmin-grafana systemctl start grafana-server systemctl start influxdb msg_ok "Started $APP" - # Cleaning up msg_info "Cleaning Up" rm -rf /opt/garmin-grafana-backup msg_ok "Cleanup Completed" - # Last Action echo "${RELEASE}" >/opt/${APP}_version.txt msg_ok "Update Successful" else diff --git a/install/garmin-grafana-install.sh b/install/garmin-grafana-install.sh index f49a56e..c0d85a6 100644 --- a/install/garmin-grafana-install.sh +++ b/install/garmin-grafana-install.sh @@ -16,18 +16,16 @@ update_os # Installing Dependencies msg_info "Installing Dependencies" -# Grafana dependencies -$STD apt-get install -y gnupg -$STD apt-get install -y apt-transport-https -$STD apt-get install -y software-properties-common -# Influx dependencies -$STD apt-get install -y lsb-base -$STD apt-get install -y lsb-release -$STD apt-get install -y gnupg2 -# garmin-grafana dependencies -$STD apt-get install -y python3 -$STD apt-get install -y python3-requests -$STD apt-get install -y python3-dotenv +$STD apt-get install -y \ + gnupg \ + apt-transport-https \ + software-properties-common \ + lsb-base \ + lsb-release \ + gnupg2 \ + python3 \ + python3-requests \ + python3-dotenv setup_uv msg_ok "Installed Dependencies" @@ -46,10 +44,8 @@ $STD dpkg -i chronograf_1.10.7_amd64.deb msg_ok "Installed InfluxDB" msg_info "Setting up InfluxDB" -# Patch the config file to use the tsi1 index $STD sed -i 's/# index-version = "inmem"/index-version = "tsi1"/' /etc/influxdb/influxdb.conf -# Create InfluxDB user and database INFLUXDB_USER="garmin_grafana_user" INFLUXDB_PASSWORD=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) INFLUXDB_NAME="GarminStats" @@ -78,9 +74,7 @@ msg_ok "Installed Grafana" msg_info "Setting up Grafana" GRAFANA_USER="admin" GRAFANA_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13) -# Create Grafana user $STD grafana-cli admin reset-admin-password "${GRAFANA_PASS}" -# # Install plugins $STD grafana-cli plugins install marcusolsson-hourly-heatmap-panel $STD systemctl restart grafana-server # Output credentials to file @@ -101,9 +95,7 @@ if [[ "${RELEASE}" == v* ]]; then RELEASE="${RELEASE:1}" fi mv "garmin-grafana-${RELEASE}/" "/opt/garmin-grafana" -# Create dir for garmin tokens mkdir -p /opt/garmin-grafana/.garminconnect -# Install python dependencies with uv $STD uv sync --locked --project /opt/garmin-grafana/ # Setup grafana provisioning configs # shellcheck disable=SC2016 @@ -127,7 +119,6 @@ else GARMIN_CN="False" fi -# Setup environment variables cat </opt/garmin-grafana/.env INFLUXDB_HOST=localhost INFLUXDB_PORT=8086 @@ -142,7 +133,6 @@ EOF # garmin-grafana usually prompts the user for email and password (and MFA) on first run, # then stores a refreshable token. We try to avoid storing user credentials in the env vars if [ -z "$(ls -A /opt/garmin-grafana/.garminconnect)" ]; then - # Get the email and password from the user read -r -p "Please enter your Garmin Connect Email: " GARMIN_EMAIL read -r -p "Please enter your Garmin Connect Password (this is used to generate a token and NOT stored): " GARMIN_PASSWORD read -r -p "Please enter your MFA Code (if applicable, leave blank if not): " GARMIN_MFA @@ -153,7 +143,6 @@ ${GARMIN_EMAIL} ${GARMIN_PASSWORD} ${GARMIN_MFA} EOF - # Clear the credentials from the terminal unset GARMIN_EMAIL unset GARMIN_PASSWORD unset GARMIN_MFA @@ -164,7 +153,6 @@ EOF fi fi -# Restart Grafana to pick up the provisioned data sources and dashboards $STD systemctl restart grafana-server # Add a script to make the manual bulk data import easier @@ -197,7 +185,6 @@ EOF chmod +x ~/bulk-import.sh msg_ok "Set up garmin-grafana" -# Creating Service (if needed) msg_info "Creating Service" cat </etc/systemd/system/garmin-grafana.service [Unit]