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 <noreply@anthropic.com>
This commit is contained in:
parent
c8801b97c6
commit
4ec63f0fe8
1 changed files with 20 additions and 13 deletions
33
install.sh
33
install.sh
|
|
@ -38,6 +38,24 @@ log_warn() { echo -e "${YELLOW}[!]${NC} $1"; }
|
||||||
log_err() { echo -e "${RED}[✗]${NC} $1"; }
|
log_err() { echo -e "${RED}[✗]${NC} $1"; }
|
||||||
separator() { echo -e "${GREEN}=================================================================${NC}"; }
|
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() {
|
require_root() {
|
||||||
if [ "$(id -u)" -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
log_err "This script must be run as root. Use: sudo $0"
|
log_err "This script must be run as root. Use: sudo $0"
|
||||||
|
|
@ -420,19 +438,6 @@ do_reset_password() {
|
||||||
do_update() {
|
do_update() {
|
||||||
require_root
|
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
|
if [ ! -d "$INSTALL_DIR" ]; then
|
||||||
log_err "D3V-NPMWG is not installed. Install it first."
|
log_err "D3V-NPMWG is not installed. Install it first."
|
||||||
return
|
return
|
||||||
|
|
@ -913,6 +918,8 @@ show_help() {
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
# Entry point
|
# Entry point
|
||||||
# -----------------------------------------------------------
|
# -----------------------------------------------------------
|
||||||
|
self_update "$@"
|
||||||
|
|
||||||
if [ "$#" -eq 0 ]; then
|
if [ "$#" -eq 0 ]; then
|
||||||
show_menu
|
show_menu
|
||||||
else
|
else
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue