Files
imagefind/fnos/cmd/uninstall_init
T

39 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -eu
fail() {
MESSAGE="$1"
printf '%s\n' "$MESSAGE" >&2
if [ -n "${TRIM_TEMP_LOGFILE:-}" ]; then
printf '%s\n' "$MESSAGE" >>"$TRIM_TEMP_LOGFILE" 2>/dev/null || true
fi
exit 1
}
case "${wizard_clear_data:-false}" in
1|true|TRUE|yes|YES|on|ON) ;;
*) exit 0 ;;
esac
DATA_ROOT="${TRIM_PKGVAR:-}"
[ -n "$DATA_ROOT" ] || fail "ImageFind 数据清理失败:fnOS 未提供应用数据目录。"
[ -e "$DATA_ROOT" ] || exit 0
[ -d "$DATA_ROOT" ] || fail "ImageFind 数据清理失败:应用数据路径不是目录。"
DATA_ROOT_REAL=$(readlink -f -- "$DATA_ROOT") || fail "ImageFind 数据清理失败:无法解析应用数据路径。"
case "$DATA_ROOT_REAL" in
""|/|/home|/var|/var/apps) fail "ImageFind 数据清理失败:拒绝清理不安全的路径。" ;;
esac
[ "$(dirname -- "$DATA_ROOT_REAL")" != "/" ] || fail "ImageFind 数据清理失败:拒绝清理顶层目录。"
[ -f "$DATA_ROOT_REAL/.imagefind-data-root" ] || fail "ImageFind 数据清理失败:应用数据目录缺少安全标记。"
[ "$(sed -n '1p' "$DATA_ROOT_REAL/.imagefind-data-root")" = "imagefind-data-v1" ] || \
fail "ImageFind 数据清理失败:应用数据目录安全标记无效。"
SCRIPT_ROOT=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
"$SCRIPT_ROOT/main" stop || fail "ImageFind 数据清理失败:无法停止应用服务。"
# Only clear TRIM_PKGVAR. Shared video directories and user-authorized paths
# live outside this directory and are deliberately never traversed here.
find "$DATA_ROOT_REAL" -mindepth 1 -maxdepth 1 -exec rm -rf -- {} + || \
fail "ImageFind 数据清理失败:部分内部数据无法删除。"