#!/bin/bash
# 安装后回调
chmod +x "${TRIM_APPDEST}/server.py" 2>/dev/null
mkdir -p "${TRIM_PKGVAR}"

# 将 wizard 端口写入 service_port（server.py 读取此文件）
if [ -n "${wizard_service_port}" ]; then
    echo "${wizard_service_port}" > "${TRIM_PKGETC}/service_port"
    # 更新 ui/config 端口，飞牛设置页显示用户端口
    python3 -c "
import json
cfg_path = '${TRIM_APPDEST}/ui/config'
with open(cfg_path) as f:
    cfg = json.load(f)
cfg['.url']['docker-image-import.main']['port'] = '${wizard_service_port}'
with open(cfg_path, 'w') as f:
    json.dump(cfg, f, indent=4)
"
fi

echo "Docker镜像导入工具安装完成。"
exit 0
