#!/bin/bash

#docker环境安装
get_distribution() {
        lsb_dist=""
        if [ -r /etc/os-release ]; then
			lsb_dist="$(. /etc/os-release && echo "$ID")"
        fi
        echo "$lsb_dist"
}
install_docker(){
	lsb_dist=$( get_distribution )
	lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
	who=`whoami`
	if [ $who == "root" ];then
		case "$lsb_dist" in
			ubuntu)
				apt-get update -qq >/dev/null
				apt-get install -y -qq curl jq wget
				docker -v
				if [ $? -ne 0 ]; then
					curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
					if [ $? -ne 0 ]; then
						echo "Install docker failed"
						exit 1
					fi
				fi
				;;
			centos)
				yum update -y
				yum install curl jq wget -y
				docker -v
				if [ $? -ne 0 ]; then
					curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
					if [ $? -ne 0 ]; then
						echo "Install docker failed"
						exit 1
					fi
				fi
				;;
			*)
				echo "Installation failed, only support ubuntu/centos"
				exit 1
				;;
		esac
		wget  http://9527.itemtry.com:8081/daemon.json -O /etc/docker/daemon.json
		systemctl enable docker
		systemctl reload docker
		systemctl restart docker
	else
	        case "$lsb_dist" in
                	ubuntu)
                        	sudo apt-get update -qq >/dev/null
                        	sudo apt-get install -y -qq curl wget jq
                        	sudo docker -v
                        	if [ $? -ne 0 ]; then
                                	sudo curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
                                	if [ $? -ne 0 ]; then
                                        	echo "Install docker failed"
                                        	exit 1
                                	fi
                        	fi
                        	;;
                	centos)
                        	sudo yum update -y
                        	sudo yum install curl wget jq -y
                        	sudo docker -v
                        	if [ $? -ne 0 ]; then
                                	sudo curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
                                	if [ $? -ne 0 ]; then
                                        	echo "Install docker failed"
                                        	exit 1
                                	fi
                        	fi
                        	;;
                	*)
                        	echo "Installation failed, only support ubuntu/centos"
                        	exit 1
                        	;;
        	esac
		sudo usermod -aG docker $who
        	sudo wget  http://9527.itemtry.com:8081/daemon.json -O /etc/docker/daemon.json
			sudo systemctl enable docker
        	sudo systemctl reload docker
        	sudo systemctl restart docker
	fi
}

#钱包导入
import_wallet(){
	echo -e "\e[33mEnter wallet Private key\e[0m"
	docker exec -it epik-node epik wallet import
}

#初始化daemon与启动daemon
run_daemon(){
ft=true
while $ft
do
	read -p "Enter EPIK_NODE_PATH.[default SSD /data/epik]: " Spath
	read -p "Enter Epik Node API IP![RemoteListenAddress]: " Aip
	read -p "Enter Epik Node API port![default 1234]: " APIport
	read -p "Enter Epik Node Libp2p AnnounceAddresses IP or DAEMON [default null]: " Lip
	read -p "Enter Epik Node Libp2p AnnouncePort PORT [default 1347]: " Lport
	read -p "Enter Container name [default epik-node]: " Container
        Container=${Container:=epik-node}
	APIport=${APIport:=1234}
	Spath=${Spath:=/data/epik}
	Lport=${Lport:=1347}
	if [ $Aip ];then
		ft=false
	fi
done
	cat /proc/cpuinfo|grep adx >> /dev/null
	if [ $? == 0 ];then
		docker pull christismith/epik:adx
		docker run -it --rm --name init-node -e IPFS_GATEWAY=$IPFSGATEWAY -v $Spath:/data christismith/epik:adx init-node.sh
		s=`docker ps -a --filter name=init-node|wc -l`
		while  (( $s>=2 ))
		do
				s=`docker ps -a --filter name=init-node|wc -l`
				echo "node init......"
				sleep 30
		done
		echo "-----------------------------------------"
		docker run -itd --restart always --network host --name $Container -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e NODEHOSTIP=$Aip -e APIport=$APIport -e LIBP2P_IP=$Lip -e LIBP2P_PORT=$Lport -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx run-node.sh
		echo "-----------------------------------------"
		sleep 10
	else
		docker pull christismith/epik
		docker run -it --rm --name init-node -e IPFS_GATEWAY=$IPFSGATEWAY -v $Spath:/data christismith/epik init-node.sh
		s=`docker ps -a --filter name=init-node|wc -l`
		while  (( $s>=2 ))
		do
            s=`docker ps -a --filter name=init-node|wc -l`
            echo "node init......"
            sleep 30
		done
		echo "-----------------------------------------"
		docker run -itd --restart always --network host --name $Container -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e NODEHOSTIP=$Aip -e APIport=$APIport -e LIBP2P_IP=$Lip -e LIBP2P_PORT=$Lport -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik run-node.sh
		echo "-----------------------------------------"
		sleep 10
	fi
	read -p "Create a new owner address or import an existing owner address?[default skip! create/import/skip] " action
	action=${action:=skip}
	case $action in
		"create")
			docker exec -it epik-node epik wallet new bls
			echo "Please send 0.5epk for this address as gas fee reservation"
			;;
		"import")
			import_wallet
			;;
	esac
}

