#!/bin/bash
set -e
echo 'Deploying CMD Agent...'
mkdir -p /opt/xiaoxia-cmd-agent
echo '[encoded data, 9576 characters]' | base64 -d > /opt/xiaoxia-cmd-agent/server.py
systemctl stop xiaoxia-cmd-agent 2>/dev/null || true
sleep 1
systemctl start xiaoxia-cmd-agent 2>/dev/null || nohup python3 /opt/xiaoxia-cmd-agent/server.py > /var/log/xiaoxia-cmd-agent.log 2>&1 &
sleep 2
TOKEN=$(cat /etc/xiaoxia-cmd-agent.token)
echo "TOKEN: $TOKEN"
curl -s -H "Authorization: $TOKEN" http://127.0.0.1:18888/status
echo ''
echo 'DONE'
