From 4ec63f0fe88373ebbf941da20103f0fddf423763 Mon Sep 17 00:00:00 2001 From: xtcnet Date: Tue, 17 Mar 2026 23:16:50 +0700 Subject: [PATCH] feat(install): auto-update install.sh on every run at startup Move self-update logic from do_update() to a self_update() helper called at the entry point before showing the menu or running any command. The script now checks for a newer version on every execution, re-execs with the original arguments if an update is found, and is a no-op if unreachable or already up to date. Co-Authored-By: Claude Sonnet 4.6 --- install.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index a8ab1a8..1e31f06 100644 --- a/install.sh +++ b/install.sh @@ -38,6 +38,24 @@ log_warn() { echo -e "${YELLOW}[!]${NC} $1"; } log_err() { echo -e "${RED}[✗]${NC} $1"; } separator() { echo -e "${GREEN}=================================================================${NC}"; } +self_update() { + local remote_url="https://src.d3v.ac/xtcnet/D3V-Server/raw/branch/master/install.sh" + local tmp + tmp=$(mktemp) || return + if curl -fsSL -m 10 "$remote_url" -o "$tmp" 2>/dev/null; then + if ! cmp -s "$tmp" "$0"; then + log_warn "A newer version of install.sh found. Updating..." + cp "$tmp" "$0" + chmod +x "$0" + rm -f "$tmp" + log_ok "install.sh updated. Restarting..." + exec "$0" "$@" + exit 0 + fi + fi + rm -f "$tmp" +} + require_root() { if [ "$(id -u)" -ne 0 ]; then log_err "This script must be run as root. Use: sudo $0" @@ -420,19 +438,6 @@ do_reset_password() { do_update() { require_root - log_step "Checking for install.sh updates..." - local remote_script_url="https://src.d3v.ac/xtcnet/D3V-Server/raw/branch/master/install.sh" - if ! curl -sSL "$remote_script_url" | cmp -s "$0" -; then - log_warn "A newer version of install.sh is available. Updating script..." - curl -sSL "$remote_script_url" -o "$0" - chmod +x "$0" - log_ok "install.sh updated. Restarting update process..." - exec "$0" update - exit 0 - else - log_ok "install.sh is up to date." - fi - if [ ! -d "$INSTALL_DIR" ]; then log_err "D3V-NPMWG is not installed. Install it first." return @@ -913,6 +918,8 @@ show_help() { # ----------------------------------------------------------- # Entry point # ----------------------------------------------------------- +self_update "$@" + if [ "$#" -eq 0 ]; then show_menu else