Skip to content

Commit 6450bef

Browse files
feat: version-aware auto-update via version.txt
- build.yml now creates and releases version.txt with the tag name - auto-update.sh fetches MIRROR/version.txt and compares to INSTALL_DIR/.version; skips update if versions match - save_installed_version() writes .version after install/update so the baseline is always set
1 parent af604ac commit 6450bef

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ jobs:
8686
merge-multiple: true
8787
path: dist/
8888

89+
- name: Create version.txt
90+
run: echo "${{ inputs.version }}" > dist/version.txt
91+
8992
- name: Create GitHub release
9093
uses: softprops/action-gh-release@v2
9194
with:
@@ -98,4 +101,5 @@ jobs:
98101
dist/installer-linux-x64
99102
dist/installer-linux-arm64
100103
dist/mura.zip
104+
dist/version.txt
101105
install.sh

install.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
336346
def 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
341351
set -e
342352
MIRROR="{mirror}"
343353
ARCH="{arch}"
344354
INSTALL_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"
345368
systemctl stop parley-chat
346369
if 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
354375
fi
355376
chmod +x "$INSTALL_DIR/sova.new"
356377
mv "$INSTALL_DIR/sova.new" "$INSTALL_DIR/sova"
357378
rm -rf "$INSTALL_DIR/mura"
358379
mkdir -p "$INSTALL_DIR/mura"
359380
unzip -q "$INSTALL_DIR/mura.zip" -d "$INSTALL_DIR/mura"
360381
rm "$INSTALL_DIR/mura.zip"
382+
echo "$REMOTE_VERSION" > "$VERSION_FILE"
361383
systemctl 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("\nParley Chat updated successfully.")
559587

0 commit comments

Comments
 (0)