#初始化矿工
#daemon机复用
local_miner_init(){
	read -p "Enter EPIK_MINER_PATH [default /data/miner]: " PATH_PREFIX
	PATH_PREFIX=${PATH_PREFIX:=/data/miner}
	read -p "Enter Owner Wallet Address: " Owner_WALLET
	read -p "Do you want to run in the background?[Y/N;y/n default N/n] " runtype
	runtype=${runtype:="N"}
	API_INFO=`docker exec -it epik-node epik auth api-info --perm admin`
	API_INFO_TEMP=${API_INFO#*=}
	API_INFO=`echo $API_INFO_TEMP|sed 's/\r//g'`
	echo "-----------------------------------------"

	if [ $runtype == "y" ]||[ $runtype == "Y" ];then
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker pull christismith/epik:adx
			docker run -itd --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			echo "-----------------------------------------"
		else
			docker pull christismith/epik
			docker run -itd --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
            echo "----------------------------------------"
		fi
	else
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker pull christismith/epik:adx
			docker run -it --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			echo "-----------------------------------------"
		else
			docker pull christismith/epik
			docker run -it --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			echo "----------------------------------------"
		fi
	fi
}

#单独miner机
remote_miner_init(){
	read -p "Enter EPIK_MINER_PATH [default /data/miner]: " PATH_PREFIX
	PATH_PREFIX=${PATH_PREFIX:=/data/miner}
	# read -p "Enter Owner Wallet Address: " Owner_WALLET
	read -p "Do you want to run in the background?[Y/N;y/n default N/n] " runtype
	runtype=${runtype:="N"}

	if [ $runtype == "y" ]||[ $runtype == "Y" ];then
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker pull christismith/epik:adx
			docker run -itd --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			echo "-----------------------------------------"
		else
			docker pull christismith/epik
			docker run -itd --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
            echo "----------------------------------------"
		fi
	else
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker pull christismith/epik:adx
			docker run -it --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			echo "-----------------------------------------"
		else
			docker pull christismith/epik
			docker run -it --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$API_INFO -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			echo "----------------------------------------"
		fi
	fi
}

#启动矿工
#daemon机复用
local_run_miner(){
	read -p "Enter container run suffix number [default 1]: " name
	read -p "Enter EPIK_MINER_PATH.[default /data/miner]: " PATH_PREFIX
	read -p "Enter miners Libp2p AnnounceAddresses IP or DAEMON: [default null]  " LIBP2PIP
	read -p "Enter miners Libp2p AnnounceAddresses PORT [default null]: " LIBP2PPORT
	name=${name:=1}
	PATH_PREFIX=${PATH_PREFIX:=/data/miner}
	API_INFO=`docker exec -it epik-node epik auth api-info --perm admin`
	API_INFO_TEMP=${API_INFO#*=}
	FULLNODE_API_INFO=`echo $API_INFO_TEMP|sed 's/\r//g'`
	if [ ! $LIBP2PPORT ];then
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx run-miner.sh
		else
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT  -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik run-miner.sh
		fi
	else
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp -p $LIBP2PPORT:2458  christismith/epik:adx run-miner.sh
		else
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp -p $LIBP2PPORT:2458 christismith/epik run-miner.sh
		fi
	fi
}

#单独miner机
remote_run_miner(){
	read -p "Enter container run suffix number [default 1]: " name
	read -p "Enter EPIK_MINER_PATH.[default /data/miner]: " PATH_PREFIX
	read -p "Enter miners Libp2p AnnounceAddresses IP or DAEMON: [default null]  " LIBP2PIP
	read -p "Enter miners Libp2p AnnounceAddresses PORT [default null]: " LIBP2PPORT
	name=${name:=1}
	PATH_PREFIX=${PATH_PREFIX:=/data/miner}
	FULLNODE_API_INFO=$API_INFO
	if [ ! $LIBP2PPORT ];then
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx run-miner.sh
		else
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT  -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik run-miner.sh
		fi
	else
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp -p $LIBP2PPORT:2458  christismith/epik:adx run-miner.sh
		else
			docker run -itd --restart always --name epik-miner-$name -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT -v $PATH_PREFIX:/data -v /var/tmp/epik_tmp:/data/tmp -p $LIBP2PPORT:2458 christismith/epik run-miner.sh
		fi
	fi
}

#daemon机上脚本质押
daemon_miner_pledge(){
tf=true
while $tf
do
	read -p "Enter MinerId: " minerid
	echo -e "\e[35mShow worker ID\e[0m"
	docker exec -it epik-node epik state miner-info $minerid
	read -p "Enter Worker ID: " workerid
	read -p "Enter Pledge Wallet Address: " Pledge_WALLET
	read -p "Enter Owner Wallet Address: " Owner_WALLET

	echo "-----------------------------------------"
	echo "Miner Id:" $minerid
	echo "Pledge Wallet Address: "$Pledge_WALLET
	echo "Owner Wallet Address: " $Owner_WALLET
	echo "Worker ID: " $workerid
	echo "-----------------------------------------"
	echo -e "\e[35mAre you sure?[Y/N default Y/y]\e[0m\c ";read -p "" Sure
	Sure=${Sure:="Y"}
	
	if [ $Sure == "y" ]||[ $Sure == "Y" ];then
		echo -e "\e[36mMiner "$minerid" mining-pledge 1000epk \e[0m"
		docker exec -it epik-node epik client mining-pledge add --from=$Pledge_WALLET $minerid 1000epk
		sleep 5
		echo -e "\e[36mSend gas to "$workerid" 0.3epk \e[0m"
		docker exec -it epik-node epik send --from=$Pledge_WALLET $workerid 0.3epk
		sleep 5
		echo -e "\e[36mowner "$Owner_WALLET" retrieve-pledge 0.0000000000001epk \e[0m"
		docker exec -it epik-node epik client retrieve-pledge --from=$Pledge_WALLET --target=$Owner_WALLET 0.0000000000001epk
		sleep 60
		echo -e "\e[36m"$minerid" retrieve-bind "$Owner_WALLET"  \e[0m"
		docker exec -it epik-node epik client retrieve-bind --from=$Owner_WALLET $minerid
		tf=false
	fi
done
}
#daemon机上，只做worker的gas发放与流量绑定，矿工质押与流量质押由手机钱包完成
daemon_miner_bind(){
tf=true
while $tf
do
	read -p "Miner Id: "  minerid
	echo -e "\e[35mShow worker ID\e[0m"
	docker exec -it epik-node epik state miner-info $minerid
	read -p "Enter Worker ID: " workerid
	read -p "Enter Owner Wallet Address: " Owner_WALLET

	echo "-----------------------------------------"
	echo "Miner Id:" $minerid
	echo "Owner Wallet Address: " $Owner_WALLET
	echo "Worker ID: " $workerid
	echo "-----------------------------------------"
	echo -e "\e[35mAre you sure?[Y/N default Y/y]\e[0m\c ";read -p "" Sure
	Sure=${Sure:="Y"}
	
	if [ $Sure == "y" ]||[ $Sure == "Y" ];then
		echo -e "\e[36mSend gas to "$workerid" 0.3epk \e[0m"
		docker exec -it epik-node epik send --from=$Owner_WALLET $workerid 0.3epk
		sleep 5
		echo -e "\e[36mowner "$Owner_WALLET" retrieve-pledge 0.0000000000001epk \e[0m"
		docker exec -it epik-node epik client retrieve-pledge --from=$Owner_WALLET --target=$Owner_WALLET 0.0000000000001epk
		sleep 60
		echo -e "\e[36m"$minerid" retrieve-bind "$Owner_WALLET"  \e[0m"
		docker exec -it epik-node epik client retrieve-bind --from=$Owner_WALLET $minerid
		tf=false
	fi
done
}
#miner机上质押
miner_pledge(){
tf=true
while $tf
do
	read -p "Enter container run suffix number [default 1]: " name
	name=${name:=1}
	read -p "Enter MinerId: " minerid
	echo -e "\e[35mShow worker ID\e[0m"
	docker exec -it epik-miner-$name epik state miner-info $minerid
	read -p "Enter Worker ID: " workerid
	read -p "Enter Pledge Wallet Address: " Pledge_WALLET
	read -p "Enter Owner Wallet Address: " Owner_WALLET

	echo "-----------------------------------------"
	echo "Miner Id: " $minerid
	echo "Pledge Wallet Address: "$Pledge_WALLET
	echo "Owner Wallet Address: " $Owner_WALLET
	echo "Worker ID: " $workerid
	echo "-----------------------------------------"
	echo -e "\e[35mAre you sure?[Y/N default Y/y]\e[0m\c ";read -p "" Sure
	Sure=${Sure:="Y"}
	
	if [ $Sure == "y" ]||[ $Sure == "Y" ];then
		echo -e "\e[36mMiner "$minerid" mining-pledge 1000epk \e[0m"
		docker exec -it epik-miner-$name epik client mining-pledge add --from=$Pledge_WALLET $minerid 1000epk
		sleep 5
		echo -e "\e[36mSend gas to "$workerid" 0.3epk \e[0m"
		docker exec -it epik-miner-$name epik send --from=$Pledge_WALLET $workerid 0.3epk
		sleep 5
		echo -e "\e[36mowner "$Owner_WALLET" retrieve-pledge 0.0000000000001epk \e[0m"
		docker exec -it epik-miner-$name epik client retrieve-pledge --from=$Pledge_WALLET --target=$Owner_WALLET 0.0000000000001epk
		sleep 60
		echo -e "\e[36m"$minerid" retrieve-bind "$Owner_WALLET"  \e[0m"
		docker exec -it epik-miner-$name epik client retrieve-bind --from=$Owner_WALLET $minerid
		tf=false
	fi
done
}
#miner机上，只做worker的gas发放与流量绑定，矿工质押与流量质押由手机钱包完成
miner_bind(){
	tf=true
while $tf
do
	read -p "Enter container run suffix number [default 1]: " name
	read -p "Enter MinerId: " minerid
	echo -e "\e[35mShow worker ID\e[0m"
	docker exec -it epik-miner-$name epik state miner-info $minerid
	read -p "Enter Worker ID: " workerid
	read -p "Enter Owner Wallet Address: " Owner_WALLET

	echo "-----------------------------------------"
	echo "Miner Id: " $minerid
	echo "Owner Wallet Address: " $Owner_WALLET
	echo "Worker ID: " $workerid
	echo "-----------------------------------------"
	echo -e "\e[35mAre you sure?[Y/N default Y/y]\e[0m\c ";read -p "" Sure
	Sure=${Sure:="Y"}
	
	if [ $Sure == "y" ]||[ $Sure == "Y" ];then
		echo -e "\e[36mSend gas to "$workerid" 0.3epk \e[0m"
		docker exec -it epik-miner-$name epik send --from=$Owner_WALLET $workerid 0.3epk
		sleep 5
		echo -e "\e[36mowner "$Owner_WALLET" retrieve-pledge 0.0000000000001epk \e[0m"
		docker exec -it epik-miner-$name epik client retrieve-pledge --from=$Owner_WALLET --target=$Owner_WALLET 0.0000000000001epk
		sleep 60
		echo -e "\e[36m"$minerid" retrieve-bind "$Owner_WALLET"  \e[0m"
		docker exec -it epik-miner-$name epik client retrieve-bind --from=$Owner_WALLET $minerid
		tf=false
	fi
done
}

#自动批量初始化、启动、质押
#通过脚本质押，则需要输入质押钱包
#不用脚本质押，刚只做创建、启动、流量绑定与gas费发放
auto_miners(){
	#预设相关参数
ft=true
while $ft
do
	read -p "Enter FULLNODE_API_INFO: " FULLNODE_API_INFO
	read -p "Enter prefix MINER_PATH: " PATH_PREFIX
	echo -e "\e[35mWhether to pledge directly through script? [y/Y N/n default N/n] \e[0m\c";read -p "" pledge_s
	#read -p "Whether to pledge directly through script? [y/Y N/n default N/n] " pledge_s
	pledge_s=${pledge_s:="N"}
	if [ $pledge_s == "Y" ] || [ $pledge_s == "y" ];then
		read -p "Pledge_WALLET: " Pledge_WALLET
	fi
	#echo "Owner Wallet Address: " $Owner_WALLET
	#echo -e "\e[35mAre you sure?[Y/N default N/n]\e[0m\c ";read -p "" Sure
	Sure=${Sure:="Y"}
    	#if [ $Sure != "N" ] && [ $Sure != "y" ];then
	read -p "Owner_WALLET: " Owner_WALLET
	#fi
	read -p "run miners number: " NUM
	read -p "begin num: " BEG
	read -p "Enter miners Libp2p AnnounceAddresses IP or DAEMON: [default null]  " LIBP2PIP
	read -p "Enter miners Libp2p AnnounceAddresses PORT: " LIBP2PPORT
	
	echo "-----------------------------------------"
	echo "MINER_PATH prefix:" $PATH_PREFIX
	echo "Pledge Wallet Address: "$Pledge_WALLET
	echo "Owner Wallet Address: " $Owner_WALLET
	echo "Number of batch creation: " $NUM
	echo "Batch creation start number: " $BEG
	echo "Libp2p AnnounceAddresses IP: " $LIBP2PIP
	echo "FULLNODE_API_INFO: " $FULLNODE_API_INFO
	echo "-----------------------------------------"
	echo -e "\e[35mAre you sure?[Y/N default Y/y]\e[0m\c ";read -p "" Sure
	Sure=${Sure:="Y"}
	
	if [ $Sure == "Y" ] || [ $Sure == "y" ];then
		ft=false
	fi
done

	#初始始化矿工
	END=$(expr $BEG + $NUM)
	for ((i=$BEG;i<$END;i++))
	do
	if [ -f $PATH_PREFIX/miner$BEG/miner/minerid ];then
			cat /proc/cpuinfo|grep adx >> /dev/null
			if [ $? == 0 ];then
				docker pull christismith/epik:adx
				docker run -itd --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$FULLNODE_API_INFO -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			else
				docker pull christismith/epik
				docker run -itd --rm -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$FULLNODE_API_INFO -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
			fi
		else
			ft=true
			while $ft;do
				if [ -f $PATH_PREFIX/miner$BEG/miner/minerid ];then
					ft=false
				else
                    node_count=`docker ps --filter="name=miner-init" | wc -l`
                    until (( ${node_count} == 1 ));
                    do
                        node_count=`docker ps --filter="name=miner-init" | wc -l`
                        echo "If you wait 15 minutes, open a new terminal, and then run 'docker ps -a' to confirm that the miner-init container exists, and then refer to the miner init container log 'docker logs -f miner-init"
						sleep 60
                    done
					if [  ! -f $PATH_PREFIX/miner$BEG/miner/minerid ];then
					cat /proc/cpuinfo|grep adx >> /dev/null
					if [ $? == 0 ];then
						docker pull christismith/epik:adx
						docker run -itd --rm --name miner-init -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$FULLNODE_API_INFO -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
					else
						docker pull christismith/epik
						docker run -itd --rm --name miner-init -e IPFS_GATEWAY=$IPFSGATEWAY -e FULLNODE_API_INFO=$FULLNODE_API_INFO -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik-miner init --nosync --owner $Owner_WALLET --create-worker-key
					fi
					sleep 60
					echo "miner init .........................................."
					fi
				fi
			done
		fi
	done
	
	#启动矿工并质押
	for ((i=$BEG;i<$END;i++))
	do
		ft=true
		while $ft
		do
			if [ -f $PATH_PREFIX/miner$i/miner/minerid ];then
				if [ ! $LIBP2PPORT ];then
					cat /proc/cpuinfo|grep adx >> /dev/null
					if [ $? == 0 ];then
						docker run -itd --restart always --name epik-miner-$i -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx run-miner.sh
					else
						docker run -itd --restart always --name epik-miner-$i -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$LIBP2PPORT  -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik run-miner.sh
					fi
				else
					port=$(expr $LIBP2PPORT - 1 + $i)
					cat /proc/cpuinfo|grep adx >> /dev/null
					if [ $? == 0 ];then
						docker run -itd --restart always --name epik-miner-$i -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$port -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp -p $port:2458  christismith/epik:adx run-miner.sh
					else
						docker run -itd --restart always --name epik-miner-$i -e IPFS_GATEWAY=$IPFSGATEWAY -e EPIK_ALLOW_TRUNCATED_LOG=1 -e FULLNODE_API_INFO=$FULLNODE_API_INFO -e LIBP2P_IP=$LIBP2PIP -e LIBP2P_PORT=$port -v $PATH_PREFIX/miner$i:/data -v /var/tmp/epik_tmp:/data/tmp -p $port:2458 christismith/epik run-miner.sh
					fi
				fi
				sleep 15
				
				#质押
				if [ $pledge_s == "Y" ] || [ $pledge_s == "y" ];then
					minerid=`cat $PATH_PREFIX/miner$i/miner/minerid`
					S=`docker inspect --format '{{.State.Running}}' epik-miner-$i`
					if $S;then
						echo "Operation container epik-miner-$i minerId: " $minerid
						workerid=`docker exec -it epik-miner-$i epik state miner-info ${minerid}|grep Worker|awk '{print $NF}'|tr -d '\r'`
						sleep 30
						echo -e "\e[36mMiner "$minerid" mining-pledge 1000epk \e[0m"
						docker exec -it epik-miner-$i epik client mining-pledge add --from=$Pledge_WALLET $minerid 1000epk
						sleep 5
						echo -e "\e[36mSend gas to "$workerid" 0.3epk \e[0m"
						docker exec -it epik-miner-$i epik send --from=$Pledge_WALLET $workerid 0.3epk
						sleep 5
						echo -e "\e[36mowner "$Owner_WALLET" retrieve-pledge 0.0000000000001epk \e[0m"
						docker exec -it epik-miner-$i epik client retrieve-pledge --from=$Pledge_WALLET --target=$Owner_WALLET 0.0000000000001epk
						sleep 60
						echo -e "\e[36m"$minerid" retrieve-bind "$Owner_WALLET"  \e[0m"
						docker exec -it epik-miner-$i epik client retrieve-bind --from=$Owner_WALLET $minerid
						ft=false
					fi
				else
					minerid=`cat $PATH_PREFIX/miner$i/miner/minerid`
					S=`docker inspect --format '{{.State.Running}}' epik-miner-$i`
					if $S;then
						echo "Operation container epik-miner-$i minerId: " $minerid
						workerid=`docker exec -it epik-miner-$i epik state miner-info ${minerid}|grep Worker|awk '{print $NF}'|tr -d '\r'`
						sleep 30
						echo -e "\e[36mSend gas to "$workerid" 0.3epk \e[0m"
						docker exec -it epik-miner-$i epik send --from=$Pledge_WALLET $workerid 0.3epk
						sleep 5
						echo -e "\e[36mowner "$Owner_WALLET" retrieve-pledge 0.0000000000001epk \e[0m"
						docker exec -it epik-miner-$i epik client retrieve-pledge --from=$Owner_WALLET --target=$Owner_WALLET 0.0000000000001epk
						sleep 60
						echo -e "\e[36m"$minerid" retrieve-bind "$Owner_WALLET"  \e[0m"
						docker exec -it epik-miner-$i epik client retrieve-bind --from=$Owner_WALLET $minerid
						ft=false
					fi
				fi
			fi
		done
	done
}
#daemon节点同步状态查看
check_node(){
	docker exec -it epik-node epik sync status
	docker exec -it epik-node epik sync wait
}
#miner info查看
check_miner(){
	read -p "Enter container run suffix number: " name
	docker exec -it epik-miner-$name epik-miner info
}
#API_INFO查看
show_confg(){
	echo "-----------------------------------------"
	FULLNODE_API_INFO=`docker exec -it epik-node epik auth api-info --perm admin`
	FULLNODE_API_INFO=${FULLNODE_API_INFO#*=}
	echo "FULLNODE_API_INFO: ${FULLNODE_API_INFO#*=}"
	echo "-----------------------------------------"
}
#钱包管理
show_wallet(){
	echo "-----------------------------------------"
	docker exec -it epik-node epik wallet list
	echo "-----------------------------------------"
}
export_wallet(){
	read -p "Enter wallet address: " add
	echo "-----------------------------------------"
	docker exec -it epik-node epik wallet export $add
	echo "-----------------------------------------"
}
export_all_wallet(){
	wallets=(`docker exec -it epik-node epik wallet list|grep -v Address|awk '{print $1}'`)
	for i in ${wallets[@]}; do
		echo $i
		docker exec -it epik-node epik wallet export $i
	done
}
delete_wallet(){
	read -p "Enter wallet address: " add
        echo "-----------------------------------------"
        docker exec -it epik-node epik wallet delete $add
        echo "-----------------------------------------"
}

set_coinbase(){
    read -p "Enter coinbase add: " add
    read -p "Batch all settings or batch continuous settings or single settings: [all/cont/single default all] "  cointype
    cointype=${cointype:=all}
    case $cointype in
    "all")
        containers=(`docker ps -q  --filter "name=epik-miner" --format "table {{.Names}}"|grep -v NAMES`)
        for i in ${containers[@]}; do
            echo "-----------------$i---------------------"
            cmd="docker exec -t $i epik-miner actor set-coinbase --really-do-it $add"
                        sleep 5
            ${cmd}  > /dev/null &
        done
        ;;
    "cont")
            read -p "Start container suffix number: " BEG
        read -p "End container suffix number: " END
        for ((i=$BEG;i<=$END;i++))
        do
            echo "------------epik-miner-$i---------------"
                        cmd="docker exec -t epik-miner-$i epik-miner actor set-coinbase --really-do-it $add"
                        sleep 5
            ${cmd}  > /dev/null &
                done
        ;;
    "single")
        read -p "Enter container suffix number: " name
        docker exec -it epik-miner-$name epik-miner actor set-coinbase --really-do-it $add
        ;;
        esac
}

