Files
imagefind/fnos/cmd/config_callback
T

35 lines
1.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -eu
DATA_ROOT="${TRIM_PKGVAR:-}"
ENABLED="${wizard_direct_access:-false}"
PORT="${wizard_direct_port:-8765}"
unset wizard_direct_access wizard_direct_port
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
}
[ -n "$DATA_ROOT" ] || fail "ImageFind 配置失败:fnOS 未提供应用数据目录。"
case "$ENABLED" in
true|false) ;;
*) fail "ImageFind 配置失败:直接访问开关无效。" ;;
esac
case "$PORT" in
''|*[!0-9]*) fail "ImageFind 配置失败:端口必须是数字。" ;;
esac
[ "$PORT" -ge 1 ] && [ "$PORT" -le 65535 ] || fail "ImageFind 配置失败:端口必须在 165535 之间。"
mkdir -p "$DATA_ROOT"
ACCESS_TEMP="$DATA_ROOT/access.json.tmp.$$"
trap 'rm -f "$ACCESS_TEMP"' EXIT
printf '{"direct_access":{"enabled":%s,"port":%s}}\n' "$ENABLED" "$PORT" >"$ACCESS_TEMP"
chmod 0600 "$ACCESS_TEMP"
mv "$ACCESS_TEMP" "$DATA_ROOT/access.json"
trap - EXIT