#!/bin/bash
set -e

FTP_SERVER="${FTP_SERVER:-172.30.0.40}"
FTP_USER="${FTP_USER:-ftpuser}"
FTP_PASSWORD="${FTP_PASSWORD:-ZGClab1234!}"
FTP_PORT="${FTP_PORT:-21}"

FTP_HOST="${FTP_SERVER}"

echo "[03] 进入测试节点执行安装..."
echo "[03] 使用 FTP 地址: ${FTP_HOST}:${FTP_PORT}"

docker exec argus-metric-test-node bash -c "
set -e

if ! command -v curl &>/dev/null; then
    echo '[03] curl 未安装，正在安装...'
    apt-get update && apt-get install -y curl
fi

cd /tmp
echo '[03] 下载 setup.sh...'
curl -u ${FTP_USER}:${FTP_PASSWORD} ftp://${FTP_HOST}:${FTP_PORT}/setup.sh -o setup.sh

echo '[03] 执行安装...'
chmod +x setup.sh
bash setup.sh --server ${FTP_HOST} --user ${FTP_USER} --password '${FTP_PASSWORD}' --port ${FTP_PORT}

echo '[03] 安装完成'
"

echo "[03] 完成"
