|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2026 community-scripts ORG |
| 4 | +# Author: Tom Frenzel (tomfrenzel) |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://github.com/CodeWithCJ/SparkyFitness |
| 7 | + |
| 8 | +if ! command -v curl &>/dev/null; then |
| 9 | + printf "\r\e[2K%b" '\033[93m Setup Source \033[m' >&2 |
| 10 | + apt-get update >/dev/null 2>&1 |
| 11 | + apt-get install -y curl >/dev/null 2>&1 |
| 12 | +fi |
| 13 | +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/core.func) |
| 14 | +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/tools.func) |
| 15 | +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/error_handler.func) |
| 16 | +source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/api.func) 2>/dev/null || true |
| 17 | +declare -f init_tool_telemetry &>/dev/null && init_tool_telemetry "sparkyfitness-garmin" "addon" |
| 18 | + |
| 19 | +# Enable error handling |
| 20 | +set -Eeuo pipefail |
| 21 | +trap 'error_handler' ERR |
| 22 | +load_functions |
| 23 | + |
| 24 | +# ============================================================================== |
| 25 | +# CONFIGURATION |
| 26 | +# ============================================================================== |
| 27 | +APP="SparkyFitness Garmin Microservice" |
| 28 | +APP_TYPE="addon" |
| 29 | +INSTALL_PATH="/opt/sparkyfitness-garmin" |
| 30 | +CONFIG_PATH="/etc/sparkyfitness-garmin/.env" |
| 31 | +SERVICE_PATH="/etc/systemd/system/sparkyfitness-garmin.service" |
| 32 | +DEFAULT_PORT=8000 |
| 33 | + |
| 34 | +# ============================================================================== |
| 35 | +# OS DETECTION |
| 36 | +# ============================================================================== |
| 37 | +if ! grep -qE 'ID=debian|ID=ubuntu' /etc/os-release 2>/dev/null; then |
| 38 | + echo -e "${CROSS} Unsupported OS detected. This script only supports Debian and Ubuntu." |
| 39 | + exit 238 |
| 40 | +fi |
| 41 | + |
| 42 | +# ============================================================================== |
| 43 | +# SparkyFitness LXC DETECTION |
| 44 | +# ============================================================================== |
| 45 | +if [[ ! -d /opt/sparkyfitness ]]; then |
| 46 | + echo -e "${CROSS} No SparkyFitness installation detected. This addon must be installed within a container that already has SparkyFitness installed." |
| 47 | + exit 238 |
| 48 | +fi |
| 49 | + |
| 50 | +# ============================================================================== |
| 51 | +# UNINSTALL |
| 52 | +# ============================================================================== |
| 53 | +function uninstall() { |
| 54 | + msg_info "Uninstalling ${APP}" |
| 55 | + systemctl disable --now sparkyfitness-garmin.service &>/dev/null || true |
| 56 | + rm -rf "$SERVICE_PATH" "$CONFIG_PATH" "$INSTALL_PATH" ~/.sparkyfitness-garmin |
| 57 | + msg_ok "${APP} has been uninstalled" |
| 58 | +} |
| 59 | + |
| 60 | +# ============================================================================== |
| 61 | +# UPDATE |
| 62 | +# ============================================================================== |
| 63 | +function update() { |
| 64 | + if check_for_gh_release "sparkyfitness-garmin" "CodeWithCJ/SparkyFitness"; then |
| 65 | + PYTHON_VERSION="3.13" setup_uv |
| 66 | + |
| 67 | + msg_info "Stopping service" |
| 68 | + systemctl stop sparkyfitness-garmin.service &>/dev/null || true |
| 69 | + msg_ok "Stopped service" |
| 70 | + |
| 71 | + CLEAN_INSTALL=1 fetch_and_deploy_gh_release "sparkyfitness-garmin" "CodeWithCJ/SparkyFitness" "tarball" "latest" $INSTALL_PATH |
| 72 | + |
| 73 | + msg_info "Starting service" |
| 74 | + systemctl start sparkyfitness-garmin |
| 75 | + msg_ok "Started service" |
| 76 | + msg_ok "Updated successfully" |
| 77 | + exit |
| 78 | + fi |
| 79 | +} |
| 80 | + |
| 81 | +# ============================================================================== |
| 82 | +# INSTALL |
| 83 | +# ============================================================================== |
| 84 | +function install() { |
| 85 | + PYTHON_VERSION="3.13" setup_uv |
| 86 | + fetch_and_deploy_gh_release "sparkyfitness-garmin" "CodeWithCJ/SparkyFitness" "tarball" "latest" $INSTALL_PATH |
| 87 | + |
| 88 | + msg_info "Setting up ${APP}" |
| 89 | + mkdir -p "/etc/sparkyfitness-garmin" |
| 90 | + cp "/opt/sparkyfitness-garmin/docker/.env.example" $CONFIG_PATH |
| 91 | + cd $INSTALL_PATH/SparkyFitnessGarmin |
| 92 | + $STD uv venv --clear .venv |
| 93 | + $STD uv pip install -r requirements.txt |
| 94 | + sed -i -e "s|^#\?GARMIN_MICROSERVICE_URL=.*|GARMIN_MICROSERVICE_URL=http://${LOCAL_IP}:${DEFAULT_PORT}|" $CONFIG_PATH |
| 95 | + cat <<EOF >/etc/systemd/system/sparkyfitness-garmin.service |
| 96 | +[Unit] |
| 97 | +Description=${APP} |
| 98 | +After=network.target sparkyfitness-server.service |
| 99 | +Requires=sparkyfitness-server.service |
| 100 | +
|
| 101 | +[Service] |
| 102 | +Type=simple |
| 103 | +WorkingDirectory=$INSTALL_PATH/SparkyFitnessGarmin |
| 104 | +EnvironmentFile=$CONFIG_PATH |
| 105 | +ExecStart=$INSTALL_PATH/SparkyFitnessGarmin/.venv/bin/python3 -m uvicorn main:app --host 0.0.0.0 --port ${DEFAULT_PORT} |
| 106 | +Restart=always |
| 107 | +RestartSec=5 |
| 108 | +
|
| 109 | +[Install] |
| 110 | +WantedBy=multi-user.target |
| 111 | +EOF |
| 112 | + systemctl enable -q --now sparkyfitness-garmin |
| 113 | + msg_ok "Set up ${APP} - reachable at http://${LOCAL_IP}:${DEFAULT_PORT}" |
| 114 | + msg_ok "You might need to update the GARMIN_MICROSERVICE_URL in your SparkyFitness .env file to http://${LOCAL_IP}:${DEFAULT_PORT}" |
| 115 | +} |
| 116 | + |
| 117 | +# ============================================================================== |
| 118 | +# MAIN |
| 119 | +# ============================================================================== |
| 120 | +header_info |
| 121 | +ensure_usr_local_bin_persist |
| 122 | +get_lxc_ip |
| 123 | + |
| 124 | +# Handle type=update (called from update script) |
| 125 | +if [[ "${type:-}" == "update" ]]; then |
| 126 | + if [[ -d "$INSTALL_PATH" ]]; then |
| 127 | + update |
| 128 | + else |
| 129 | + msg_error "${APP} is not installed. Nothing to update." |
| 130 | + exit 233 |
| 131 | + fi |
| 132 | + exit 0 |
| 133 | +fi |
| 134 | + |
| 135 | +# Check if already installed |
| 136 | +if [[ -d "$INSTALL_PATH" && -n "$(ls -A "$INSTALL_PATH" 2>/dev/null)" ]]; then |
| 137 | + msg_warn "${APP} is already installed." |
| 138 | + echo "" |
| 139 | + |
| 140 | + echo -n "${TAB}Uninstall ${APP}? (y/N): " |
| 141 | + read -r uninstall_prompt |
| 142 | + if [[ "${uninstall_prompt,,}" =~ ^(y|yes)$ ]]; then |
| 143 | + uninstall |
| 144 | + exit 0 |
| 145 | + fi |
| 146 | + |
| 147 | + echo -n "${TAB}Update ${APP}? (y/N): " |
| 148 | + read -r update_prompt |
| 149 | + if [[ "${update_prompt,,}" =~ ^(y|yes)$ ]]; then |
| 150 | + update |
| 151 | + exit 0 |
| 152 | + fi |
| 153 | + |
| 154 | + msg_warn "No action selected. Exiting." |
| 155 | + exit 0 |
| 156 | +fi |
| 157 | + |
| 158 | +# Fresh installation |
| 159 | +msg_warn "${APP} is not installed." |
| 160 | +echo "" |
| 161 | +echo -e "${TAB}${INFO} This will install:" |
| 162 | +echo -e "${TAB} - UV (Python Version Manager)" |
| 163 | +echo -e "${TAB} - SparkyFitness Garmin Microservice" |
| 164 | +echo "" |
| 165 | + |
| 166 | +echo -n "${TAB}Install ${APP}? (y/N): " |
| 167 | +read -r install_prompt |
| 168 | +if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then |
| 169 | + install |
| 170 | +else |
| 171 | + msg_warn "Installation cancelled. Exiting." |
| 172 | + exit 0 |
| 173 | +fi |
0 commit comments