Skip to content

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

Self-host installers: new look, exit codes, image fallback

InlitXf7fd2baf9843
diff --git a/selfhost/install.ps1 b/selfhost/install.ps1
index c96b8f2..7d362b4 100644
--- a/selfhost/install.ps1
+++ b/selfhost/install.ps1
@@ -10,15 +10,58 @@ function Install-GymMane {
$quiet = $env:GYMMANE_YES -eq '1'
$action = if ($env:GYMMANE_UNINSTALL -eq '1') { 'remove' } else { '' }
- function Step($t) { Write-Host ''; Write-Host ' > ' -ForegroundColor DarkYellow -NoNewline; Write-Host $t -ForegroundColor White }
- function Ok($t) { Write-Host ' + ' -ForegroundColor Green -NoNewline; Write-Host $t }
- function Note($t) { Write-Host " - $t" -ForegroundColor DarkGray }
- function Warn($t) { Write-Host ' ! ' -ForegroundColor Yellow -NoNewline; Write-Host $t }
- function Prompt-Line($q, $hint) { Write-Host ' ? ' -ForegroundColor DarkYellow -NoNewline; Write-Host "$q " -NoNewline; Write-Host $hint -ForegroundColor DarkGray -NoNewline; Write-Host ' ' -NoNewline }
+ $vt = $false
+ try { $vt = [bool]$Host.UI.SupportsVirtualTerminal } catch { }
+ if ($env:NO_COLOR -or [Console]::IsOutputRedirected) { $vt = $false }
+ $e = [char]27
+ function Rgb($r, $g, $b) { if ($vt) { "$e[38;2;$r;$g;${b}m" } else { '' } }
+ $R = if ($vt) { "$e[0m" } else { '' }
+ $B = if ($vt) { "$e[1m" } else { '' }
+ $A = Rgb 217 161 132
+ $G = Rgb 143 181 140
+ $D = Rgb 128 128 128
+ $F = Rgb 80 80 80
+ $Y = Rgb 230 190 110
+ $X = Rgb 230 120 110
+ $SH = Rgb 96 78 66
+ $CLR = if ($vt) { "`r$e[K" } else { "`r" }
+
+ $tick = [string][char]0x2713
+ $cross = [string][char]0x2717
+ $dot = [string][char]0x00B7
+ $bul = [string][char]0x203A
+ $hz = [string][char]0x2500
+ $vbar = [string][char]0x2502
+ $spin = @(0x280B, 0x2819, 0x2839, 0x2838, 0x283C, 0x2834, 0x2826, 0x2827, 0x2807, 0x280F) | ForEach-Object { [string][char]$_ }
+
+ $script:step = 0
+ $script:steps = 4
+ $script:boxW = 52
+
+ function Put($t) { Write-Host $t -NoNewline }
+ function Line($t) { Write-Host $t }
+ function Step($t) { $script:step++; Line ''; Line " $A$B$($script:step)$R$F/$($script:steps)$R $B$t$R"; Line '' }
+ function Ok($t) { Line " $G$tick$R $t" }
+ function Note($t) { Line " $D$dot $t$R" }
+ function Warn($t) { Line " $Y!$R $t" }
+ function Prompt-Line($q, $hint) { Put " $A?$R $q $F$hint$R $A$bul$R " }
+
+ function Spinner($i, $msg) { if ($vt) { Put "$CLR $A$($spin[$i % 10])$R $D$msg$R" } }
+ function Unspin { if ($vt) { Put $CLR } }
+
+ function BoxFit([string[]]$values) { foreach ($v in $values) { if ($v.Length + 11 -gt $script:boxW) { $script:boxW = $v.Length + 11 } } }
+ function BoxTop { Line " $F$([char]0x256D)$($hz * ($script:boxW + 2))$([char]0x256E)$R" }
+ function BoxBottom { Line " $F$([char]0x2570)$($hz * ($script:boxW + 2))$([char]0x256F)$R" }
+ function BoxRow([string]$plain, [string]$styled) {
+ if (-not $styled) { $styled = $plain }
+ $pad = [Math]::Max(0, $script:boxW - $plain.Length)
+ Line " $F$vbar$R $styled$(' ' * $pad) $F$vbar$R"
+ }
+ function BoxPair($label, $value) { BoxRow ($label.PadRight(11) + $value) ("$D$($label.PadRight(11))$R$value") }
function Ask($q, $default) {
if ($quiet) { return $default }
- Prompt-Line $q "($default)"
+ Prompt-Line $q $default
$a = Read-Host
if ([string]::IsNullOrWhiteSpace($a)) { return $default }
return $a.Trim()
@@ -26,7 +69,7 @@ function Install-GymMane {
function YesNo($q, $default) {
if ($quiet) { return $default }
- $hint = if ($default) { '[Y/n]' } else { '[y/N]' }
+ $hint = if ($default) { 'Y/n' } else { 'y/N' }
while ($true) {
Prompt-Line $q $hint
$a = (Read-Host).Trim().ToLower()
@@ -62,33 +105,56 @@ function Install-GymMane {
} catch { return $false }
}
- Write-Host ''
- Write-Host @'
- ____ __ __
- / ___|_ _ _ __ ___ | \/ | __ _ _ __ ___
- | | _| | | | '_ ` _ \| |\/| |/ _` | '_ \ / _ \
- | |_| | |_| | | | | | | | | | (_| | | | | __/
- \____|\__, |_| |_| |_|_| |_|\__,_|_| |_|\___|
- |___/
-'@ -ForegroundColor DarkYellow
- Write-Host ' Self-host installer' -ForegroundColor White
- Write-Host ' The whole app in your browser. Your data stays on this machine.' -ForegroundColor DarkGray
+ function Banner {
+ $map = @{ '#' = [char]0x2588; '7' = [char]0x2557; 'L' = [char]0x255A; 'J' = [char]0x255D; 'F' = [char]0x2554; '=' = [char]0x2550; '|' = [char]0x2551 }
+ $art = @(
+ ' ######7 ##7 ##7###7 ###7###7 ###7 #####7 ###7 ##7#######7',
+ ' ##F====J L##7 ##FJ####7 ####|####7 ####|##F==##7####7 ##|##F====J',
+ ' ##| ###7 L####FJ ##F####F##|##F####F##|#######|##F##7 ##|#####7 ',
+ ' ##| ##| L##FJ ##|L##FJ##|##|L##FJ##|##F==##|##|L##7##|##F==J ',
+ ' L######FJ ##| ##| L=J ##|##| L=J ##|##| ##|##| L####|#######7',
+ ' L=====J L=J L=J L=JL=J L=JL=J L=JL=J L===JL======J'
+ )
+ $tones = @(@(242, 200, 174), @(234, 188, 160), @(225, 175, 146), @(212, 164, 135), @(198, 153, 124), @(185, 143, 114))
+ Line ''
+ for ($i = 0; $i -lt $art.Count; $i++) {
+ $c = Rgb $tones[$i][0] $tones[$i][1] $tones[$i][2]
+ $sb = New-Object Text.StringBuilder
+ $last = ''
+ foreach ($ch in $art[$i].ToCharArray()) {
+ $s = [string]$ch
+ if ($map.ContainsKey($s)) {
+ $want = if ($s -eq '#') { $c } else { $SH }
+ if ($want -ne $last) { [void]$sb.Append($want); $last = $want }
+ [void]$sb.Append($map[$s])
+ } else { [void]$sb.Append($s) }
+ }
+ Line ($sb.ToString() + $R)
+ }
+ Line ''
+ Line " ${B}Self-host installer$R $F$dot$R ${D}your gym log, on your own machine$R"
+ Line " ${D}No account, no cloud. Your data stays in one folder here.$R"
+ }
- Step 'Checking this machine'
- Ok "Windows, $env:PROCESSOR_ARCHITECTURE"
- if ($admin) { Ok 'Running as administrator' } else { Note 'Not running as administrator: GymMane will start when you log in' }
+ Banner
+
+ Step 'This machine'
+ $os = (Get-CimInstance Win32_OperatingSystem -ErrorAction SilentlyContinue).Caption
+ if (-not $os) { $os = 'Windows' }
+ Ok "$os $D($($env:PROCESSOR_ARCHITECTURE.ToLower()))$R"
+ if ($admin) { Note 'Running as administrator: GymMane starts with Windows' } else { Note "Running as $env:USERNAME, no administrator needed: GymMane starts when you log in" }
$installed = Test-Path $exe
if ($installed) { Ok "GymMane is already installed in $home_" }
if ($installed -and -not $action) {
if ($quiet) { $action = 'update' } else {
- Write-Host ''
+ Line ''
while (-not $action) {
Prompt-Line 'What do you want to do?' '[U]pdate, [r]emove, [c]ancel'
switch ((Read-Host).Trim().ToLower()) {
{ $_ -in '', 'u', 'update' } { $action = 'update' }
{ $_ -in 'r', 'remove' } { $action = 'remove' }
- { $_ -in 'c', 'cancel' } { Write-Host ''; return }
+ { $_ -in 'c', 'cancel' } { Line ''; return }
default { Note 'Type u, r or c.' }
}
}
@@ -96,8 +162,9 @@ function Install-GymMane {
}
if ($action -eq 'remove') {
- Write-Host ''
- if (-not $quiet -and -not (YesNo "Remove GymMane? Your data stays in $data" $false)) { Write-Host ''; return }
+ $script:steps = 2
+ Line ''
+ if (-not $quiet -and -not (YesNo "Remove GymMane? Your data stays in $data" $false)) { Line ''; return }
Step 'Removing GymMane'
Unregister-ScheduledTask -TaskName 'GymMane' -Confirm:$false -ErrorAction SilentlyContinue
Get-Process gymmane-server -ErrorAction SilentlyContinue | Stop-Process -Force
@@ -105,16 +172,18 @@ function Install-GymMane {
if ($admin) { Remove-NetFirewallRule -DisplayName 'GymMane' -ErrorAction SilentlyContinue }
Remove-Item -Recurse -Force (Join-Path $home_ 'web'), $exe, (Join-Path $home_ 'run.cmd'), (Join-Path $home_ 'start.bat') -ErrorAction SilentlyContinue
Ok 'Removed the program files'
- Write-Host ''
- Write-Host " Your data is still in $data. Delete that folder yourself if you want it gone."
- Write-Host ''
+ Line ''
+ Line " Your data is still in $B$data$R. Delete that folder yourself if you want it gone."
+ Line ''
return
}
$update = $action -eq 'update'
$oldPort = EnvValue 'GYMMANE_PORT'
$port = if ($env:GYMMANE_PORT) { $env:GYMMANE_PORT } elseif ($oldPort) { $oldPort } else { '8080' }
- Write-Host ''
+
+ Step 'Settings'
+ if ($update) { Ok 'Keeping your port, password and data' } elseif (-not $quiet) { Note 'Press Enter to keep the value in grey.'; Line '' }
if (-not $update -and -not $env:GYMMANE_PORT) {
while ($true) {
$p = Ask 'Port to open GymMane on' $port
@@ -134,7 +203,7 @@ function Install-GymMane {
$pass = ''
if (-not $quiet) {
while ($true) {
- $p = Secret 'Password (press Enter to make one up for you)'
+ $p = Secret 'Password, or Enter to make one up'
if (-not $p) { break }
if (ValidPassword $p) { $pass = $p; break }
Note '8 or more characters: letters, digits and . _ @ % + = ! ? ~ ^ : , / -'
@@ -152,14 +221,19 @@ function Install-GymMane {
$openPort = $false
if ($admin) { $openPort = YesNo "Open port $port in Windows Firewall so other devices can reach it?" $true }
- Write-Host ''
- Write-Host $(if ($update) { ' Ready to update' } else { ' Ready to install' }) -ForegroundColor White
- Write-Host " Folder $home_"
- Write-Host " Starts $(if ($admin) { 'with Windows' } else { 'when you log in' })"
- Write-Host " Port $port"
- Write-Host " Password $(if ($pass) { 'yes' } else { 'no' })"
- Write-Host ''
- if (-not (YesNo 'Go ahead?' $true)) { Write-Host ''; return }
+ $starts = if ($admin) { 'starts with Windows' } else { 'starts when you log in' }
+ BoxFit @($home_, $starts)
+ Line ''
+ BoxTop
+ if ($update) { BoxRow 'Ready to update' "${B}Ready to update$R" } else { BoxRow 'Ready to install' "${B}Ready to install$R" }
+ BoxRow ''
+ BoxPair 'Folder' $home_
+ BoxPair 'Runs with' $starts
+ BoxPair 'Port' $port
+ BoxPair 'Password' $(if ($pass) { 'yes' } else { 'no, open to your network' })
+ BoxBottom
+ Line ''
+ if (-not (YesNo 'Go ahead?' $true)) { Line ''; return }
$extra = @()
if (Test-Path $envFile) {
@@ -172,12 +246,14 @@ function Install-GymMane {
try {
if ($env:GYMMANE_ARCHIVE) {
Expand-Archive $env:GYMMANE_ARCHIVE -DestinationPath $tmp -Force
- Ok "Unpacked $env:GYMMANE_ARCHIVE"
+ Ok "Unpacked $(Split-Path $env:GYMMANE_ARCHIVE -Leaf)"
} else {
$zip = Join-Path $tmp 'gymmane.zip'
+ Spinner 0 'Downloading gymmane-selfhost-windows-x64.zip'
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
try { Invoke-WebRequest -UseBasicParsing "https://github.com/$repo/releases/latest/download/gymmane-selfhost-windows-x64.zip" -OutFile $zip }
- catch { throw 'Could not download GymMane from the latest release. Check the internet connection and try again.' }
+ catch { Unspin; throw 'Could not download GymMane from the latest release. Check the internet connection and try again.' }
+ Unspin
Expand-Archive $zip -DestinationPath $tmp -Force
Ok 'Downloaded gymmane-selfhost-windows-x64.zip'
}
@@ -215,7 +291,7 @@ function Install-GymMane {
Register-ScheduledTask -TaskName 'GymMane' -Action $taskAction -Trigger $trigger -Settings $settings -Force | Out-Null
}
Start-ScheduledTask -TaskName 'GymMane'
- Ok $(if ($admin) { 'Started GymMane, it starts again with Windows' } else { 'Started GymMane, it starts again when you log in' })
+ Ok "Started GymMane, it $starts"
if ($openPort) {
Remove-NetFirewallRule -DisplayName 'GymMane' -ErrorAction SilentlyContinue
@@ -224,41 +300,53 @@ function Install-GymMane {
}
$up = $false
- for ($i = 0; $i -lt 30; $i++) {
- if (Healthy $port $pass) { $up = $true; break }
- Start-Sleep -Seconds 1
+ for ($i = 0; $i -lt 60; $i++) {
+ Spinner $i 'Waiting for GymMane to answer'
+ if (($i % 2 -eq 0) -and (Healthy $port $pass)) { $up = $true; break }
+ Start-Sleep -Milliseconds 500
}
+ Unspin
if ($up) { Ok "GymMane answers on port $port" } else { Warn "GymMane is not answering yet. See what it says in $home_\gymmane.log" }
- Write-Host ''
- Write-Host ' GymMane is ready.' -ForegroundColor Green -NoNewline
- Write-Host ' Open it from any device on your network:'
- Write-Host " http://localhost:$port" -ForegroundColor DarkYellow
+ $links = @("http://localhost:$port")
+ $real = @(Get-NetAdapter -ErrorAction SilentlyContinue | Where-Object { $_.Status -eq 'Up' -and $_.InterfaceDescription -notmatch 'VirtualBox|VMware|Hyper-V|WSL|TAP|Loopback' } | ForEach-Object { $_.ifIndex })
Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue |
- Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' } |
- ForEach-Object { Write-Host " http://$($_.IPAddress):$port" -ForegroundColor DarkYellow }
+ Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' -and ($real.Count -eq 0 -or $real -contains $_.InterfaceIndex) } |
+ ForEach-Object { $links += "http://$($_.IPAddress):$port" }
+ $script:boxW = 52
+ BoxFit $links
+ if ($generated) { BoxFit @("$pass (any user name works)") }
+
+ Line ''
+ BoxTop
+ if ($up) { BoxRow "+ GymMane is running" "$G$tick$R ${B}GymMane is running$R" } else { BoxRow 'GymMane is installed' "${B}GymMane is installed$R" }
+ BoxRow ''
+ BoxRow 'Open it from any device on your network:' "${D}Open it from any device on your network:$R"
+ foreach ($l in $links) { BoxRow " $l" " $A$B$l$R" }
if ($pass) {
- Write-Host ''
+ BoxRow ''
if ($generated) {
- Write-Host ' Password ' -NoNewline; Write-Host $pass -ForegroundColor White -NoNewline; Write-Host ' (made up for you, any user name works)' -ForegroundColor DarkGray
+ BoxPair 'Password' $pass
+ BoxRow ' made up for you, any user name works' " ${D}made up for you, any user name works$R"
} else {
- Write-Host ' Password the one you chose ' -NoNewline; Write-Host '(any user name works)' -ForegroundColor DarkGray
+ BoxPair 'Password' 'the one you chose'
}
}
+ BoxBottom
if (-not $admin) {
- Write-Host ''
- Write-Host ' Run this as administrator to start it with Windows and open the firewall port.' -ForegroundColor DarkGray
+ Line ''
+ Line " ${D}Run this as administrator to start it with Windows and open the firewall port.$R"
}
- Write-Host ''
- Write-Host " Data $data" -ForegroundColor DarkGray
- Write-Host " Settings $envFile" -ForegroundColor DarkGray
- Write-Host " Logs $home_\gymmane.log" -ForegroundColor DarkGray
- Write-Host ' Update run this command again' -ForegroundColor DarkGray
- Write-Host ''
+ Line ''
+ Line " ${D}Data $R$data"
+ Line " ${D}Settings $R$envFile"
+ Line " ${D}Logs $R$home_\gymmane.log"
+ Line " ${D}Update ${R}run this command again"
+ Line ''
}
try { Install-GymMane } catch {
Write-Host ''
- Write-Host " x $($_.Exception.Message)" -ForegroundColor Red
+ Write-Host " x $($_.Exception.Message)" -ForegroundColor Red
Write-Host ''
}
diff --git a/selfhost/install.sh b/selfhost/install.sh
index 651a098..b81434a 100644
--- a/selfhost/install.sh
+++ b/selfhost/install.sh
@@ -3,6 +3,7 @@ set -eu
REPO="InlitX/GymMane"
RAW="https://raw.githubusercontent.com/$REPO/main"
+IMAGE="ghcr.io/inlitx/gymmane"
MODE=""
SYNC=""
ACTION=""
@@ -33,32 +34,151 @@ for arg in "$@"; do
esac
done
-if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
+UTF=0
+case "${LC_ALL:-${LC_CTYPE:-${LANG:-}}}" in
+ *UTF-8*|*utf-8*|*UTF8*|*utf8*) UTF=1 ;;
+esac
+
+COLOR=0
+if [ -t 1 ] && [ -z "${NO_COLOR:-}" ] && [ "${TERM:-}" != dumb ]; then COLOR=1; fi
+
+if [ "$COLOR" = 1 ]; then
esc=$(printf '\033')
- B="$esc[1m"; D="$esc[2m"; R="$esc[0m"
- A="$esc[38;5;180m"; G="$esc[32m"; Y="$esc[33m"; E="$esc[31m"
+ R="$esc[0m"; B="$esc[1m"
+ case "${COLORTERM:-}" in
+ truecolor|24bit)
+ A="$esc[38;2;217;161;132m"; S2="$esc[38;2;185;143;114m"; G="$esc[38;2;143;181;140m"
+ D="$esc[38;2;128;128;128m"; F="$esc[38;2;80;80;80m"; Y="$esc[38;2;230;190;110m"; E="$esc[38;2;230;120;110m"
+ SH="$esc[38;2;96;78;66m"
+ L1="$esc[38;2;242;200;174m"; L2="$esc[38;2;234;188;160m"; L3="$esc[38;2;225;175;146m"
+ L4="$esc[38;2;212;164;135m"; L5="$esc[38;2;198;153;124m"; L6="$esc[38;2;185;143;114m" ;;
+ *)
+ A="$esc[38;5;180m"; S2="$esc[38;5;137m"; G="$esc[38;5;108m"
+ D="$esc[38;5;244m"; F="$esc[38;5;239m"; Y="$esc[38;5;179m"; E="$esc[38;5;167m"
+ SH="$esc[38;5;95m"
+ L1="$esc[38;5;223m"; L2="$esc[38;5;216m"; L3="$esc[38;5;180m"
+ L4="$esc[38;5;180m"; L5="$esc[38;5;173m"; L6="$esc[38;5;137m" ;;
+ esac
+ HIDE="$esc[?25l"; SHOW="$esc[?25h"; CLR="$(printf '\r')$esc[K"
else
- B=""; D=""; R=""; A=""; G=""; Y=""; E=""
+ R=""; B=""; A=""; S2=""; G=""; D=""; F=""; Y=""; E=""; SH=""
+ L1=""; L2=""; L3=""; L4=""; L5=""; L6=""; HIDE=""; SHOW=""; CLR=""
+fi
+
+if [ "$UTF" = 1 ]; then
+ TICK="✓"; CROSS="✗"; DOT="·"; BUL="›"; WARN="!"
+ TL="╭"; TR="╮"; BL="╰"; BR="╯"; HZ="─"; VT="│"
+else
+ TICK="+"; CROSS="x"; DOT="-"; BUL=">"; WARN="!"
+ TL="+"; TR="+"; BL="+"; BR="+"; HZ="-"; VT="|"
fi
-case "${LC_ALL:-${LC_CTYPE:-${LANG:-}}}" in
- *UTF-8*|*utf-8*|*UTF8*|*utf8*) TICK="✓"; CROSS="✗"; ARROW="›"; DOT="•" ;;
- *) TICK="+"; CROSS="x"; ARROW=">"; DOT="-" ;;
-esac
TTY=0
if [ "$YES" = 0 ] && (: </dev/tty) 2>/dev/null; then TTY=1; fi
+STEP=0
+STEPS=4
+LOGF=$(mktemp 2>/dev/null || echo "/tmp/gymmane-install.$$")
+TMPD=""
+cleanup() {
+ rc=$?
+ printf '%s' "$SHOW"
+ stty echo </dev/tty 2>/dev/null || true
+ rm -f "$LOGF"
+ [ -z "$TMPD" ] || rm -rf "$TMPD"
+ exit "$rc"
+}
+trap cleanup EXIT
+trap 'exit 130' INT TERM
+
say() { printf '%s\n' "$*"; }
have() { command -v "$1" >/dev/null 2>&1; }
-step() { printf '\n %s%s%s %s%s%s\n' "$A" "$ARROW" "$R" "$B" "$*" "$R"; }
-ok() { printf ' %s%s%s %s\n' "$G" "$TICK" "$R" "$*"; }
-note() { printf ' %s%s %s%s\n' "$D" "$DOT" "$*" "$R"; }
-warn() { printf ' %s!%s %s\n' "$Y" "$R" "$*"; }
-die() { printf '\n %s%s %s%s\n\n' "$E" "$CROSS" "$*" "$R" >&2; exit 1; }
+step() {
+ STEP=$((STEP + 1))
+ printf '\n %s%s%s%s%s/%s%s %s%s%s\n\n' "$A" "$B" "$STEP" "$R" "$F" "$STEPS" "$R" "$B" "$*" "$R"
+}
+ok() { printf ' %s%s%s %s\n' "$G" "$TICK" "$R" "$*"; }
+note() { printf ' %s%s %s%s\n' "$D" "$DOT" "$*" "$R"; }
+warn() { printf ' %s%s%s %s\n' "$Y" "$WARN" "$R" "$*"; }
+die() {
+ printf '%s' "$CLR"
+ printf '\n %s%s %s%s\n\n' "$E" "$CROSS" "$*" "$R" >&2
+ exit 1
+}
+
+rule() {
+ n=$1; out=""
+ while [ "$n" -gt 0 ]; do out="$out$HZ"; n=$((n - 1)); done
+ printf '%s' "$out"
+}
+
+BOXW=52
+box_top() { printf ' %s%s%s%s%s\n' "$F" "$TL" "$(rule $((BOXW + 2)))" "$TR" "$R"; }
+box_bottom() { printf ' %s%s%s%s%s\n' "$F" "$BL" "$(rule $((BOXW + 2)))" "$BR" "$R"; }
+box_row() {
+ plain=$1; styled=${2:-$1}
+ pad=$((BOXW - ${#plain}))
+ [ "$pad" -ge 0 ] || pad=0
+ sp=""
+ while [ "$pad" -gt 0 ]; do sp="$sp "; pad=$((pad - 1)); done
+ printf ' %s%s%s %s%s %s%s%s\n' "$F" "$VT" "$R" "$styled" "$sp" "$F" "$VT" "$R"
+}
+box_pair() {
+ label=$1; value=$2
+ box_row "$(printf '%-11s%s' "$label" "$value")" "$(printf '%s%-11s%s%s' "$D" "$label" "$R" "$value")"
+}
+box_fit() {
+ for v in "$@"; do
+ w=$((${#v} + 11))
+ [ "$w" -le "$BOXW" ] || BOXW=$w
+ done
+}
+
+frame() {
+ if [ "$UTF" = 1 ]; then
+ case $1 in
+ 0) f="⠋" ;; 1) f="⠙" ;; 2) f="⠹" ;; 3) f="⠸" ;; 4) f="⠼" ;;
+ 5) f="⠴" ;; 6) f="⠦" ;; 7) f="⠧" ;; 8) f="⠇" ;; *) f="⠏" ;;
+ esac
+ else
+ case $(($1 % 4)) in 0) f="|" ;; 1) f="/" ;; 2) f="-" ;; *) f="\\" ;; esac
+ fi
+ printf '%s' "$f"
+}
+
+tick() { sleep 0.1 2>/dev/null || sleep 1; }
+
+run() {
+ msg=$1; shift
+ : >"$LOGF"
+ if [ "$COLOR" = 0 ]; then
+ note "$msg"
+ "$@" >"$LOGF" 2>&1
+ return
+ fi
+ "$@" >"$LOGF" 2>&1 &
+ pid=$!
+ i=0
+ printf '%s' "$HIDE"
+ while kill -0 "$pid" 2>/dev/null; do
+ printf '%s %s%s%s %s%s%s' "$CLR" "$A" "$(frame $((i % 10)))" "$R" "$D" "$msg" "$R"
+ i=$((i + 1))
+ tick
+ done
+ rc=0
+ wait "$pid" || rc=$?
+ printf '%s%s' "$CLR" "$SHOW"
+ return "$rc"
+}
+
+show_log() {
+ [ -s "$LOGF" ] || return 0
+ tail -n 6 "$LOGF" | while IFS= read -r l; do printf ' %s%s%s\n' "$D" "$l" "$R"; done
+}
ask() {
if [ "$TTY" = 0 ]; then REPLY=$2; return 0; fi
- printf ' %s?%s %s %s(%s)%s ' "$A" "$R" "$1" "$D" "$2" "$R"
+ printf ' %s?%s %s %s%s%s %s%s%s ' "$A" "$R" "$1" "$F" "$2" "$R" "$A" "$BUL" "$R"
IFS= read -r REPLY </dev/tty || REPLY=""
[ -n "$REPLY" ] || REPLY=$2
}
@@ -67,7 +187,7 @@ yes_no() {
if [ "$TTY" = 0 ]; then [ "$2" = y ]; return; fi
if [ "$2" = y ]; then hint="Y/n"; else hint="y/N"; fi
while :; do
- printf ' %s?%s %s %s[%s]%s ' "$A" "$R" "$1" "$D" "$hint" "$R"
+ printf ' %s?%s %s %s%s%s %s%s%s ' "$A" "$R" "$1" "$F" "$hint" "$R" "$A" "$BUL" "$R"
IFS= read -r answer </dev/tty || answer=""
[ -n "$answer" ] || answer=$2
case "$answer" in
@@ -79,18 +199,31 @@ yes_no() {
}
secret() {
- printf ' %s?%s %s ' "$A" "$R" "$1"
+ printf ' %s?%s %s %s%s%s ' "$A" "$R" "$1" "$A" "$BUL" "$R"
stty -echo </dev/tty 2>/dev/null || true
IFS= read -r REPLY </dev/tty || REPLY=""
stty echo </dev/tty 2>/dev/null || true
printf '\n'
}
-trap 'stty echo </dev/tty 2>/dev/null || true' INT TERM
+paint() {
+ printf '%s' "$1" | sed -e "s/█/$2█/g" -e "s/╗/$SH╗/g" -e "s/╝/$SH╝/g" -e "s/║/$SH║/g" \
+ -e "s/═/$SH═/g" -e "s/╔/$SH╔/g" -e "s/╚/$SH╚/g"
+ printf '%s\n' "$R"
+}
banner() {
- printf '\n%s%s' "$A" "$B"
- cat <<'ART'
+ say ""
+ if [ "$UTF" = 1 ]; then
+ paint ' ██████╗ ██╗ ██╗███╗ ███╗███╗ ███╗ █████╗ ███╗ ██╗███████╗' "$L1"
+ paint ' ██╔════╝ ╚██╗ ██╔╝████╗ ████║████╗ ████║██╔══██╗████╗ ██║██╔════╝' "$L2"
+ paint ' ██║ ███╗ ╚████╔╝ ██╔████╔██║██╔████╔██║███████║██╔██╗ ██║█████╗ ' "$L3"
+ paint ' ██║ ██║ ╚██╔╝ ██║╚██╔╝██║██║╚██╔╝██║██╔══██║██║╚██╗██║██╔══╝ ' "$L4"
+ paint ' ╚██████╔╝ ██║ ██║ ╚═╝ ██║██║ ╚═╝ ██║██║ ██║██║ ╚████║███████╗' "$L5"
+ paint ' ╚═════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝' "$L6"
+ else
+ printf '%s' "$A"
+ cat <<'ART'
____ __ __
/ ___|_ _ _ __ ___ | \/ | __ _ _ __ ___
| | _| | | | '_ ` _ \| |\/| |/ _` | '_ \ / _ \
@@ -98,9 +231,11 @@ banner() {
\____|\__, |_| |_| |_|_| |_|\__,_|_| |_|\___|
|___/
ART
- printf '%s' "$R"
- say " ${B}Self-host installer${R}"
- say " ${D}The whole app in your browser. Your data stays on this machine.${R}"
+ printf '%s' "$R"
+ fi
+ say ""
+ say " ${B}Self-host installer${R} ${F}${DOT}${R} ${D}your gym log, on your own machine${R}"
+ say " ${D}No account, no cloud. Your data stays in one folder here.${R}"
}
fetch() {
@@ -113,7 +248,7 @@ env_value() {
}
random_password() {
- LC_ALL=C tr -dc 'A-Za-z0-9' </dev/urandom 2>/dev/null | head -c 16 || date +%s | sha256sum | head -c 16
+ LC_ALL=C tr -dc 'A-HJ-NP-Za-km-z2-9' </dev/urandom 2>/dev/null | head -c 16 || date +%s | sha256sum | head -c 16
}
valid_password() {
@@ -123,8 +258,7 @@ valid_password() {
[ "${#1}" -ge 8 ]
}
-addresses() {
- printf ' %s%shttp://localhost:%s%s\n' "$A" "$B" "$PORT" "$R"
+lan_ips() {
ips=""
if [ "$OS" = linux ]; then
ips=$(hostname -I 2>/dev/null || true)
@@ -134,9 +268,11 @@ addresses() {
elif [ "$OS" = macos ]; then
for i in en0 en1; do ips="$ips $(ipconfig getifaddr "$i" 2>/dev/null || true)"; done
fi
+ out=""
for ip in $ips; do
- case "$ip" in *:*) ;; *) printf ' %s%shttp://%s:%s%s\n' "$A" "$B" "$ip" "$PORT" "$R" ;; esac
+ case "$ip" in *:*|172.17.*|172.18.*|172.19.*) ;; *) out="$out $ip" ;; esac
done
+ printf '%s' "$out"
}
firewall() {
@@ -173,17 +309,26 @@ healthy() {
fi
}
-wait_healthy() {
- i=0
- while [ "$i" -lt 30 ]; do
+wait_loop() {
+ n=0
+ while [ "$n" -lt 30 ]; do
rc=0
healthy || rc=$?
- if [ "$rc" = 0 ]; then ok "GymMane answers on port $PORT"; return 0; fi
- if [ "$rc" = 2 ]; then return 0; fi
- i=$((i + 1))
+ [ "$rc" = 0 ] && return 0
+ [ "$rc" = 2 ] && return 0
+ n=$((n + 1))
sleep 1
done
- warn "GymMane is not answering yet. See what it says with: $LOGS"
+ return 1
+}
+
+wait_healthy() {
+ if run "Waiting for GymMane to answer" wait_loop; then
+ ok "GymMane answers on port $PORT"
+ UP=1
+ else
+ warn "GymMane is not answering yet. See what it says with: $LOGS"
+ fi
}
if [ "$(id -u)" = 0 ]; then ROOT=1; HOME_DIR="${GYMMANE_HOME:-/opt/gymmane}"
@@ -199,6 +344,12 @@ case "$(uname -m)" in
aarch64|arm64) ARCH=arm64 ;;
*) ARCH="$(uname -m)" ;;
esac
+if [ "$OS" = linux ] && [ -r /etc/os-release ]; then
+ distro=$(. /etc/os-release && printf '%s' "${PRETTY_NAME:-}")
+ [ -z "$distro" ] || OS_NAME="$distro"
+elif [ "$OS" = macos ] && have sw_vers; then
+ OS_NAME="macOS $(sw_vers -productVersion 2>/dev/null || true)"
+fi
if [ "$ROOT" = 1 ]; then SYSTEMCTL="systemctl"; JOURNAL="journalctl -u gymmane -f"
else SYSTEMCTL="systemctl --user"; JOURNAL="journalctl --user -u gymmane -f"; fi
@@ -211,12 +362,16 @@ else PLIST="$HOME/Library/LaunchAgents/com.gymmane.server.plist"; fi
banner
-step "Checking this machine"
-ok "$OS_NAME, $ARCH"
+step "This machine"
+ok "$OS_NAME ${D}($ARCH)${R}"
+if [ "$ROOT" = 1 ]; then note "Running as root: GymMane goes to $HOME_DIR as a system service"
+else note "Running as $(id -un), no root needed: GymMane goes to $HOME_DIR"; fi
DOCKER=0
if have docker; then
- if docker info >/dev/null 2>&1; then DOCKER=1; ok "Docker is running"
- else note "Docker is installed but not usable by this user (try sudo, or join the docker group)"; fi
+ if docker info >/dev/null 2>&1; then
+ DOCKER=1
+ ok "Docker $(docker version --format '{{.Server.Version}}' 2>/dev/null || true) is running"
+ else note "Docker is here but this user cannot use it (sudo, or the docker group)"; fi
else
note "No Docker here, the standalone server will be used"
fi
@@ -232,7 +387,7 @@ if [ "$INSTALLED" = 1 ] && [ -z "$ACTION" ]; then
if [ "$TTY" = 1 ]; then
say ""
while [ -z "$ACTION" ]; do
- printf ' %s?%s What do you want to do? %s[U]pdate, [r]emove, [c]ancel%s ' "$A" "$R" "$D" "$R"
+ printf ' %s?%s What do you want to do? %s[U]pdate, [r]emove, [c]ancel%s %s%s%s ' "$A" "$R" "$F" "$R" "$A" "$BUL" "$R"
IFS= read -r answer </dev/tty || answer=""
case "$answer" in
""|u|U|update) ACTION=update ;;
@@ -247,6 +402,7 @@ if [ "$INSTALLED" = 1 ] && [ -z "$ACTION" ]; then
fi
if [ "$ACTION" = uninstall ]; then
+ STEPS=2
say ""
if [ "$TTY" = 1 ]; then yes_no "Remove GymMane? Your data stays in $HOME_DIR" n || { say ""; exit 0; }; fi
step "Removing GymMane"
@@ -282,7 +438,9 @@ if [ "$ACTION" = update ]; then
[ -n "$SYNC" ] || SYNC=0
fi
-say ""
+step "Settings"
+if [ "$ACTION" = update ]; then ok "Keeping your port, password and data"
+elif [ "$TTY" = 1 ]; then note "Press Enter to keep the value in grey."; say ""; fi
if [ -z "$MODE" ]; then
if [ "$DOCKER" = 1 ] && yes_no "Docker is available. Run GymMane in Docker?" y; then MODE=docker; else MODE=binary; fi
fi
@@ -316,7 +474,7 @@ elif yes_no "Ask for a password in the browser?" y; then
PASS=""
if [ "$TTY" = 1 ]; then
while :; do
- secret "Password (press Enter to make one up for you)"
+ secret "Password, or Enter to make one up"
[ -n "$REPLY" ] || break
if valid_password "$REPLY"; then PASS=$REPLY; break; fi
note "8 or more characters: letters, digits and . _ @ % + = ! ? ~ ^ : , / -"
@@ -328,7 +486,7 @@ else
fi
if [ "$MODE" = docker ] && [ -z "$SYNC" ]; then
- if yes_no "Also run Syncthing, to share data with the GymMane phone app?" n; then SYNC=1; else SYNC=0; fi
+ if yes_no "Also run Syncthing, to share data with the phone app?" n; then SYNC=1; else SYNC=0; fi
fi
[ -n "$SYNC" ] || SYNC=0
if [ "$MODE" = binary ] && [ "$SYNC" = 1 ]; then
@@ -346,31 +504,40 @@ if [ "$MODE" = docker ]; then
DATA_DIR="$HOME_DIR/gymmane-data"
LOGS="docker logs -f gymmane"
elif [ "$SYSTEMD" = 1 ]; then
- HOW="standalone server, systemd service"
+ HOW="systemd service"
+ [ "$ROOT" = 1 ] || HOW="systemd service of $(id -un)"
DATA_DIR="$HOME_DIR/data"
LOGS="$JOURNAL"
elif [ "$OS" = macos ]; then
- HOW="standalone server, starts at login"
- [ "$ROOT" = 1 ] && HOW="standalone server, starts with the Mac"
+ HOW="starts when you log in"
+ [ "$ROOT" = 1 ] && HOW="starts with the Mac"
DATA_DIR="$HOME_DIR/data"
LOGS="tail -f $HOME_DIR/gymmane.log"
else
- HOW="standalone server, you start it yourself"
+ HOW="you start it yourself"
DATA_DIR="$HOME_DIR/data"
LOGS="the terminal where you started it"
fi
-say ""
-if [ "$ACTION" = update ]; then say " ${B}Ready to update${R}"; else say " ${B}Ready to install${R}"; fi
-say " Folder $HOME_DIR"
-say " Runs with $HOW"
-say " Port $PORT"
-if [ -n "$PASS" ]; then say " Password yes"; else say " Password no"; fi
+if [ -n "$PASS" ]; then PW_TEXT="yes"; else PW_TEXT="no, open to your network"; fi
+box_fit "$HOME_DIR" "$HOW"
+[ "$TTY" = 0 ] || say ""
+box_top
+if [ "$ACTION" = update ]; then box_row "Ready to update" "${B}Ready to update${R}"
+else box_row "Ready to install" "${B}Ready to install${R}"; fi
+box_row ""
+box_pair "Folder" "$HOME_DIR"
+box_pair "Runs with" "$HOW"
+box_pair "Port" "$PORT"
+box_pair "Password" "$PW_TEXT"
if [ "$MODE" = docker ]; then
- if [ "$SYNC" = 1 ]; then say " Syncthing yes"; else say " Syncthing no"; fi
+ if [ "$SYNC" = 1 ]; then box_pair "Syncthing" "yes"; else box_pair "Syncthing" "no"; fi
+fi
+box_bottom
+if [ "$TTY" = 1 ]; then
+ say ""
+ yes_no "Go ahead?" y || { say ""; exit 0; }
fi
-say ""
-yes_no "Go ahead?" y || { say ""; exit 0; }
mkdir -p "$HOME_DIR"
EXTRA=""
@@ -378,6 +545,9 @@ if [ -f "$HOME_DIR/.env" ]; then
EXTRA=$(grep -E '^GYMMANE_' "$HOME_DIR/.env" | grep -vE '^GYMMANE_(PASSWORD|PORT|DATA|WEB|SYNCTHING)=' || true)
fi
+if [ "$ROOT" = 1 ]; then OWNER="${SUDO_UID:-1000}"; GROUP="${SUDO_GID:-$OWNER}"
+else OWNER=$(id -u); GROUP=$(id -g); fi
+
write_env() {
{
say "GYMMANE_PASSWORD=$PASS"
@@ -387,47 +557,66 @@ write_env() {
say "GYMMANE_WEB=$HOME_DIR/web"
else
say "GYMMANE_SYNCTHING=$SYNC"
+ say "PUID=$OWNER"
+ say "PGID=$GROUP"
fi
if [ -n "$EXTRA" ]; then say "$EXTRA"; fi
} >"$HOME_DIR/.env"
chmod 600 "$HOME_DIR/.env"
}
+docker_up() {
+ if [ "$SYNC" = 1 ]; then compose --profile sync up -d; else compose up -d gymmane; fi
+}
+
+docker_pull() {
+ if [ "$SYNC" = 1 ]; then compose --profile sync pull -q; else compose pull -q gymmane; fi
+}
+
+UP=0
if [ "$MODE" = docker ]; then
step "Installing with Docker"
- fetch "$RAW/compose.yaml" "$HOME_DIR/compose.yaml"
- ok "Downloaded compose.yaml"
+ if [ -n "${GYMMANE_COMPOSE:-}" ]; then cp "$GYMMANE_COMPOSE" "$HOME_DIR/compose.yaml"
+ else fetch "$RAW/compose.yaml" "$HOME_DIR/compose.yaml" || die "Could not download compose.yaml. Check the internet connection and try again."; fi
+ ok "Got compose.yaml"
write_env
ok "Saved the settings in $HOME_DIR/.env"
+ mkdir -p "$DATA_DIR/sync"
+ [ "$SYNC" = 1 ] && mkdir -p "$HOME_DIR/syncthing"
+ if [ "$ROOT" = 1 ]; then
+ chown -R "$OWNER:$GROUP" "$DATA_DIR"
+ [ "$SYNC" = 1 ] && chown -R "$OWNER:$GROUP" "$HOME_DIR/syncthing"
+ fi
cd "$HOME_DIR"
- note "Downloading the image, this can take a minute"
- if [ "$SYNC" = 1 ]; then
- compose --profile sync pull -q || die "Could not download the images. Check the internet connection and try again."
- compose --profile sync up -d >/dev/null 2>&1 || compose --profile sync up -d
+ if run "Downloading the image, this can take a minute" docker_pull; then
+ ok "Downloaded the latest image"
+ elif docker image inspect "$IMAGE:latest" >/dev/null 2>&1; then
+ warn "Could not download a newer image, using the one already here"
else
- compose pull -q gymmane || die "Could not download the GymMane image. Check the internet connection and try again."
- compose up -d gymmane >/dev/null 2>&1 || compose up -d gymmane
+ show_log
+ die "Could not download the GymMane image. Check the internet connection and try again."
fi
- ok "Started the container"
+ run "Starting the container" docker_up || { show_log; die "Docker could not start GymMane."; }
+ ok "Started the container, Docker brings it back after a reboot"
[ "$SYNC" = 1 ] && ok "Started Syncthing"
else
step "Installing the standalone server"
asset="gymmane-selfhost-$OS-$ARCH.tar.gz"
- tmp=$(mktemp -d)
- trap 'rm -rf "$tmp"; stty echo </dev/tty 2>/dev/null || true' EXIT
+ TMPD=$(mktemp -d)
if [ -n "${GYMMANE_ARCHIVE:-}" ]; then
[ -f "$GYMMANE_ARCHIVE" ] || die "$GYMMANE_ARCHIVE does not exist."
- tar -xzf "$GYMMANE_ARCHIVE" -C "$tmp"
- ok "Unpacked $GYMMANE_ARCHIVE"
+ tar -xzf "$GYMMANE_ARCHIVE" -C "$TMPD"
+ ok "Unpacked $(basename "$GYMMANE_ARCHIVE")"
else
- fetch "https://github.com/$REPO/releases/latest/download/$asset" "$tmp/$asset" || die "Could not download $asset from the latest release."
- tar -xzf "$tmp/$asset" -C "$tmp"
+ run "Downloading $asset" fetch "https://github.com/$REPO/releases/latest/download/$asset" "$TMPD/$asset" \
+ || die "Could not download $asset from the latest release."
+ tar -xzf "$TMPD/$asset" -C "$TMPD"
ok "Downloaded $asset"
fi
if [ "$SYSTEMD" = 1 ]; then $SYSTEMCTL stop gymmane.service >/dev/null 2>&1 || true; fi
if [ "$OS" = macos ] && [ -f "$PLIST" ]; then launchctl unload "$PLIST" >/dev/null 2>&1 || true; fi
rm -rf "$HOME_DIR/web"
- cp -R "$tmp/gymmane/." "$HOME_DIR/"
+ cp -R "$TMPD/gymmane/." "$HOME_DIR/"
chmod +x "$HOME_DIR/gymmane-server"
mkdir -p "$DATA_DIR"
[ "$OS" = macos ] && { xattr -d com.apple.quarantine "$HOME_DIR/gymmane-server" 2>/dev/null || true; }
@@ -489,14 +678,36 @@ if [ "$MODE" = docker ] || [ "$SYSTEMD" = 1 ] || [ "$OS" = macos ]; then
wait_healthy
fi
+IPS=$(lan_ips)
+LINKS="http://localhost:$PORT"
+for ip in $IPS; do LINKS="$LINKS http://$ip:$PORT"; done
+BOXW=52
+for l in $LINKS; do box_fit "$l"; done
+if [ "$GENERATED" = 1 ]; then box_fit "$PASS (any user name works)"; fi
+
say ""
-say " ${G}${B}GymMane is ready.${R} Open it from any device on your network:"
-addresses
+box_top
+if [ "$UP" = 1 ] || [ "$MODE" = docker ] || [ "$SYSTEMD" = 1 ] || [ "$OS" = macos ]; then
+ box_row "+ GymMane is running" "${G}${TICK}${R} ${B}GymMane is running${R}"
+ box_row ""
+ box_row "Open it from any device on your network:" "${D}Open it from any device on your network:${R}"
+else
+ box_row "GymMane is installed" "${B}GymMane is installed${R}"
+ box_row ""
+ box_row "Once it runs, open it from any device on your network:" "${D}Once it runs, open it from any device on your network:${R}"
+fi
+for l in $LINKS; do box_row " $l" " ${A}${B}$l${R}"; done
if [ -n "$PASS" ]; then
- say ""
- if [ "$GENERATED" = 1 ]; then say " Password ${B}$PASS${R} ${D}(made up for you, any user name works)${R}"
- else say " Password the one you chose ${D}(any user name works)${R}"; fi
+ box_row ""
+ if [ "$GENERATED" = 1 ]; then
+ box_pair "Password" "$PASS"
+ box_row " made up for you, any user name works" " ${D}made up for you, any user name works${R}"
+ else
+ box_pair "Password" "the one you chose"
+ fi
fi
+box_bottom
+
if [ "$MODE" = binary ] && [ "$SYSTEMD" = 0 ] && [ "$OS" != macos ]; then
say ""
say " Start it with:"
@@ -504,13 +715,13 @@ if [ "$MODE" = binary ] && [ "$SYSTEMD" = 0 ] && [ "$OS" != macos ]; then
fi
if [ "$SYNC" = 1 ]; then
say ""
- say " ${B}Phone sync${R}: open Syncthing at http://<this-machine>:8384, add the folder"
- say " ${B}/var/syncthing/GymMane${R} and share it with your phone. Then, in the phone app,"
- say " choose that folder in Settings › Data & backup › Auto backup."
+ say " ${B}Phone sync${R} ${D}open Syncthing at${R} http://<this-machine>:8384${D}, add the folder${R}"
+ say " /var/syncthing/GymMane ${D}and share it with your phone. Then, in the${R}"
+ say " ${D}phone app, choose it in Settings › Data & backup › Auto backup.${R}"
fi
say ""
-say " ${D}Data $DATA_DIR${R}"
-say " ${D}Settings $HOME_DIR/.env${R}"
-say " ${D}Logs $LOGS${R}"
-say " ${D}Update run this command again${R}"
+say " ${D}Data ${R}$DATA_DIR"
+say " ${D}Settings ${R}$HOME_DIR/.env"
+say " ${D}Logs ${R}$LOGS"
+say " ${D}Update ${R}run this command again"
say ""