mirror of
https://github.com/hotwa/luci-app-openclaw.git
synced 2026-03-31 04:52:33 +00:00
feat(storage): support configurable install root
Add a LuCI install-root input, persist the selected path in UCI, and route install, status, backup, uninstall, and runtime scripts through the configured storage root for new installs. Reference: custom install root flow
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
config openclaw 'main'
|
||||
option enabled '0'
|
||||
option install_root '/opt'
|
||||
option port '18789'
|
||||
option bind 'lan'
|
||||
option token ''
|
||||
|
||||
@@ -10,15 +10,15 @@ EXTRA_HELP=" setup 下载 Node.js 并安装 OpenClaw
|
||||
status_service 显示服务状态
|
||||
restart_gateway 仅重启 Gateway 实例 (不影响 Web PTY)"
|
||||
|
||||
NODE_BASE="/opt/openclaw/node"
|
||||
OC_GLOBAL="/opt/openclaw/global"
|
||||
OC_DATA="/opt/openclaw/data"
|
||||
. /usr/libexec/openclaw-paths.sh
|
||||
oc_load_paths "$OPENCLAW_INSTALL_ROOT"
|
||||
|
||||
# ── OverlayFS 兼容性修复 ──
|
||||
# Docker bind mount (/overlay/upper/opt/docker) 会导致 /opt 不可写
|
||||
# 解决: bind mount upper 层的 /opt 到合并视图的 /opt
|
||||
_oc_fix_opt() {
|
||||
mkdir -p /opt/openclaw/.probe 2>/dev/null && { rmdir /opt/openclaw/.probe 2>/dev/null; return 0; }
|
||||
oc_install_root_uses_opt_workaround "$OPENCLAW_INSTALL_ROOT" || return 0
|
||||
mkdir -p "${OC_ROOT}/.probe" 2>/dev/null && { rmdir "${OC_ROOT}/.probe" 2>/dev/null; return 0; }
|
||||
if [ -d /overlay/upper/opt ]; then
|
||||
mkdir -p /overlay/upper/opt/openclaw 2>/dev/null
|
||||
mount --bind /overlay/upper/opt /opt 2>/dev/null && return 0
|
||||
@@ -306,6 +306,7 @@ HOME="$OC_DATA" \
|
||||
OPENCLAW_HOME="$OC_DATA" \
|
||||
OPENCLAW_STATE_DIR="${OC_DATA}/.openclaw" \
|
||||
OPENCLAW_CONFIG_PATH="$CONFIG_FILE" \
|
||||
OPENCLAW_INSTALL_ROOT="$OPENCLAW_INSTALL_ROOT" \
|
||||
NODE_ICU_DATA="${NODE_BASE}/share/icu" \
|
||||
NODE_BASE="$NODE_BASE" \
|
||||
OC_GLOBAL="$OC_GLOBAL" \
|
||||
@@ -335,6 +336,7 @@ procd_set_param env \
|
||||
OC_CONFIG_PORT="$pty_port" \
|
||||
OC_PTY_TOKEN="$pty_token" \
|
||||
OC_CONFIG_SCRIPT="/usr/share/openclaw/oc-config.sh" \
|
||||
OPENCLAW_INSTALL_ROOT="$OPENCLAW_INSTALL_ROOT" \
|
||||
NODE_ICU_DATA="${NODE_BASE}/share/icu" \
|
||||
NODE_BASE="$NODE_BASE" \
|
||||
OC_GLOBAL="$OC_GLOBAL" \
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
# ============================================================================
|
||||
# luci-app-openclaw — 全局环境变量
|
||||
# 仅在 Node.js 已安装时生效,为 SSH 登录用户提供正确的运行环境
|
||||
# 解决 Issue #42: 统一配置文件路径,避免 /root/.openclaw 与 /opt/openclaw/data/.openclaw 混乱
|
||||
# 解决 Issue #42: 统一配置文件路径,避免 /root/.openclaw 与运行目录混乱
|
||||
# ============================================================================
|
||||
|
||||
NODE_BASE="/opt/openclaw/node"
|
||||
OC_GLOBAL="/opt/openclaw/global"
|
||||
OC_DATA="/opt/openclaw/data"
|
||||
. /usr/libexec/openclaw-paths.sh
|
||||
oc_load_paths "$OPENCLAW_INSTALL_ROOT"
|
||||
|
||||
# 检查 Node.js 是否已安装
|
||||
[ -x "${NODE_BASE}/bin/node" ] || return 0
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
#!/bin/sh
|
||||
# luci-app-openclaw — 首次安装/升级初始化脚本
|
||||
|
||||
CURRENT_INSTALL_ROOT=$(uci -q get openclaw.main.install_root)
|
||||
if [ -z "$CURRENT_INSTALL_ROOT" ]; then
|
||||
uci set openclaw.main.install_root='/opt'
|
||||
uci commit openclaw
|
||||
CURRENT_INSTALL_ROOT='/opt'
|
||||
fi
|
||||
|
||||
. /usr/libexec/openclaw-paths.sh
|
||||
oc_load_paths "$CURRENT_INSTALL_ROOT"
|
||||
|
||||
# ── v1.0.16: 清理错误路径下的配置文件 (Issue #42) ──
|
||||
# 用户在 SSH 中直接运行 openclaw 命令时,可能创建了 /root/.openclaw/ 目录
|
||||
# 需要迁移数据并清理,避免路径混乱
|
||||
if [ -d "/root/.openclaw" ]; then
|
||||
OC_DATA="/opt/openclaw/data"
|
||||
# 迁移 skills 目录 (如果存在且目标不存在)
|
||||
if [ -d "/root/.openclaw/skills" ] && [ ! -d "${OC_DATA}/.openclaw/skills" ]; then
|
||||
mkdir -p "${OC_DATA}/.openclaw"
|
||||
@@ -41,7 +50,7 @@ if ! id openclaw >/dev/null 2>&1; then
|
||||
done
|
||||
# OpenWrt 方式:直接写入 /etc/passwd 和 /etc/shadow
|
||||
if ! grep -q '^openclaw:' /etc/passwd 2>/dev/null; then
|
||||
echo "openclaw:x:${OC_UID}:${OC_GID}:openclaw:/opt/openclaw/data:/bin/false" >> /etc/passwd
|
||||
echo "openclaw:x:${OC_UID}:${OC_GID}:openclaw:${OC_DATA}:/bin/false" >> /etc/passwd
|
||||
fi
|
||||
if ! grep -q '^openclaw:' /etc/shadow 2>/dev/null; then
|
||||
echo 'openclaw:x:0:0:99999:7:::' >> /etc/shadow
|
||||
@@ -53,19 +62,21 @@ fi
|
||||
|
||||
# 创建数据目录
|
||||
# ── OverlayFS 兼容: Docker bind mount 可能导致 /opt 不可写 ──
|
||||
if ! mkdir -p /opt/openclaw/.probe 2>/dev/null; then
|
||||
if [ -d /overlay/upper/opt ]; then
|
||||
mkdir -p /overlay/upper/opt/openclaw 2>/dev/null
|
||||
mount --bind /overlay/upper/opt /opt 2>/dev/null
|
||||
if oc_install_root_uses_opt_workaround "$OPENCLAW_INSTALL_ROOT"; then
|
||||
if ! mkdir -p "${OC_ROOT}/.probe" 2>/dev/null; then
|
||||
if [ -d /overlay/upper/opt ]; then
|
||||
mkdir -p /overlay/upper/opt/openclaw 2>/dev/null
|
||||
mount --bind /overlay/upper/opt /opt 2>/dev/null
|
||||
fi
|
||||
rmdir "${OC_ROOT}/.probe" 2>/dev/null
|
||||
else
|
||||
rmdir "${OC_ROOT}/.probe" 2>/dev/null
|
||||
fi
|
||||
rmdir /opt/openclaw/.probe 2>/dev/null
|
||||
else
|
||||
rmdir /opt/openclaw/.probe 2>/dev/null
|
||||
fi
|
||||
mkdir -p /opt/openclaw/data/.openclaw
|
||||
mkdir -p /opt/openclaw/node
|
||||
mkdir -p /opt/openclaw/global
|
||||
chown -R openclaw:openclaw /opt/openclaw 2>/dev/null || true
|
||||
mkdir -p "${OC_DATA}/.openclaw"
|
||||
mkdir -p "$NODE_BASE"
|
||||
mkdir -p "$OC_GLOBAL"
|
||||
chown -R openclaw:openclaw "$OC_ROOT" 2>/dev/null || true
|
||||
|
||||
# 生成随机 Token (如果尚未设置)
|
||||
CURRENT_TOKEN=$(uci -q get openclaw.main.token)
|
||||
|
||||
Reference in New Issue
Block a user