forked from ladopixel/ergo-node-sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_node_v2.sh
161 lines (128 loc) · 5.18 KB
/
start_node_v2.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# ┌───────────────────────────┐
# │ Developed by ladopixel │
# │ Execute Ergo node v5.0.13 │
# └───────────────────────────┘
# I define my key for the configuration file
# my_key="aaaa"
# I define some colors for the messages
texto_verde="\033[32m"
texto_rojo="\033[31m"
reset="\033[0m"
# ERGO
echo
echo " ███████"
echo " █"
echo " █"
echo " █"
echo " █"
echo " █"
echo " ███████ ErgoPlatform.org"
echo
# I verify that a Java version exists in my computer, if it does not exist I show a message and exit.
if ! type -p java > /dev/null; then
echo -e "${texto_rojo} [-] Java is not installed on your system, you need to install it. ${reset}"
exit 1
fi
# I go to the user's home directory
cd || exit
# The first parameter ($1) is to indicate the name of the directory where everything will be installed,
# if you do not specify it, it will automatically create a directory in the user's home ergo_node.
if [ $# -gt 0 ]; then
directory=$1
else
directory="ergo_node"
fi
if [ ! -d "$directory" ]; then
mkdir -v "$directory" > /dev/null
echo -e "${texto_verde}[+] Ergo directory successfully created ${reset}"
else
echo -e "${texto_rojo}[!] The directory already exists, impossible to create another one with the same name ${reset}"
fi
# I check that my_key is not empty and I define my key for the configuration file
while true; do
# Check if the input is not blank and if exist ergo.conf
if [ -n "$my_key" ] || [ -f "$HOME/$directory/ergo.conf" ]; then
break # Exit the loop if input is not blank or ergo.conf exists
else
echo "API Key name cannot be blank."
# Ask the user for input
echo -n "Enter your name: "
read -r my_key
# Display the input
echo "Hello, $my_key!"
fi
done
# I download the node version
url_ergo="https://github.com/ergoplatform/ergo/releases/download/v5.0.13"
jar_file="ergo-5.0.13.jar"
if [ ! -f "$HOME/$directory/$jar_file" ]; then
curl -LJO $url_ergo/$jar_file
mv "$HOME"/$jar_file "$HOME/$directory"
echo -e "${texto_verde}[+] The node has been successfully downloaded ${reset}"
else
echo -e "${texto_rojo}[!] You already have an available node ${reset}"
fi
# I create the initial ergo.conf file.
if [ ! -f "$HOME/$directory/ergo.conf" ]; then
ergo_conf="ergo {"
echo "$ergo_conf" > "$HOME/$directory/ergo.conf"
ergo_conf="directory = \${ergo.directory}/$HOME/$directory"
echo "$ergo_conf" >> "$HOME/$directory/ergo.conf"
ergo_conf="networkType = \"mainnet\""
echo "$ergo_conf" >> "$HOME/$directory/ergo.conf"
ergo_conf="node.stateType = \"digest\""
echo "$ergo_conf" >> "$HOME/$directory/ergo.conf"
ergo_conf="node.blocksToKeep = 1440"
echo "$ergo_conf" >> "$HOME/$directory/ergo.conf"
ergo_conf="node.nipopow.nipopowBootstrap = true"
echo "$ergo_conf" >> "$HOME/$directory/ergo.conf"
ergo_conf="}"
echo $ergo_conf >> "$HOME/$directory/ergo.conf"
echo -e "${texto_verde}[+] Configuration file successfully created ${reset}"
# I run the node for the first time
cd "$HOME"/"$directory" || exit
java -jar $jar_file --mainnet -c ergo.conf &
# I store the pid of the node process running at background for the first time
node_process_pid=$!
echo -e "${texto_verde}[+] PID $node_process_pid ${reset}"
# To initialize local node
sleep 20
# known public node http://213.239.193.208:9053/
# local node http://localhost:9053/
# Create my key haciendo uso de la API en mi nodo activo
api_key=$(curl -X POST "http://localhost:9053/utils/hash/blake2b" -H "accept: application/json" -H "Content-Type: application/json" -d "\"$my_key\"")
if [ $? -eq 0 ]; then # Check if the request was successful
echo -e "${texto_verde}[+] API Response: Api key generated correctly ${reset}"
else
echo -e "${texto_rojo}[-] Error when querying the API. ${reset}"
fi
# Stop the node
kill $node_process_pid
echo -e "${texto_verde}[+] Node closed to restart with api_key ${reset}"
# update ergo.conf with api_key
echo_conf="scorex {"
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="restApi {"
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="apiKeyHash = $api_key"
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="}"
echo $echo_conf >> "$HOME/$directory/ergo.conf"
echo_conf="network {"
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="nodeName = \"ergo-at-bash\""
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="agentName = \"ergo-at-bash\""
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="maxConnections = 12"
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="}"
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
echo_conf="}"
echo "$echo_conf" >> "$HOME/$directory/ergo.conf"
fi
# I start the node with the correctly configured configuration file.
cd "$HOME/$directory" || exit
echo -e "${texto_verde}[+] Restarting node ${reset}"
java -jar $jar_file --mainnet -c ergo.conf