feat: add upgrade and migration flow for native fnOS

This commit is contained in:
2026-10-02 15:49:19 +08:00
parent 57ea2b29f4
commit 27bc5d0353
8 changed files with 214 additions and 9 deletions
+5
View File
@@ -1,9 +1,14 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/migrate_legacy.sh"
mkdir -p "$TRIM_PKGVAR/logs"
chown -R "$TRIM_USERNAME:$TRIM_GROUPNAME" "$TRIM_PKGVAR"
migrate_legacy_data
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH_DIR="amd64" ;;
+37
View File
@@ -0,0 +1,37 @@
#!/bin/bash
set -euo pipefail
migrate_legacy_data() {
local legacy_root="$TRIM_PKGVAR/data"
local legacy_db="$legacy_root/havline.db"
local target_db="$TRIM_PKGVAR/havline.db"
if [ ! -f "$legacy_db" ] || [ -f "$target_db" ]; then
return 0
fi
echo "检测到旧版数据布局:$legacy_root"
mkdir -p "$TRIM_PKGVAR/backups"
for item in "$legacy_root"/* "$legacy_root"/.[!.]* "$legacy_root"/..?*; do
[ -e "$item" ] || continue
local name
name="$(basename "$item")"
if [ -e "$TRIM_PKGVAR/$name" ]; then
continue
fi
mv "$item" "$TRIM_PKGVAR/$name"
done
echo "旧版数据已迁移到:$TRIM_PKGVAR"
}
backup_database() {
local db="$TRIM_PKGVAR/havline.db"
if [ ! -f "$db" ]; then
return 0
fi
mkdir -p "$TRIM_PKGVAR/backups"
cp -f "$db" "$TRIM_PKGVAR/backups/havline-pre-upgrade-$(date +%Y%m%d%H%M%S).db"
}
+6
View File
@@ -1,6 +1,9 @@
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/migrate_legacy.sh"
if [ -f "$TRIM_PKGVAR/havline.db" ] && [ ! -r "$TRIM_PKGVAR/havline.db" ]; then
echo "数据库不可读:$TRIM_PKGVAR/havline.db" > "$TRIM_TEMP_LOGFILE"
exit 1
@@ -11,4 +14,7 @@ if [ -f "$TRIM_PKGVAR/session_secret" ] && [ ! -r "$TRIM_PKGVAR/session_secret"
exit 1
fi
migrate_legacy_data
backup_database
exit 0