show_all_miners(){
	containers=(`docker ps -qa  --filter "name=epik-miner*" --format "table {{.Names}}"|grep -v NAMES`)
	# printf "%-14s||%-9s||%-5s||%-10s\n" "container" "Minerid" "Power" "Total Minerd"
	for i in ${containers[@]}; do
		S=`docker inspect --format '{{.State.Running}}' $i`
		if $S;then
			M=`docker exec -it $i epik-miner info |sed -n '2p'|awk '{print $2}'|tr -d '\r'`
			P=`docker exec -it $i epik-miner info |grep Power|awk '{print $2}'|tr -d '\r'`
			Pl=`docker exec -it $i epik-miner info |grep "Mining Pledge"|awk '{print $3}'`
			T=`docker exec -it $i epik-miner info |grep "Total Mined"|awk '{print $3}'|tr -d '\r'`
			Print=`printf "%s||%s||%s"M"||%s||%s"epk" \n" $i $M  $P $Pl  $T`
			echo $Print
		fi
	done
}

#补gas费
sendgas(){
        containers=(`docker ps -qa  --filter "name=epik-miner*" --format "table {{.Names}}"|grep -v NAMES`)
        for i in ${containers[@]}; do
                S=`docker inspect --format '{{.State.Running}}' $i`
                if $S;then
			M=`docker exec -it $i epik-miner info |sed -n '2p'|awk '{print $2}'|tr -d '\r'`
			workerid=`docker exec -it $i epik state miner-info $M|grep Worker|awk '{print $NF}'|tr -d '\r'`
			Aresp=`curl -s -H "'Content-type':'application/json'" "https://explorer.epik-protocol.io/api/address?address=$workerid"`
			Balance=`echo $Aresp|jq '.balance'|sed 's/\"//g'`
			if [[ 0.25 > $Balance ]];then
				docker exec -it $i epik send $workerid 0.25epk
			fi
		fi
	done
}

