Skip to content

Offline gym log for Android. No account, no ads, no internet.

Add Docker and install scripts for self-hosting

InlitX9d682d38da6b
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..07a161c
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,18 @@
+.git
+.github
+.dart_tool
+build
+android
+ios
+macos
+linux
+windows
+doc-personal
+docs
+fastlane
+fdroid
+site
+test
+server/.dart_tool
+server/test
+**/*.iml
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..e08aa5f
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,31 @@
+ARG FLUTTER_VERSION=3.41.9
+
+FROM --platform=$BUILDPLATFORM ghcr.io/cirruslabs/flutter:${FLUTTER_VERSION} AS web
+WORKDIR /src
+COPY packages ./packages
+COPY pubspec.yaml pubspec.lock l10n.yaml analysis_options.yaml ./
+RUN flutter pub get
+COPY lib ./lib
+COPY assets ./assets
+COPY web ./web
+RUN flutter build web --wasm --release --no-web-resources-cdn --pwa-strategy=none
+
+FROM dart:3.11 AS server
+WORKDIR /src/server
+COPY packages /src/packages
+COPY server/pubspec.yaml server/pubspec.lock ./
+RUN dart pub get
+COPY server ./
+RUN dart compile exe bin/server.dart -o /out/gymmane-server
+
+FROM scratch
+COPY --from=server /runtime/ /
+COPY --from=server /out/gymmane-server /app/gymmane-server
+COPY --from=web /src/build/web /app/web
+ENV GYMMANE_DATA=/data \
+ GYMMANE_WEB=/app/web \
+ GYMMANE_PORT=8080
+VOLUME /data
+EXPOSE 8080
+HEALTHCHECK --interval=60s --timeout=5s --start-period=10s CMD ["/app/gymmane-server", "--health"]
+ENTRYPOINT ["/app/gymmane-server"]
diff --git a/SELFHOST.md b/SELFHOST.md
new file mode 100644
index 0000000..d2d4920
--- /dev/null
+++ b/SELFHOST.md
@@ -0,0 +1,163 @@
+# Self-hosting GymMane
+
+The whole GymMane app also runs in the browser, served from your own machine: a home server, a
+NAS, a Raspberry Pi or your laptop. Same design, same features, laid out for a big screen. Your data
+stays in one folder on that machine. No account, no cloud, nothing leaves your network.
+
+The phone app does not change: it still has no internet permission at all. If you want the phone and
+the server to share data, they do it through a folder you sync with Syncthing (see below).
+
+## Install in one command
+
+**Linux, a VPS or a Raspberry Pi** (also macOS):
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/InlitX/GymMane/main/selfhost/install.sh | sh
+```
+
+That's it. The script:
+
+- uses Docker if the machine has it, and the standalone binary if it doesn't (no Docker needed);
+- starts GymMane as a service that comes back on its own after a reboot;
+- creates a password for you, opens the port in the firewall if you run it as root;
+- prints the address to open and the password.
+
+Add `-s -- --sync` at the end to also run Syncthing for the phone app (needs Docker):
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/InlitX/GymMane/main/selfhost/install.sh | sh -s -- --sync
+```
+
+Run the same command again to update. `--uninstall` removes it and keeps your data.
+
+**Windows** (a PC or a server you reach over Remote Desktop), in PowerShell:
+
+```powershell
+irm https://raw.githubusercontent.com/InlitX/GymMane/main/selfhost/install.ps1 | iex
+```
+
+Run it as administrator to start GymMane with Windows and open the firewall port. Without admin it
+starts when you log in.
+
+No password? Set `GYMMANE_PASSWORD=` (empty) before running the script. Already have one you like?
+Set `GYMMANE_PASSWORD=yours`.
+
+## Docker by hand
+
+```sh
+mkdir gymmane && cd gymmane
+curl -fsSLO https://raw.githubusercontent.com/InlitX/GymMane/main/compose.yaml
+echo "GYMMANE_PASSWORD=pick-something-long" > .env
+docker compose up -d
+```
+
+Open `http://localhost:8080` (or `http://<server-ip>:8080` from any device on your network).
+Everything you log is stored in `./gymmane-data`. Back up that folder and you have everything.
+
+Or with plain Docker:
+
+```sh
+docker run -d --name gymmane -p 8080:8080 -v gymmane-data:/data --restart unless-stopped ghcr.io/inlitx/gymmane
+```
+
+Images are built for `amd64` and `arm64` (Raspberry Pi 4/5 and most NAS boxes).
+
+## By hand, without Docker or scripts
+
+Download the archive for your system from the
+[latest release](https://github.com/InlitX/GymMane/releases/latest), unpack it and run
+`gymmane-server` (on Windows, `start.bat`). The `web` folder must stay next to it. On macOS, if the
+system blocks the binary, run `xattr -d com.apple.quarantine gymmane-server` once.
+
+## Settings
+
+All settings are environment variables:
+
+| Variable | Default | What it does |
+|---|---|---|
+| `GYMMANE_PORT` | `8080` | Port to listen on |
+| `GYMMANE_HOST` | `0.0.0.0` | Address to bind. Use `127.0.0.1` to keep it to this machine |
+| `GYMMANE_DATA` | `./data` (Docker: `/data`) | Where your data lives |
+| `GYMMANE_PASSWORD` | none | Ask for a password in the browser (any user name works) |
+| `GYMMANE_SYNC` | `<data>/sync` | Folder shared with your phone. `off` turns it off |
+| `GYMMANE_KEEP_DAYS` | `30` | Daily copies of your data kept in `<data>/history` |
+
+Put them in the settings file of your install, one per line, and restart GymMane:
+
+| Installed with | Settings file | Restart |
+|---|---|---|
+| Docker Compose | `.env` next to `compose.yaml` | `docker compose up -d` |
+| Script, Linux or macOS | `~/gymmane/.env` (`/opt/gymmane/.env` as root) | run the script again |
+| Script, Windows | `%LOCALAPPDATA%\GymMane\gymmane.env` | run the script again |
+
+Running the script again keeps whatever you added. In the web app, Settings › Data & backup shows
+the folder the server shares with your phone.
+
+The password uses plain HTTP authentication. If you open GymMane from outside your home, put it
+behind a reverse proxy with HTTPS (Caddy, Traefik, Nginx Proxy Manager…) or a VPN like Tailscale or
+WireGuard.
+
+## Using it on several devices
+
+Open the same address on your laptop, tablet or phone browser. They all read and write the same data
+on the server, and each one picks up the others' changes within seconds. You can also install it as
+an app from the browser menu ("Install app" or "Add to Home Screen").
+
+## Sharing data with the phone app (Syncthing)
+
+The phone app never connects to the server. They share a folder instead:
+each side leaves its copy there, and each side brings in what the other left, merging it with what it
+already has.
+
+1. On the server, run the installer with `--sync` (or `docker compose --profile sync up -d`).
+ Open `http://<server-ip>:8384`, the Syncthing page, and share the `GymMane` folder (it is
+ `gymmane-data/sync` on disk).
+
+2. On the phone, install [Syncthing-Fork](https://f-droid.org/packages/com.github.catfriend1.syncthingandroid/)
+ from F-Droid, pair it with the server and accept the `GymMane` folder into a folder on your phone.
+ For a home server you can turn off Global Discovery, Relaying and NAT traversal in both: they
+ find each other on your Wi-Fi.
+
+3. In GymMane on the phone: Settings › Data & backup › Auto backup, and choose that same folder.
+
+From then on:
+
+- Every automatic backup the phone makes reaches the server, and the server merges it within a few
+ seconds. The web app shows the change on its own.
+- Whatever you log in the browser, the server leaves in the folder a moment later. The phone brings it
+ in when it opens, or right away with Auto backup › Sync now.
+
+How merging works:
+
+- **Nothing is lost.** A workout, note, food or routine that exists on either side ends up on both.
+- **The same item edited on both sides:** the most recent copy wins.
+- **Deleting doesn't travel.** Merging never removes anything, so delete it on both sides.
+- Settings follow the most recent copy.
+
+The server also keeps a daily copy of its data in `history`, just in case.
+
+Not using Docker? Point Syncthing (any install) at the server's `sync` folder, by default
+`data/sync` next to `gymmane-server`.
+
+## What works differently in the browser
+
+Everything in the app works, with these exceptions, because browsers can't do them:
+
+- No notifications or reminders while the tab is closed (the rest timer still beeps while it's open).
+- No home screen widgets, Health Connect or Apple Health.
+- Photos and backups are uploaded and downloaded through the browser.
+
+## Updating
+
+Docker: `docker compose pull && docker compose up -d`.
+Script: run it again. Without Docker or scripts: replace the files with the new release. Your data
+folder is never touched by an update.
+
+## Building it yourself
+
+```sh
+docker build -t gymmane .
+```
+
+Or by hand: `flutter build web --wasm --release --no-web-resources-cdn` for the app, and
+`dart compile exe server/bin/server.dart` for the server, then set `GYMMANE_WEB` to `build/web`.
diff --git a/compose.yaml b/compose.yaml
new file mode 100644
index 0000000..3bfb0fe
--- /dev/null
+++ b/compose.yaml
@@ -0,0 +1,32 @@
+services:
+ gymmane:
+ image: ghcr.io/inlitx/gymmane:latest
+ build: .
+ container_name: gymmane
+ restart: unless-stopped
+ ports:
+ - "${GYMMANE_PORT:-8080}:8080"
+ volumes:
+ - ./gymmane-data:/data
+ environment:
+ GYMMANE_PASSWORD: ${GYMMANE_PASSWORD:-}
+ GYMMANE_SYNC: ${GYMMANE_SYNC:-}
+ GYMMANE_KEEP_DAYS: ${GYMMANE_KEEP_DAYS:-}
+
+ syncthing:
+ image: syncthing/syncthing:latest
+ container_name: gymmane-syncthing
+ restart: unless-stopped
+ profiles: ["sync"]
+ hostname: gymmane
+ environment:
+ PUID: "0"
+ PGID: "0"
+ ports:
+ - "8384:8384"
+ - "22000:22000/tcp"
+ - "22000:22000/udp"
+ - "21027:21027/udp"
+ volumes:
+ - ./syncthing:/var/syncthing
+ - ./gymmane-data/sync:/var/syncthing/GymMane
diff --git a/selfhost/install.ps1 b/selfhost/install.ps1
new file mode 100644
index 0000000..e1b91aa
--- /dev/null
+++ b/selfhost/install.ps1
@@ -0,0 +1,83 @@
+$ErrorActionPreference = 'Stop'
+$repo = 'InlitX/GymMane'
+$port = if ($env:GYMMANE_PORT) { $env:GYMMANE_PORT } else { '8080' }
+$home_ = if ($env:GYMMANE_HOME) { $env:GYMMANE_HOME } else { Join-Path $env:LOCALAPPDATA 'GymMane' }
+$data = Join-Path $home_ 'data'
+$envFile = Join-Path $home_ 'gymmane.env'
+$admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
+
+if ($args -contains '--uninstall') {
+ Unregister-ScheduledTask -TaskName 'GymMane' -Confirm:$false -ErrorAction SilentlyContinue
+ Get-Process gymmane-server -ErrorAction SilentlyContinue | Stop-Process -Force
+ Remove-Item -Recurse -Force (Join-Path $home_ 'web'), (Join-Path $home_ 'gymmane-server.exe'), (Join-Path $home_ 'run.cmd') -ErrorAction SilentlyContinue
+ Write-Host "GymMane removed. Your data is still in $data"
+ return
+}
+
+if ($null -ne $env:GYMMANE_PASSWORD) {
+ $pass = $env:GYMMANE_PASSWORD
+} elseif (Test-Path $envFile) {
+ $pass = ((Get-Content $envFile | Where-Object { $_ -like 'GYMMANE_PASSWORD=*' }) -replace '^GYMMANE_PASSWORD=', '')
+} else {
+ $chars = [char[]]'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'
+ $pass = -join (1..16 | ForEach-Object { $chars | Get-Random })
+}
+
+$extra = @()
+if (Test-Path $envFile) {
+ $extra = @(Get-Content $envFile | Where-Object { $_ -match '^GYMMANE_' -and $_ -notmatch '^GYMMANE_(PASSWORD|PORT|DATA|WEB)=' })
+}
+
+Write-Host 'Downloading GymMane'
+$tmp = Join-Path ([IO.Path]::GetTempPath()) ('gymmane-' + [guid]::NewGuid())
+New-Item -ItemType Directory -Force $tmp | Out-Null
+$zip = Join-Path $tmp 'gymmane.zip'
+Invoke-WebRequest -UseBasicParsing "https://github.com/$repo/releases/latest/download/gymmane-selfhost-windows-x64.zip" -OutFile $zip
+Expand-Archive $zip -DestinationPath $tmp -Force
+
+Get-Process gymmane-server -ErrorAction SilentlyContinue | Stop-Process -Force
+New-Item -ItemType Directory -Force $home_, $data | Out-Null
+Remove-Item -Recurse -Force (Join-Path $home_ 'web') -ErrorAction SilentlyContinue
+Copy-Item -Recurse -Force (Join-Path $tmp 'gymmane\*') $home_
+Remove-Item -Recurse -Force $tmp
+
+Set-Content -Path $envFile -Value (@("GYMMANE_PASSWORD=$pass", "GYMMANE_PORT=$port") + $extra) -Encoding ascii
+$run = Join-Path $home_ 'run.cmd'
+Set-Content -Path $run -Encoding ascii -Value @(
+ '@echo off',
+ "cd /d `"$home_`"",
+ "set GYMMANE_DATA=$data",
+ "set GYMMANE_WEB=$home_\web",
+ 'for /f "usebackq eol=# tokens=1,* delims==" %%a in ("gymmane.env") do set "%%a=%%b"',
+ 'gymmane-server.exe'
+)
+
+$action = New-ScheduledTaskAction -Execute 'cmd.exe' -Argument "/c `"$run`"" -WorkingDirectory $home_
+$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
+if ($admin) {
+ $trigger = New-ScheduledTaskTrigger -AtStartup
+ $principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -RunLevel Highest
+ Register-ScheduledTask -TaskName 'GymMane' -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Force | Out-Null
+ New-NetFirewallRule -DisplayName 'GymMane' -Direction Inbound -Protocol TCP -LocalPort $port -Action Allow -ErrorAction SilentlyContinue | Out-Null
+} else {
+ $trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
+ Register-ScheduledTask -TaskName 'GymMane' -Action $action -Trigger $trigger -Settings $settings -Force | Out-Null
+}
+Start-ScheduledTask -TaskName 'GymMane'
+
+Write-Host ''
+Write-Host 'GymMane is running. Open it at:'
+Write-Host " http://localhost:$port"
+Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue |
+ Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' } |
+ ForEach-Object { Write-Host " http://$($_.IPAddress):$port" }
+if ($pass) {
+ Write-Host ''
+ Write-Host "Password: $pass (any user name works)"
+}
+if (-not $admin) {
+ Write-Host ''
+ Write-Host 'It starts when you log in. Run this as administrator to start it with Windows and open the firewall port.'
+}
+Write-Host ''
+Write-Host "Your data lives in $data. Run this again any time to update."
diff --git a/selfhost/install.sh b/selfhost/install.sh
new file mode 100644
index 0000000..41bcbfb
--- /dev/null
+++ b/selfhost/install.sh
@@ -0,0 +1,234 @@
+#!/bin/sh
+set -eu
+
+REPO="InlitX/GymMane"
+RAW="https://raw.githubusercontent.com/$REPO/main"
+PORT="${GYMMANE_PORT:-8080}"
+MODE=""
+SYNC=0
+UNINSTALL=0
+
+for arg in "$@"; do
+ case "$arg" in
+ --docker) MODE=docker ;;
+ --binary) MODE=binary ;;
+ --sync) SYNC=1 ;;
+ --uninstall) UNINSTALL=1 ;;
+ -h|--help)
+ echo "GymMane installer"
+ echo " sh install.sh install or update (Docker if it is there, otherwise the binary)"
+ echo " sh install.sh --sync also run Syncthing to share data with the phone app"
+ echo " sh install.sh --docker force Docker"
+ echo " sh install.sh --binary force the standalone binary"
+ echo " sh install.sh --uninstall remove GymMane (your data folder is kept)"
+ echo "Environment: GYMMANE_PORT (8080), GYMMANE_PASSWORD (empty = no password), GYMMANE_HOME"
+ exit 0 ;;
+ esac
+done
+
+say() { printf '%s\n' "$*"; }
+have() { command -v "$1" >/dev/null 2>&1; }
+
+if [ "$(id -u)" = 0 ]; then
+ ROOT=1
+ HOME_DIR="${GYMMANE_HOME:-/opt/gymmane}"
+else
+ ROOT=0
+ HOME_DIR="${GYMMANE_HOME:-$HOME/gymmane}"
+fi
+
+fetch() {
+ if have curl; then curl -fsSL "$1" -o "$2"; else wget -q "$1" -O "$2"; fi
+}
+
+password() {
+ if [ "${GYMMANE_PASSWORD+set}" = set ]; then
+ printf '%s' "$GYMMANE_PASSWORD"
+ elif [ -f "$HOME_DIR/.env" ] && grep -q '^GYMMANE_PASSWORD=' "$HOME_DIR/.env"; then
+ grep '^GYMMANE_PASSWORD=' "$HOME_DIR/.env" | head -n1 | cut -d= -f2-
+ else
+ LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom 2>/dev/null | head -c 16 || date +%s | sha256sum | head -c 16
+ fi
+}
+
+addresses() {
+ ips=""
+ if have hostname; then ips=$(hostname -I 2>/dev/null || true); fi
+ if [ -z "$ips" ] && have ip; then
+ ips=$(ip -4 -o addr show scope global 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | tr '\n' ' ')
+ fi
+ say " http://localhost:$PORT"
+ for ip in $ips; do
+ case "$ip" in *:*) ;; *) say " http://$ip:$PORT" ;; esac
+ done
+}
+
+open_port() {
+ [ "$ROOT" = 1 ] || return 0
+ if have ufw && ufw status 2>/dev/null | grep -q 'Status: active'; then
+ ufw allow "$PORT"/tcp >/dev/null 2>&1 || true
+ [ "$SYNC" = 1 ] && { ufw allow 22000 >/dev/null 2>&1 || true; ufw allow 21027/udp >/dev/null 2>&1 || true; }
+ fi
+ if have firewall-cmd && firewall-cmd --state >/dev/null 2>&1; then
+ firewall-cmd --permanent --add-port="$PORT"/tcp >/dev/null 2>&1 || true
+ firewall-cmd --reload >/dev/null 2>&1 || true
+ fi
+}
+
+finish() {
+ pass="$1"
+ say ""
+ say "GymMane is running. Open it at:"
+ addresses
+ if [ -n "$pass" ]; then
+ say ""
+ say "Password: $pass (any user name works)"
+ say "Change it in $HOME_DIR/.env and run this script again."
+ fi
+ if [ "$SYNC" = 1 ]; then
+ say ""
+ say "Syncthing is at http://<this-machine>:8384 . Share the GymMane folder with the phone,"
+ say "then in the app pick it in Settings > Data & backup > Auto backup."
+ fi
+ say ""
+ say "Your data lives in $DATA_DIR. Run this script again any time to update."
+}
+
+compose() {
+ if docker compose version >/dev/null 2>&1; then docker compose "$@"; else docker-compose "$@"; fi
+}
+
+if [ "$UNINSTALL" = 1 ]; then
+ if [ -f "$HOME_DIR/compose.yaml" ] && have docker; then
+ (cd "$HOME_DIR" && compose --profile sync down) || true
+ fi
+ if have systemctl; then
+ if [ "$ROOT" = 1 ]; then
+ systemctl disable --now gymmane.service >/dev/null 2>&1 || true
+ rm -f /etc/systemd/system/gymmane.service
+ systemctl daemon-reload || true
+ else
+ systemctl --user disable --now gymmane.service >/dev/null 2>&1 || true
+ rm -f "$HOME/.config/systemd/user/gymmane.service"
+ systemctl --user daemon-reload || true
+ fi
+ fi
+ rm -rf "$HOME_DIR/web" "$HOME_DIR/gymmane-server" "$HOME_DIR/compose.yaml"
+ say "GymMane removed. Your data is still in $HOME_DIR (delete it yourself if you want it gone)."
+ exit 0
+fi
+
+if [ -z "$MODE" ]; then
+ if have docker && docker info >/dev/null 2>&1; then MODE=docker; else MODE=binary; fi
+fi
+
+mkdir -p "$HOME_DIR"
+PASS=$(password)
+EXTRA=""
+if [ -f "$HOME_DIR/.env" ]; then
+ EXTRA=$(grep -E '^GYMMANE_' "$HOME_DIR/.env" | grep -vE '^GYMMANE_(PASSWORD|PORT|DATA|WEB)=' || true)
+fi
+
+if [ "$MODE" = docker ]; then
+ DATA_DIR="$HOME_DIR/gymmane-data"
+ say "Installing GymMane with Docker in $HOME_DIR"
+ fetch "$RAW/compose.yaml" "$HOME_DIR/compose.yaml"
+ {
+ say "GYMMANE_PASSWORD=$PASS"
+ say "GYMMANE_PORT=$PORT"
+ if [ -n "$EXTRA" ]; then say "$EXTRA"; fi
+ } >"$HOME_DIR/.env"
+ chmod 600 "$HOME_DIR/.env"
+ cd "$HOME_DIR"
+ if [ "$SYNC" = 1 ]; then
+ compose --profile sync pull
+ compose --profile sync up -d
+ else
+ compose pull gymmane
+ compose up -d gymmane
+ fi
+ open_port
+ finish "$PASS"
+ exit 0
+fi
+
+os=$(uname -s)
+arch=$(uname -m)
+case "$os" in
+ Linux) os=linux ;;
+ Darwin) os=macos ;;
+ *) say "Sorry, $os is not supported by this script. Use Docker or the Windows installer."; exit 1 ;;
+esac
+case "$arch" in
+ x86_64|amd64) arch=x64 ;;
+ aarch64|arm64) arch=arm64 ;;
+ *) say "Sorry, $arch is not supported yet. Use Docker instead."; exit 1 ;;
+esac
+if [ "$os" = macos ] && [ "$arch" = x64 ]; then
+ say "Intel Macs are not built yet. Use Docker instead."
+ exit 1
+fi
+
+DATA_DIR="$HOME_DIR/data"
+asset="gymmane-selfhost-$os-$arch.tar.gz"
+tmp=$(mktemp -d)
+trap 'rm -rf "$tmp"' EXIT
+say "Downloading $asset"
+fetch "https://github.com/$REPO/releases/latest/download/$asset" "$tmp/$asset"
+tar -xzf "$tmp/$asset" -C "$tmp"
+if have systemctl; then
+ if [ "$ROOT" = 1 ]; then systemctl stop gymmane.service >/dev/null 2>&1 || true
+ else systemctl --user stop gymmane.service >/dev/null 2>&1 || true; fi
+fi
+rm -rf "$HOME_DIR/web"
+cp -R "$tmp/gymmane/." "$HOME_DIR/"
+chmod +x "$HOME_DIR/gymmane-server"
+mkdir -p "$DATA_DIR"
+{
+ say "GYMMANE_PASSWORD=$PASS"
+ say "GYMMANE_PORT=$PORT"
+ say "GYMMANE_DATA=$DATA_DIR"
+ say "GYMMANE_WEB=$HOME_DIR/web"
+ if [ -n "$EXTRA" ]; then say "$EXTRA"; fi
+} >"$HOME_DIR/.env"
+chmod 600 "$HOME_DIR/.env"
+[ "$os" = macos ] && xattr -d com.apple.quarantine "$HOME_DIR/gymmane-server" 2>/dev/null || true
+
+if [ "$os" = linux ] && have systemctl; then
+ if [ "$ROOT" = 1 ]; then
+ unit=/etc/systemd/system/gymmane.service
+ target=multi-user.target
+ ctl="systemctl"
+ else
+ unit="$HOME/.config/systemd/user/gymmane.service"
+ target=default.target
+ ctl="systemctl --user"
+ mkdir -p "$(dirname "$unit")"
+ fi
+ cat >"$unit" <<UNIT
+[Unit]
+Description=GymMane
+After=network-online.target
+Wants=network-online.target
+
+[Service]
+EnvironmentFile=$HOME_DIR/.env
+ExecStart=$HOME_DIR/gymmane-server
+Restart=on-failure
+RestartSec=3
+
+[Install]
+WantedBy=$target
+UNIT
+ $ctl daemon-reload
+ $ctl enable --now gymmane.service
+ if [ "$ROOT" = 0 ] && have loginctl; then loginctl enable-linger "$(id -un)" >/dev/null 2>&1 || true; fi
+ open_port
+ [ "$SYNC" = 1 ] && say "Tip: for Syncthing without Docker, install the 'syncthing' package and share $DATA_DIR/sync."
+ finish "$PASS"
+else
+ say ""
+ say "Installed in $HOME_DIR. Start it with:"
+ say " set -a; . $HOME_DIR/.env; set +a; $HOME_DIR/gymmane-server"
+ finish "$PASS"
+fi