-
Notifications
You must be signed in to change notification settings - Fork 2
/
newchain-mine.sh
86 lines (76 loc) · 3.37 KB
/
newchain-mine.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
default_networkname="mainnet"
cd /data/newchain/${networkname}/
function color() {
# Usage: color "31;5" "string"
# Some valid values for color:
# - 5 blink, 1 strong, 4 underlined
# - fg: 31 red, 32 green, 33 yellow, 34 blue, 35 purple, 36 cyan, 37 white
# - bg: 40 black, 41 red, 44 blue, 45 purple
printf '\033[%sm%s\033[0m\n' "$@"
}
color "37" ""
if [[ "$*" == "" ]]; then
networkname="${default_networkname}"
elif [[ "$*" == "mainnet" || "$*" == "main" ]]; then
networkname="mainnet"
elif [[ "$*" == "testnet" || "$*" == "test" ]]; then
networkname="testnet"
else
color "31" "Not support network $*."
exit 1
fi
color "32" "Current NewChain network is ${networkname}"
if [[ $(/data/newchain/${networkname}/bin/geth attach /data/newchain/${networkname}/nodedata/geth.ipc --exec eth.syncing) != "false" ]]; then
color "31" "Please wait until your node synchronization is complete"
exit 0
else
color "37" "Your node has been synchronized"
fi
# Trying to get current miner address if exits
address=$(/data/newchain/${networkname}/bin/geth attach /data/newchain/${networkname}/nodedata/geth.ipc --exec eth.coinbase | sed 's/\"//g')
if [[ ${address} != 0x* || ${#address} < 42 ]]; then
# Account
color "" "Create new password for your miner's keystore."
color "" "Your new account is locked with a password. Please give a password. Do not forget this password."
echo -n "Password: "
read -s password0
echo
echo -n "Repeat password: "
read -s password1
echo
if [[ ${password0} != ${password1} ]]; then
color "31" "Passwords do not match"
exit 0
fi
if [[ ${password0} == "" ]]; then
color "31" "Passwords is empty"
exit 0
fi
if ( echo ${password0} | grep -q ' ' ); then
color "31" "Passwords has space"
exit 0
fi
echo ${password0} > /data/newchain/${networkname}/password.txt
# /data/newchain/${networkname}/bin/geth --config /data/newchain/${networkname}/conf/node.toml account new --password /data/newchain/${networkname}/password.txt
address=`/data/newchain/${networkname}/bin/geth --config /data/newchain/${networkname}/conf/node.toml account new --password /data/newchain/${networkname}/password.txt | grep "Public address" | awk '{print $6}'`
echo "you miner address is: |${address}|"
if [[ ${address} != 0x* || ${#address} < 42 ]]; then
color "31" "address len error"
exit 1
fi
color "32" "Your miner address keystore is under /data/newchain/${networkname}/nodedata, please backup it."
fi
current_time=$(date +"%Y%m%d%H%M%S")
cp /data/newchain/${networkname}/conf/node.toml /data/newchain/${networkname}/conf/node.bak.${current_time}.toml
cp /etc/supervisor/conf.d/newchain.conf /data/newchain/${networkname}/supervisor/newchain.bak.${current_time}.conf
sudo sed -i "s,command=.*,command=/data/newchain/${networkname}/bin/geth --config /data/newchain/${networkname}/conf/node.toml --mine --unlock ${address} --password /data/newchain/${networkname}/password.txt --allow-insecure-unlock --miner.gastarget 100000000," /etc/supervisor/conf.d/newchain.conf
sudo supervisorctl update
# get IPs from ifconfig and dig
#LOCALIP=$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | head -n1 | awk '{print $2}' | cut -d':' -f2)
IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
color "37" "Copy the following information and share it with other mining nodes: "
color "32" "
Address: ${address}
IP: ${IP}
"