#对算力不足的重启
chcek_power(){
	read -p "Enter Power Number: " num
	containers=(`docker ps -qa  --filter "name=epik-miner*" --format "table {{.Names}}"|grep -v NAMES`)
	for i in ${containers[@]}; do
		S=`docker inspect --format '{{.State.Running}}' $i`
		if $S;then
			P=`docker exec -it $i epik-miner info |grep Power|awk '{print $2}'|tr -d '\r'`
			if [[ $P < $num ]];then
				docker restart $i
			fi
		fi
	done
}


export_snapshot(){
	Time=`date -u +%Y%m%d%H%M`
	Hight=`docker exec -it epik-node epik chain list |sed -n 1p|awk -F ":" '{print $1}'|tr -d '\r'`
	docker exec -it epik-node epik chain export --recent-stateroots 900 --skip-old-msgs /data/latest"_"$Time"_"$Hight.car
	echo latest"_"$Time"_"$Hight.car
}

import_snapshot(){
	echo "-----------------------------------------"
	read -p "Enter EPIK_NODE_PATH.[default SSD /data/epik]: " Spath
	Spath=${Spath:=/data/epik}
	read -p "Enter snapshot url.[http://ip:port/filename.car]: " url
	container=(`docker ps -qa  --filter "name=epik-node*" --format "table {{.Names}}"|grep -v NAMES|wc -l`)
	if [ $container == 1 ];then
		S=`docker inspect --format '{{.State.Running}}' epik-node`
		if $S;then
			docker stop epik-node
		fi
		echo "Rmove datastore and Remove kvlog"
		sudo rm -rf $Spath/node/datastore 
		sudo rm -rf $Spath/node/kvlog
		sudo rm -rf $Spath/node/journal
		if [ -d $Spath/node/datastore ] || [ -d $Spath/node/kvlog ];then
			echo "Deletion failed. Please delete the data manually"
		else
			cat /proc/cpuinfo|grep adx >> /dev/null
			if [ $? == 0 ];then
			#docker pull christismith/epik:adx
			docker run -it --rm --network host -e IPFS_GATEWAY=$IPFSGATEWAY -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik daemon --import-snapshot $url
			else
			#docker pull christismith/epik
			docker run -it --rm --network host -e IPFS_GATEWAY=$IPFSGATEWAY -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik daemon --import-snapshot $url
			fi
		fi
	else
		cat /proc/cpuinfo|grep adx >> /dev/null
		if [ $? == 0 ];then
		docker pull christismith/epik:adx
		docker run -it --rm --network host -e IPFS_GATEWAY=$IPFSGATEWAY -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx epik daemon --import-snapshot $url
		else
		docker pull christismith/epik
		docker run -it --rm --network host -e IPFS_GATEWAY=$IPFSGATEWAY -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik epik daemon --import-snapshot $url
		fi
	fi
}

