Skip to content

Commit e71f8d7

Browse files
Add daily auto-upgrade check to tron CLI (#18)
Adds a once-daily background upgrade check before launching TronBrowser, with TRONBROWSER_AUTO_UPGRADE=0 as an opt-out.
1 parent 5211834 commit e71f8d7

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

apps/web/public/install.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ PREFIX="${TRONBROWSER_PREFIX:-$HOME/.local}"
6666
APP_DIR="$PREFIX/lib/tronbrowser"
6767
CURRENT="$APP_DIR/current"
6868
VERSION_FILE="$APP_DIR/VERSION"
69+
AUTO_UPGRADE_STAMP="$APP_DIR/.last-auto-upgrade-check"
6970
INSTALL_URL="https://tronbrowser.dev/install.sh"
7071
7172
usage() {
@@ -80,11 +81,37 @@ Usage:
8081
tron remove Uninstall TronBrowser (keeps your profile data)
8182
tron version Print the installed version
8283
tron help Show this help
84+
85+
Set TRONBROWSER_AUTO_UPGRADE=0 to skip the once-daily background upgrade check.
8386
USAGE
8487
}
8588
89+
maybe_auto_upgrade() {
90+
case "${TRONBROWSER_AUTO_UPGRADE:-1}" in
91+
0|false|False|FALSE|no|No|NO) return 0 ;;
92+
esac
93+
command -v curl >/dev/null 2>&1 || return 0
94+
[ -d "$APP_DIR" ] || return 0
95+
96+
now="$(date +%s 2>/dev/null || echo 0)"
97+
last="$(cat "$AUTO_UPGRADE_STAMP" 2>/dev/null || echo 0)"
98+
case "$now:$last" in
99+
0:*) return 0 ;;
100+
esac
101+
case "$last" in
102+
''|*[!0-9]*) last=0 ;;
103+
esac
104+
[ "$((now - last))" -lt 86400 ] && return 0
105+
106+
printf '%s\n' "$now" > "$AUTO_UPGRADE_STAMP" 2>/dev/null || return 0
107+
(
108+
TRONBROWSER_AUTO_UPGRADE=0 sh -c "curl -fsSL '$INSTALL_URL' | sh -s -- upgrade"
109+
) >/dev/null 2>&1 &
110+
}
111+
86112
launch() {
87113
[ -x "$CURRENT" ] || { echo "TronBrowser is not installed. Run: curl -fsSL $INSTALL_URL | sh" >&2; exit 1; }
114+
maybe_auto_upgrade
88115
exec "$CURRENT" "$@"
89116
}
90117

0 commit comments

Comments
 (0)