cft0808--edict
166 ่ก
5.9 KiB
Bash
166 ่ก
5.9 KiB
Bash
#!/bin/bash
|
||
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
# ไธ็ๅ
ญ้จ ยท OpenClaw Multi-Agent System ไธ้ฎๅธ่ฝฝ่ๆฌ
|
||
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
set -e
|
||
|
||
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
OC_HOME="$HOME/.openclaw"
|
||
OC_CFG="$OC_HOME/openclaw.json"
|
||
|
||
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; BLUE='\033[0;34m'; NC='\033[0m'
|
||
|
||
banner() {
|
||
echo ""
|
||
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
||
echo -e "${BLUE}โ ๐๏ธ ไธ็ๅ
ญ้จ ยท ๅธ่ฝฝๅๅฏผ โ${NC}"
|
||
echo -e "${BLUE}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
||
echo ""
|
||
}
|
||
|
||
log() { echo -e "${GREEN}โ
$1${NC}"; }
|
||
warn() { echo -e "${YELLOW}โ ๏ธ $1${NC}"; }
|
||
info() { echo -e "${BLUE}โน๏ธ $1${NC}"; }
|
||
|
||
# โโ Step 0: ็กฎ่ฎค โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
check_env() {
|
||
info "ๆฃๆฅ็ฏๅข..."
|
||
if ! command -v python3 &>/dev/null; then
|
||
warn "ๆชๆพๅฐ python3๏ผ่ทณ่ฟๆธ
็้
็ฝฎ้กน"
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${YELLOW}็กฎๅฎ่ฆๅธ่ฝฝใไธ็ๅ
ญ้จใ็ณป็ปๅนถๆธ
็็ธๅ
ณ Agent ๆฐๆฎๅ๏ผ${NC}"
|
||
read -p "(y/N) " -r
|
||
echo
|
||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||
info "ๅทฒๅๆถๅธ่ฝฝ"
|
||
exit 0
|
||
fi
|
||
}
|
||
|
||
# โโ Step 1: ๅๆญขๆญฃๅจ่ฟ่ก็ๆๅก โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
stop_services() {
|
||
info "ๅฐ่ฏๅๆญข็ธๅ
ณ่ฟ็จ..."
|
||
|
||
if pgrep -f "scripts/run_loop.sh" > /dev/null 2>&1; then
|
||
pkill -f "scripts/run_loop.sh" || warn "ๆ ๆณ่ชๅจๅๆญข run_loop.sh"
|
||
log "ๅทฒๅฐ่ฏๅๆญข run_loop.sh"
|
||
fi
|
||
|
||
if pgrep -f "python.*dashboard/server.py" > /dev/null 2>&1; then
|
||
pkill -f "python.*dashboard/server.py" || warn "ๆ ๆณ่ชๅจๅๆญข dashboard/server.py"
|
||
log "ๅทฒๅฐ่ฏๅๆญข dashboard/server.py"
|
||
fi
|
||
}
|
||
|
||
# โโ Step 2: ๆธ
็ OpenClaw ๆณจๅ้
็ฝฎ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
unregister_agents() {
|
||
info "ไป OpenClaw ็งป้คไธ็ๅ
ญ้จ Agents ๆณจๅไฟกๆฏ..."
|
||
|
||
if [ ! -f "$OC_CFG" ]; then
|
||
warn "ๆชๆพๅฐ openclaw.json๏ผ่ทณ่ฟ้
็ฝฎๆธ
็"
|
||
return
|
||
fi
|
||
|
||
cp "$OC_CFG" "$OC_CFG.bak.pre-uninstall-$(date +%Y%m%d-%H%M%S)"
|
||
log "ๅทฒๅคไปฝๅฝๅ้
็ฝฎ"
|
||
|
||
python3 << 'PYEOF'
|
||
import json, pathlib
|
||
|
||
cfg_path = pathlib.Path.home() / '.openclaw' / 'openclaw.json'
|
||
if not cfg_path.exists():
|
||
print(" openclaw.json ไธๅญๅจใ")
|
||
exit(0)
|
||
|
||
try:
|
||
cfg = json.loads(cfg_path.read_text(encoding='utf-8'))
|
||
except Exception as e:
|
||
print(f" ่งฃๆ openclaw.json ๅคฑ่ดฅ: {e}")
|
||
exit(1)
|
||
|
||
AGENTS_TO_REMOVE = {
|
||
"taizi", "zhongshu", "menxia", "shangshu",
|
||
"hubu", "libu", "bingbu", "xingbu", "gongbu",
|
||
"libu_hr", "zaochao"
|
||
}
|
||
|
||
agents_list = cfg.get('agents', {}).get('list', [])
|
||
new_list = [a for a in agents_list if a.get('id') not in AGENTS_TO_REMOVE]
|
||
removed_count = len(agents_list) - len(new_list)
|
||
|
||
if 'agents' in cfg:
|
||
cfg['agents']['list'] = new_list
|
||
cfg_path.write_text(json.dumps(cfg, ensure_ascii=False, indent=2), encoding='utf-8')
|
||
print(f" ๆๅ็งป้คไบ {removed_count} ไธช Agent ็ๆณจๅไฟกๆฏ")
|
||
PYEOF
|
||
|
||
log "ๆณจๅไฟกๆฏๆธ
็ๅฎๆ"
|
||
}
|
||
|
||
# โโ Step 3: ๆธ
้ค Workspace ็ฎๅฝ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
remove_workspaces() {
|
||
info "ๆธ
้ค Agent Workspace ็ฎๅฝ..."
|
||
|
||
AGENTS=(taizi zhongshu menxia shangshu hubu libu bingbu xingbu gongbu libu_hr zaochao)
|
||
removed=0
|
||
for agent in "${AGENTS[@]}"; do
|
||
ws="$OC_HOME/workspace-$agent"
|
||
if [ -d "$ws" ]; then
|
||
rm -rf "$ws"
|
||
removed=$((removed+1))
|
||
fi
|
||
done
|
||
|
||
log "ๆๅๆธ
็ไบ $removed ไธช Workspace ็ฎๅฝ"
|
||
}
|
||
|
||
# โโ Step 4: ๆธ
้คๆฌๅฐๆฐๆฎ็ผๅญ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
remove_data() {
|
||
info "ๆธ
้คๆฌๅฐ data ็ผๅญ..."
|
||
|
||
echo -e "${YELLOW}ๆฏๅฆ้่ฆๅ ้ค้กน็ฎๅ
็ data ็ฎๅฝๅๅทฒ็ๆ็ๆฐๆฎ๏ผ${NC}"
|
||
read -p "(y/N) " -r
|
||
echo
|
||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||
if [ -d "$REPO_DIR/data" ]; then
|
||
rm -rf "$REPO_DIR/data"
|
||
log "ๅทฒๅ ้ค $REPO_DIR/data"
|
||
else
|
||
warn "$REPO_DIR/data ไธๅญๅจ"
|
||
fi
|
||
else
|
||
info "ไฟ็ๅๆ data ็ฎๅฝ"
|
||
fi
|
||
}
|
||
|
||
# โโ Step 5: ้ๅฏ Gateway โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
restart_gateway() {
|
||
info "้ๅฏ OpenClaw Gateway ไปฅๅบ็จ้
็ฝฎ..."
|
||
if command -v openclaw &>/dev/null; then
|
||
if openclaw gateway restart 2>/dev/null; then
|
||
log "Gateway ้ๅฏๆๅ"
|
||
else
|
||
warn "Gateway ้ๅฏๅคฑ่ดฅ๏ผ่ฏทๆๅจ้ๅฏ๏ผopenclaw gateway restart"
|
||
fi
|
||
else
|
||
warn "ๆชๆพๅฐ openclaw ๅฝไปค่กๅทฅๅ
ท๏ผ่ทณ่ฟ้ๅฏ Gateway"
|
||
fi
|
||
}
|
||
|
||
# โโ Main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
||
banner
|
||
check_env
|
||
stop_services
|
||
unregister_agents
|
||
remove_workspaces
|
||
remove_data
|
||
restart_gateway
|
||
|
||
echo ""
|
||
echo -e "${GREEN}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
||
echo -e "${GREEN}โ โ
ไธ็ๅ
ญ้จๅธ่ฝฝๅฎๆ๏ผ โ${NC}"
|
||
echo -e "${GREEN}โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ${NC}"
|
||
echo ""
|