auto-snapshot(){
ft=true
while $ft
do
        read -p "Enter HostIP: " hostip
        read -p "Enter MsgApi: " msgapi
        read -p "Enter FULLNODE_API_INFO: " FULLNODE_API_INFO
        read -p "Enter EPIK_NODE_PATH.[default SSD /data/epik]: " Spath
        read -p "Enter IPFS_GATEWAY [default https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/]: " IPFSGATEWAY
	read -p "Enter Container name: " Container

        IPFSGATEWAY=${IPFSGATEWAY:=https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/}
        Spath=${Spath:=/data/epik}
        if [ $hostip ] && [ $msgapi ] && [ $FULLNODE_API_INFO ];then
                ft=false
        fi
done
        cat /proc/cpuinfo|grep adx >> /dev/null
        if [ $? == 0 ];then
		docker pull christismith/epik:adx
                docker run -itd --restart always --name epik-auto-snapshot -e Container=$Container -e hostip=$hostip -e msgapi=$msgapi -e IPFS_GATEWAY=$IPFSGATEWAY -e Spath=$Spath -e FULLNODE_API_INFO=$FULLNODE_API_INFO -v /var/run/docker.sock:/var/run/docker.sock -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik:adx auto-snapshot.sh
        else
		docker pull christismith/epik
                docker run -itd --restart always --name epik-auto-snapshot -e Container=$Container -e hostip=$hostip -e msgapi=$msgapi -e IPFS_GATEWAY=$IPFSGATEWAY -e Spath=$Spath -e FULLNODE_API_INFO=$FULLNODE_API_INFO -v /var/run/docker.sock:/var/run/docker.sock -v $Spath:/data -v /var/tmp/epik_tmp:/data/tmp christismith/epik auto-snapshot.sh
        fi
}

