fix garmin

This commit is contained in:
MickLesk 2026-02-22 19:48:50 +01:00
parent 12b1084e21
commit c7fd4d9516
3 changed files with 69 additions and 94 deletions

View File

@ -3,7 +3,7 @@ COMMUNITY_SCRIPTS_URL="${COMMUNITY_SCRIPTS_URL:-https://git.community-scripts.or
source <(curl -fsSL "$COMMUNITY_SCRIPTS_URL/misc/build.func")
# Copyright (c) 2021-2026 community-scripts ORG
# Author: aliaksei135
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
# License: MIT | https://github.com/community-scripts/ProxmoxVED/raw/main/LICENSE
# Source: https://github.com/arpanghosh8453/garmin-grafana
APP="garmin-grafana"
@ -12,7 +12,7 @@ var_cpu="${var_cpu:-2}"
var_ram="${var_ram:-2048}"
var_disk="${var_disk:-8}"
var_os="${var_os:-debian}"
var_version="${var_version:-12}"
var_version="${var_version:-13}"
var_unprivileged="${var_unprivileged:-1}"
header_info "$APP"
@ -20,81 +20,61 @@ variables
color
catch_errors
# this only updates garmin-grafana, not influxdb or grafana, which are upgraded with apt
function update_script() {
header_info
check_container_storage
check_container_resources
header_info
check_container_storage
check_container_resources
if [[ ! -d /opt/garmin-grafana/ ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
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
msg_info "Stopping Services"
systemctl stop garmin-grafana
systemctl stop grafana-server
systemctl stop influxdb
msg_ok "Stopped Services"
if [[ ! -f /opt/garmin-grafana/.env ]]; then
msg_error "No .env file found in /opt/garmin-grafana/.env"
exit
fi
source /opt/garmin-grafana/.env
if [[ -z "${INFLUXDB_USER}" || -z "${INFLUXDB_PASSWORD}" || -z "${INFLUXDB_NAME}" ]]; then
msg_error "INFLUXDB_USER, INFLUXDB_PASSWORD, or INFLUXDB_NAME not set in .env file"
exit
fi
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"
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"
$STD uv sync --locked --project /opt/garmin-grafana/
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
sed -i "s/influxdb_user/${INFLUXDB_USER}/" /opt/garmin-grafana/Grafana_Datasource/influxdb.yaml
sed -i "s/influxdb_secret_password/${INFLUXDB_PASSWORD}/" /opt/garmin-grafana/Grafana_Datasource/influxdb.yaml
sed -i "s/GarminStats/${INFLUXDB_NAME}/" /opt/garmin-grafana/Grafana_Datasource/influxdb.yaml
# Copy across grafana data
cp -r /opt/garmin-grafana/Grafana_Datasource/* /etc/grafana/provisioning/datasources
cp -r /opt/garmin-grafana/Grafana_Dashboard/* /etc/grafana/provisioning/dashboards
# Copy back the env and token files
cp /opt/garmin-grafana-backup/.env /opt/garmin-grafana/.env
cp -r /opt/garmin-grafana-backup/.garminconnect /opt/garmin-grafana/.garminconnect
msg_ok "Updated $APP to v${RELEASE}"
msg_info "Starting Services"
systemctl start garmin-grafana
systemctl start grafana-server
systemctl start influxdb
msg_ok "Started Services"
msg_info "Cleaning Up"
rm -rf /opt/garmin-grafana-backup
msg_ok "Cleanup Completed"
echo "${RELEASE}" >/opt/${APP}_version.txt
msg_ok "Updated Successfully!"
else
msg_ok "No update required. ${APP} is already at v${RELEASE}"
fi
if [[ ! -d /opt/garmin-grafana ]]; then
msg_error "No ${APP} Installation Found!"
exit
fi
if check_for_gh_release "garmin-grafana" "arpanghosh8453/garmin-grafana"; then
msg_info "Stopping Services"
systemctl stop garmin-grafana
msg_ok "Stopped Services"
msg_info "Backing up Data"
cp /opt/garmin-grafana/.env /opt/garmin-grafana.env.bak
cp -r /opt/garmin-grafana/.garminconnect /opt/garmin-grafana-tokens.bak
msg_ok "Backed up Data"
CLEAN_INSTALL=1 fetch_and_deploy_gh_release "garmin-grafana" "arpanghosh8453/garmin-grafana"
msg_info "Restoring Data"
cp /opt/garmin-grafana.env.bak /opt/garmin-grafana/.env
cp -r /opt/garmin-grafana-tokens.bak /opt/garmin-grafana/.garminconnect
rm -f /opt/garmin-grafana.env.bak
rm -rf /opt/garmin-grafana-tokens.bak
msg_ok "Restored Data"
msg_info "Updating Dependencies"
source /opt/garmin-grafana/.env
$STD uv sync --locked --project /opt/garmin-grafana/
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
sed -i "s/influxdb_user/${INFLUXDB_USERNAME}/" /opt/garmin-grafana/Grafana_Datasource/influxdb.yaml
sed -i "s/influxdb_secret_password/${INFLUXDB_PASSWORD}/" /opt/garmin-grafana/Grafana_Datasource/influxdb.yaml
sed -i "s/GarminStats/${INFLUXDB_DATABASE}/" /opt/garmin-grafana/Grafana_Datasource/influxdb.yaml
cp -r /opt/garmin-grafana/Grafana_Datasource/* /etc/grafana/provisioning/datasources
cp -r /opt/garmin-grafana/Grafana_Dashboard/* /etc/grafana/provisioning/dashboards
msg_ok "Updated Dependencies"
msg_info "Starting Services"
systemctl start garmin-grafana
$STD systemctl restart grafana-server
msg_ok "Started Services"
msg_ok "Updated Successfully!"
fi
exit
}
start
build_container
description
msg_ok "Completed successfully!\n"
msg_ok "Completed Successfully!\n"
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:3000${CL}"

View File

@ -10,20 +10,20 @@
"privileged": false,
"interface_port": 3000,
"documentation": "https://github.com/arpanghosh8453/garmin-grafana",
"config_path": "",
"config_path": "/opt/garmin-grafana/.env",
"website": "https://github.com/arpanghosh8453/garmin-grafana",
"logo": "https://cdn.jsdelivr.net/gh/selfhst/icons@main/webp/garmin-grafana.webp",
"description": "A docker container to fetch data from Garmin servers and store the data in a local influxdb database for appealing visualization with Grafana.",
"description": "A self-hosted solution to fetch data from Garmin servers and store it in a local InfluxDB database for visualization with Grafana.",
"install_methods": [
{
"type": "default",
"script": "ct/garmin-grafana.sh",
"resources": {
"cpu": 2,
"ram": 2,
"ram": 2048,
"hdd": 8,
"os": "Debian",
"version": "12"
"version": "13"
}
}
],
@ -33,12 +33,12 @@
},
"notes": [
{
"text": "Show login and database credentials: `cat ~/.garmin-grafana.creds`",
"text": "Grafana and InfluxDB credentials are stored in `/opt/garmin-grafana/.env`.",
"type": "info"
},
{
"text": "`garmin-grafana` only imports the past 7 days by default. To import historical data, use the `~/bulk-import.sh` script after installation.",
"text": "`garmin-grafana` only imports the past 7 days by default. To import historical data, use `/usr/local/bin/garmin-bulk-import` after installation.",
"type": "info"
}
]
}
}

View File

@ -13,13 +13,6 @@ setting_up_container
network_check
update_os
msg_info "Installing Dependencies"
$STD apt-get install -y \
python3 \
python3-requests \
python3-dotenv
msg_ok "Installed Dependencies"
setup_uv
setup_deb822_repo "influxdb" \
@ -29,7 +22,7 @@ setup_deb822_repo "influxdb" \
"main"
msg_info "Installing InfluxDB"
$STD apt-get install -y influxdb
$STD apt install -y influxdb
msg_ok "Installed InfluxDB"
msg_info "Installing Chronograf"
@ -57,19 +50,18 @@ setup_deb822_repo "grafana" \
msg_info "Installing Grafana"
$STD apt install -y grafana
$STD systemctl enable --now grafana-server
sleep 20
msg_ok "Installed Grafana"
msg_info "Configuring Grafana"
GRAFANA_PASS=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | cut -c1-13)
$STD grafana-cli admin reset-admin-password "${GRAFANA_PASS}"
local retries=0
while ! grafana-cli admin reset-admin-password "${GRAFANA_PASS}" &>/dev/null; do
((retries++))
[[ $retries -ge 30 ]] && break
sleep 2
done
$STD grafana-cli plugins install marcusolsson-hourly-heatmap-panel
$STD systemctl restart grafana-server
{
echo "Grafana Credentials"
echo "Grafana User: admin"
echo "Grafana Password: ${GRAFANA_PASS}"
} >>~/garmin-grafana.creds
msg_ok "Configured Grafana"
fetch_and_deploy_gh_release "garmin-grafana" "arpanghosh8453/garmin-grafana"
@ -102,9 +94,11 @@ INFLUXDB_PASSWORD=${INFLUXDB_PASSWORD}
INFLUXDB_DATABASE=${INFLUXDB_NAME}
GARMIN_IS_CN=${GARMIN_CN}
TOKEN_DIR=/opt/garmin-grafana/.garminconnect
GRAFANA_USER=admin
GRAFANA_PASSWORD=${GRAFANA_PASS}
EOF
if [ -z "$(ls -A /opt/garmin-grafana/.garminconnect)" ]; then
if [[ -z "$(ls -A /opt/garmin-grafana/.garminconnect)" ]]; then
read -r -p "Please enter your Garmin Connect Email: " GARMIN_EMAIL
read -r -p "Please enter your Garmin Connect Password (used to generate token, NOT stored): " GARMIN_PASSWORD
read -r -p "Please enter your MFA Code (leave blank if not applicable): " GARMIN_MFA
@ -115,7 +109,7 @@ ${GARMIN_PASSWORD}
${GARMIN_MFA}
EOF
unset GARMIN_EMAIL GARMIN_PASSWORD GARMIN_MFA
if [ -z "$(ls -A /opt/garmin-grafana/.garminconnect)" ]; then
if [[ -z "$(ls -A /opt/garmin-grafana/.garminconnect)" ]]; then
msg_error "Failed to create token"
exit 1
fi
@ -144,13 +138,14 @@ msg_info "Creating Service"
cat <<EOF >/etc/systemd/system/garmin-grafana.service
[Unit]
Description=garmin-grafana Service
After=network.target
After=network.target influxdb.service
Requires=influxdb.service
[Service]
Type=simple
WorkingDirectory=/opt/garmin-grafana
EnvironmentFile=/opt/garmin-grafana/.env
ExecStart=/root/.local/bin/uv run --project /opt/garmin-grafana/ /opt/garmin-grafana/src/garmin_grafana/garmin_fetch.py
ExecStart=$(which uv) run --project /opt/garmin-grafana/ /opt/garmin-grafana/src/garmin_grafana/garmin_fetch.py
Restart=on-failure
RestartSec=5