Files
douyin/fnos/cmd/upgrade_init
T

24 lines
846 B
Bash
Executable File

#!/bin/bash
set -eu
DATA_ROOT="${TRIM_APPDEST_VOL}/@appshare/dy.net"
DB_ROOT="${DATA_ROOT}/db"
DB_FILE="${DB_ROOT}/dy.sqlite"
BACKUP_ROOT="${DB_ROOT}/upgrade-backups"
if [ ! -f "${DB_FILE}" ]; then exit 0; fi
mkdir -p "${BACKUP_ROOT}"
DEST="${BACKUP_ROOT}/fpk-pre-0.2.25-$(date '+%Y%m%d-%H%M%S')"
mkdir -p "${DEST}"
cp -p "${DB_FILE}" "${DEST}/dy.sqlite"
if [ -f "${DB_FILE}-wal" ]; then cp -p "${DB_FILE}-wal" "${DEST}/dy.sqlite-wal"; fi
if [ -f "${DB_FILE}-shm" ]; then cp -p "${DB_FILE}-shm" "${DEST}/dy.sqlite-shm"; fi
if [ -d "${DB_ROOT}/keys" ]; then cp -a "${DB_ROOT}/keys" "${DEST}/keys"; fi
# Avoid GNU find -printf: fnOS releases may provide the BusyBox find implementation.
ls -1dt -- "${BACKUP_ROOT}"/* 2>/dev/null | tail -n +4 | while IFS= read -r backup; do
if [ -d "${backup}" ]; then rm -rf -- "${backup}"; fi
done
exit 0