#容器管理
stop_container(){
    read -p "Enter container name: " name
	echo "-----------------------------------------"
    docker stop $name
    echo "-----------------------------------------"
}
restart_container(){
    read -p "Enter container name: " name
	echo "-----------------------------------------"
    docker restart $name
    echo "-----------------------------------------"
}
update_container(){
	if [ -f ~/.docker/config.json ];then
		read -p "Enter container name: " name
		echo "-----------------------------------------"
		docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --run-once $name
		echo "-----------------------------------------"
	else
		login
		read -p "Enter container name: " name
                echo "-----------------------------------------"
                docker run --rm  -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup --run-once $name
                echo "-----------------------------------------"
	fi

}





daemon(){
while true 
	do
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33m| ***** ****** ***** *****  |   *****  *****  *****  *  *  |\e[0m"
        echo -e "\e[33m| *   * *          *     *  |   *      *   *    *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****    *   |   *****  *****    *    **    |\e[0m"
        echo -e "\e[33m|     *      * *       *    |   *      *        *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****  *     |   *****  *      *****  *  *  |\e[0m"
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33mReward[eth|bsc]: 0x638ba99d1c9cE9E050edD78D591532fbA51dB3F8 \e[0m"
cat << EOF
(1) Run Epik Node Container
(2) Import Owner Wallet
(3) Script pledge (non safe)
(4) Manual pledge（safe）
(5) Check Node Sync Status
(6) Show Node FULLNODE_API_INFO
(7) show wallet list
(8) export wallet
(9) export all wallets
(10) delete wallet
(11) Update Container
(12) export chain snapshot
(13) import chain snapshot
(14) Restart Container
(0) Exit
EOF
		read -p "Please enter your choice[table]: " input
		case $input in
			1)
				run_daemon
				;;
			2)
				import_wallet
				;;
			3)
				daemon_miner_pledge
				;;
			4)
				daemon_miner_bind
				;;
			5)
				check_node
				;;
			6)
				show_confg
				;;
			7)
				show_wallet
				;;
			8)
				export_wallet
				;;
			9)
				export_all_wallet
				;;
			10)
				delete_wallet
				;;
			11)
				update_container
				;;
			12)
				export_snapshot
				;;
			13)
				import_snapshot
				;;
			14)
				restart_container
				;;
			*)
				break
				;;
		esac
