#!/usr/bin/env bash

conf=""
CUSTOM_CONFIG_FILENAME="h-manifest.conf"

## 自定义模板
if [[ ! -z $CUSTOM_TEMPLATE ]]; then
    conf+="ADDRESS="
    conf+=$CUSTOM_TEMPLATE
    conf+="\n"
fi

## iCustom 配置 - 矿池地址
if [[ ! -z $CUSTOM_URL ]]; then
    conf+="POOL="
    conf+=$CUSTOM_URL
    conf+="\n"
fi

## 主机名
if [[ ! -z $WORKER_NAME ]]; then
    conf+="WORKER_NAME="
    conf+=$WORKER_NAME
    conf+="\n"
fi

## 自定义名称
if [[ ! -z $CUSTOM_NAME ]]; then
    conf+="CUSTOM_NAME="
    conf+=$CUSTOM_NAME
    conf+="\n"
fi

## 自定义版本
if [[ ! -z $CUSTOM_VERSION ]]; then
    conf+="CUSTOM_VERSION="
    conf+=$CUSTOM_VERSION
    conf+="\n"
fi

## 算法
if [[ ! -z $CUSTOM_ALGO ]]; then
    conf+="CUSTOM_ALGO="
    conf+=$CUSTOM_ALGO
    conf+="\n"
fi

## 自定义日志文件
if [[ ! -z $CUSTOM_LOG_BASENAME ]]; then
    conf+="CUSTOM_LOG_BASENAME="
    conf+=$CUSTOM_LOG_BASENAME
    conf+="\n"
fi

## 自定义配置
# if [[ ! -z $CUSTOM_USER_CONFIG ]]; then
#     conf+="CUSTOM_USER_CONFIG="
#     conf+=$CUSTOM_USER_CONFIG
#     conf+="\n"
# fi


## 自定义配置文件名称
if [[ ! -z $CUSTOM_CONFIG_FILENAME ]]; then
    conf+="CUSTOM_CONFIG_FILENAME="
    conf+=$CUSTOM_CONFIG_FILENAME
fi

echo -e "$conf" > $CUSTOM_CONFIG_FILENAME
