#!/usr/bin/env bash

cd `dirname $0`
HOSTNAME=$(hostname)
[[ "$CUSTOM_URL" = "" ]] && echo "Using default address" && CUSTOM_URL="qubic1.hk.apool.io:3334"
if echo "$CUSTOM_USER_CONFIG"|grep nvtool;then
    CUSTOM_NVTOOL=$(echo "$CUSTOM_USER_CONFIG" |head -1)
    CUSTOM_USER_CONFIG=$(echo "$CUSTOM_USER_CONFIG"|grep -v nvtool)
fi
conf=""
conf+="third_miner=\"aleominer\" "$'\n'
conf+="port=5001"$'\n'


conf+="third_cmd=\"./aleominer -u stratum+ssl://xg1.claymore.pub:8031   -w  $CUSTOM_PASS.$HOSTNAME \" "$'\n'
conf+="NVTOOL=\"$CUSTOM_NVTOOL\""$'\n'
conf+="$CUSTOM_USER_CONFIG"$'\n'
conf=`echo "$conf"|sed '/algo=/d'`
conf=`echo "$conf"|sed '/pool=/d'`
conf+=$'\n'
conf+="algo=qubic"$'\n'
conf+="account=$CUSTOM_TEMPLATE"$'\n'
conf+="pool=$CUSTOM_URL"$'\n'
conf+="worker=$HOSTNAME"$'\n'
echo "$conf" > $CUSTOM_CONFIG_FILENAME