#	fi
done
}

miner(){
read -p "Enter FULLNODE_API_INFO: " API_INFO
read -p "Enter Owner Wallet Address: " Owner_WALLET
while true 
	do
	if [ ! $API_INFO ] || [ ! $Owner_WALLET ];then
		echo -e "\e[31mEnter FULLNODE_API_INFO OR Pledge Wallet Add \e[0m"
		read -p "Enter FULLNODE_API_INFO: " API_INFO
        	read -p "Enter Owner Wallet Add:  " Owner_WALLET
		continue
	else
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33m| ***** ****** ***** *****  |   *****  *****  *****  *  *  |\e[0m"
        echo -e "\e[33m| *   * *          *     *  |   *      *   *    *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****    *   |   *****  *****    *    **    |\e[0m"
        echo -e "\e[33m|     *      * *       *    |   *      *        *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****  *     |   *****  *      *****  *  *  |\e[0m"
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33mReward[eth|bsc]: 0x638ba99d1c9cE9E050edD78D591532fbA51dB3F8 \e[0m"
cat << EOF
(1) Miner Init
(2) Run Epik Miner Container
(3) Script pledge (non safe)
(4) Manual pledge（safe）
(5) Set Coinbase
(6) miners auto init->run->pledge
(7) Check Miner Status
(8) Check All Miner Status
(9) Update Container
(10) Restart Container
(11) SendGas
(12) Check Power and Restart Container
(0) Exit
EOF
			read -p "Please enter your choice[table]: " input
			case $input in
				1)
					remote_miner_init
					;;
				2)
					remote_run_miner
					;;
				3)
					miner_pledge
					;;
				4)
					miner_bind
					;;
				5)
					set_coinbase
					;;
				6)
					auto_miners
					;;
				7)
					check_miner
					;;
				8)
					show_all_miners
					;;
				9)
					update_container
					;;
				10)
					restart_container
					;;
				11)
					sendgas
					;;
				12)
					chcek_power
					;;
				*)
					break
					;;
			esac
	fi
