69 lines
2.2 KiB
Bash
69 lines
2.2 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
config=/www/dk_project/openclaw/config/openclaw.json
|
|
workspace=/www/dk_project/openclaw/config/workspace-wechat-responder
|
|
timestamp=$(date +%Y%m%d-%H%M%S)
|
|
backup="${config}.bak.wechat-responder-finalize-${timestamp}"
|
|
success=0
|
|
|
|
rollback() {
|
|
status=$?
|
|
if [ "$success" -eq 0 ]; then
|
|
cp -a "$backup" "$config"
|
|
fi
|
|
exit "$status"
|
|
}
|
|
|
|
trap rollback EXIT HUP INT TERM
|
|
|
|
test "$(jq -r '.agents.entries | has("wechat-responder")' "$config")" = true
|
|
test -d "$workspace"
|
|
cp -a "$config" "$backup"
|
|
|
|
install -o 1000 -g 1000 -m 0644 \
|
|
/tmp/wechat-responder-AGENTS.md \
|
|
"$workspace/AGENTS.md"
|
|
install -o 1000 -g 1000 -m 0644 \
|
|
/tmp/wechat-responder-SOUL.md \
|
|
"$workspace/SOUL.md"
|
|
install -o 1000 -g 1000 -m 0644 \
|
|
/tmp/wechat-responder-IDENTITY.md \
|
|
"$workspace/IDENTITY.md"
|
|
install -o 1000 -g 1000 -m 0644 \
|
|
/tmp/wechat-responder-USER.md \
|
|
"$workspace/USER.md"
|
|
rm -f "$workspace/BOOTSTRAP.md"
|
|
|
|
temporary="${config}.wechat-responder.tmp"
|
|
jq '
|
|
.agents.entries["wechat-responder"].name = "WeChat Tool-Free Chat"
|
|
| .agents.entries["wechat-responder"].thinkingDefault = "off"
|
|
| del(.agents.entries["wechat-responder"].timeoutSeconds)
|
|
| .agents.entries["wechat-responder"].skills = []
|
|
| .agents.entries["wechat-responder"].tools = {
|
|
"profile": "minimal",
|
|
"allow": ["session_status"],
|
|
"codeMode": false
|
|
}
|
|
' "$config" > "$temporary"
|
|
chown --reference="$config" "$temporary"
|
|
chmod --reference="$config" "$temporary"
|
|
mv "$temporary" "$config"
|
|
|
|
sleep 3
|
|
test "$(jq -r '.agents.entries | ."wechat-responder" | .tools.profile' "$config")" = minimal
|
|
test "$(jq -r '.agents.entries | ."wechat-responder" | .tools.allow | join(",")' "$config")" = session_status
|
|
test "$(jq -r '.agents.entries | ."wechat-responder" | .tools.codeMode' "$config")" = false
|
|
test "$(jq -r '.agents.entries | ."wechat-responder" | .skills | length' "$config")" -eq 0
|
|
test "$(jq -r '.agents.entries | ."wechat-responder" | has("timeoutSeconds")' "$config")" = false
|
|
test ! -e "$workspace/BOOTSTRAP.md"
|
|
test "$(wc -c < "$workspace/AGENTS.md")" -lt 2000
|
|
|
|
success=1
|
|
trap - EXIT HUP INT TERM
|
|
|
|
echo "backup=$backup"
|
|
jq -c '.agents.entries | ."wechat-responder"' "$config"
|
|
find "$workspace" -maxdepth 1 -type f -printf "%f %s bytes\n" | sort
|