@@ -333,31 +333,53 @@ def write_install_info(install_dir, info):
333333 for k , v in info .items ():
334334 f .write (f"{ k } ={ v } \n " )
335335
336+ def save_installed_version (install_dir , mirror ):
337+ # Fetches version.txt from the mirror and saves it to .version
338+ try :
339+ with urllib .request .urlopen (f"{ mirror } /version.txt" ) as r :
340+ version = r .read ().decode ().strip ()
341+ with open (f"{ install_dir } /.version" , "w" ) as f :
342+ f .write (version + "\n " )
343+ except Exception :
344+ pass
345+
336346def write_auto_update_script (install_dir , mirror , arch ):
337- # Writes a self-contained shell script that downloads and applies updates
347+ # Writes a self-contained shell script that checks for a new version and updates if needed
338348 script_path = f"{ install_dir } /auto-update.sh"
339349 with open (script_path , "w" ) as f :
340350 f .write (f"""#!/bin/bash
341351set -e
342352MIRROR="{ mirror } "
343353ARCH="{ arch } "
344354INSTALL_DIR="{ install_dir } "
355+ VERSION_FILE="$INSTALL_DIR/.version"
356+ if command -v wget &>/dev/null; then
357+ REMOTE_VERSION=$(wget -qO- "$MIRROR/version.txt" 2>/dev/null || true)
358+ elif command -v curl &>/dev/null; then
359+ REMOTE_VERSION=$(curl -fsSL "$MIRROR/version.txt" 2>/dev/null || true)
360+ else
361+ echo "Neither wget nor curl found"; exit 1
362+ fi
363+ LOCAL_VERSION=$(cat "$VERSION_FILE" 2>/dev/null || true)
364+ if [ -z "$REMOTE_VERSION" ] || [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]; then
365+ exit 0
366+ fi
367+ echo "Updating from $LOCAL_VERSION to $REMOTE_VERSION"
345368systemctl stop parley-chat
346369if command -v wget &>/dev/null; then
347370 wget -q -O "$INSTALL_DIR/sova.new" "$MIRROR/sova-linux-$ARCH"
348371 wget -q -O "$INSTALL_DIR/mura.zip" "$MIRROR/mura.zip"
349- elif command -v curl &>/dev/null; then
372+ else
350373 curl -fsSL "$MIRROR/sova-linux-$ARCH" -o "$INSTALL_DIR/sova.new"
351374 curl -fsSL "$MIRROR/mura.zip" -o "$INSTALL_DIR/mura.zip"
352- else
353- echo "Neither wget nor curl found"; exit 1
354375fi
355376chmod +x "$INSTALL_DIR/sova.new"
356377mv "$INSTALL_DIR/sova.new" "$INSTALL_DIR/sova"
357378rm -rf "$INSTALL_DIR/mura"
358379mkdir -p "$INSTALL_DIR/mura"
359380unzip -q "$INSTALL_DIR/mura.zip" -d "$INSTALL_DIR/mura"
360381rm "$INSTALL_DIR/mura.zip"
382+ echo "$REMOTE_VERSION" > "$VERSION_FILE"
361383systemctl start parley-chat
362384""" )
363385 os .chmod (script_path , 0o755 )
@@ -485,6 +507,9 @@ def do_install():
485507
486508 auto_update_schedule = "0 3 * * *"
487509 auto_update_schedule_label = "daily at 3 AM"
510+ if not local :
511+ save_installed_version (install_dir , MIRROR_BASE )
512+
488513 if auto_update :
489514 print (" Setting up auto-update..." )
490515 auto_update_schedule , auto_update_schedule_label = ask_auto_update_schedule ()
@@ -554,6 +579,9 @@ def do_update():
554579 z .extractall (f"{ install_dir } /mura" )
555580 os .remove (mura_zip )
556581
582+ if not local :
583+ save_installed_version (install_dir , MIRROR_BASE )
584+
557585 sysrun (["systemctl" , "start" , "parley-chat" ])
558586 print ("\n Parley Chat updated successfully." )
559587
0 commit comments