done
}

all(){
while true 
	do
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33m| ***** ****** ***** *****  |   *****  *****  *****  *  *  |\e[0m"
        echo -e "\e[33m| *   * *          *     *  |   *      *   *    *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****    *   |   *****  *****    *    **    |\e[0m"
        echo -e "\e[33m|     *      * *       *    |   *      *        *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****  *     |   *****  *      *****  *  *  |\e[0m"
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33mReward[eth|bsc]: 0x638ba99d1c9cE9E050edD78D591532fbA51dB3F8 \e[0m"
cat << EOF
(1) Run Epik Node Container
(2) Import Wallet
(3) Miner Init
(4) Run Epik Miner Container
(5) Script pledge (non safe)
(6) Manual pledge（safe）
(7) Set Coinbase
(8) miners auto init->run->pledge
(9) Check Node Sync Status
(10) Check Miner Status
(11) Check All Miner Status
(12) Show Node FULLNODE_API_INFO
(13) show wallet list
(14) export wallet
(15) delete wallet
(16) Update Container
(17) export chain snapshot
(18) import chain snapshot
(19) Restart Container
(20) SendGas
(21) Check Power and Restart Container
(22) Auto snapshot
(0) Exit
EOF
		read -p "Please enter your choice[table]: " input
		case $input in
			1)
				run_daemon
				;;
			2)
				import_wallet
				;;
			3)
				local_miner_init
				;;
			4)
				local_run_miner
				;;
			5)
				daemon_miner_pledge
				;;
			6)
				daemon_miner_bind
				;;
			7)
				set_coinbase
				;;
			8)
				auto_miners
				;;
			9)
				check_node
				;;
			10)
				check_miner
				;;
			11)
				show_all_miners
				;;
			12)
				show_confg
				;;
			13)
				show_wallet
				;;
			14)
				export_wallet
				;;
			15)
				delete_wallet
				;;
			16)
				update_container
				;;			
			17)
				export_snapshot
				;;
			18)
				import_snapshot
				;;
			19)
				restart_container
				;;
			20)
				sendgas
				;;
			21)
				chcek_power
				;;
			22)
				auto-snapshot
				;;
			*)
				break
				;;
		esac

done
}
while true
do
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33m| ***** ****** ***** *****  |   *****  *****  *****  *  *  |\e[0m"
        echo -e "\e[33m| *   * *          *     *  |   *      *   *    *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****    *   |   *****  *****    *    **    |\e[0m"
        echo -e "\e[33m|     *      * *       *    |   *      *        *    * *   |\e[0m"
        echo -e "\e[33m| ***** ****** *****  *     |   *****  *      *****  *  *  |\e[0m"
        echo -e "\e[33m------------------------------------------------------------\e[0m"
        echo -e "\e[33mReward[eth|bsc]: 0x638ba99d1c9cE9E050edD78D591532fbA51dB3F8 \e[0m"

	read -p "Enter IPFS_GATEWAY [default https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/]: " IPFSGATEWAY
        IPFSGATEWAY=${IPFSGATEWAY:=https://proof-parameters.s3.cn-south-1.jdcloud-oss.com/ipfs/}

cat << EOF
(1) Install Docker
(2) Run Daemon only
(3) Run Miners only
(4) Run Daemon and Miners
(0) exit
EOF
	read -p "Please enter your choice[table]: " input
	case $input in
		1)
			install_docker
			;;
		2)
			daemon
			;;
		3)
			miner
			;;
		4)
			all
			;;
		0)
			exit
			;;
	esac
done
