forked from tdslaine/install_pulse_node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_offline_keygen.sh
355 lines (292 loc) · 11.5 KB
/
setup_offline_keygen.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
clear
echo ""
echo ""
echo "+-------------------------------------------------------+"
echo "| DipSlayer presents: |"
echo "| |"
echo "| Staking-Cli Offline Setup for |"
echo "| Pulsechain-Mainnet only |"
echo "| |"
echo "+-------------------------------------------------------+"
echo ""
echo ""
echo "Disclaimer:"
echo ""
echo "This script downloads the necessary requirements for running Staking-Cli and"
echo "facilitates the generation of validator keys. It is intended to be used on a"
echo "separate, offline device."
echo ""
echo "Please ensure the following:"
echo "- The device running this script is separate from the validator itself."
echo "- The device is airgapped and disconnected from the network during the key generation process."
echo "- Once the initial setup is complete, the device should remain offline to ensure the security"
echo " of the generated validator keys."
echo ""
echo "Please exercise caution and follow best practices to protect the integrity and security of"
echo "your validator keys."
echo ""
echo "After the initial Setup is done you can launch the Validator-Keygen via the Desktop Icon"
echo "or via the terminal command \"keygen\" from anywhere within your terminal/cli/console"
echo "+-------------------------------------------------------+"
echo ""
echo "Press Enter to Continue"
read -p ""
function get_main_user() {
main_user=$(logname || echo $SUDO_USER || echo $USER)
echo "Main user: $main_user"
}
clear
sudo add-apt-repository -y universe
sudo apt update
sudo apt install -y git
clear
echo "Checking if python3 > 3.8 is installed"
echo "Press Enter to Continue"
read -p ""
command -v python3 >/dev/null 2>&1 || { echo >&2 "Python3 is required but it's not installed. Aborting."; exit 1; }
# Find the highest python3 version installed
HIGHEST_PY3_VERSION=$(dpkg --get-selections | grep -oP 'python3\.\K[0-9]+' | sort -V | tail -n 1)
REQUIRED_PY_VERSION="3.8"
if (( $(echo "$HIGHEST_PY3_VERSION < $REQUIRED_PY_VERSION" | bc -l) ))
then
echo "Highest Python3 version is lower than $REQUIRED_PY_VERSION"
echo "Installing Python $REQUIRED_PY_VERSION..."
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y python3.8
else
echo "Highest Python3 version is $HIGHEST_PY3_VERSION, which is sufficient"
fi
clear
echo "Checking if pip3 is installed"
echo "Press Enter to Continue"
read -p ""
# Check if pip3 is installed
command -v pip3 >/dev/null 2>&1 || { echo >&2 "Pip3 is required but it's not installed. Installing..."; sudo apt install -y python3-pip; }
clear
# Prompt the user for the installation path
read -e -p "Please enter the installation path (Press Enter for default: home/"${main_user}"/stakingcli): " INSTALL_PATH
# Check if the user has entered a path
if [ -z "$INSTALL_PATH" ]; then
INSTALL_PATH=~/stakingcli
fi
echo ""
clear
echo "Checking if stakingcli is already installed"
echo "Press Enter to Continue"
read -p ""
# Check if the directory exists
if [ -d "./${INSTALL_PATH}" ]; then
while true; do
read -p "The staking-deposit-cli folder already exists. Do you want to delete it and clone the latest version? (y/N): " confirm_delete
if [ "$confirm_delete" == "y" ] || [ "$confirm_delete" == "Y" ]; then
sudo rm -rf "${INSTALL_PATH}"
break
elif [ "$confirm_delete" == "n" ] || [ "$confirm_delete" == "N" ] || [ -z "$confirm_delete" ]; then
echo "Skipping the cloning process as the user chose not to delete the existing folder."
break
else
echo "Invalid option. Please enter 'y' or 'n'."
fi
done
fi
# Clone the staking-deposit-cli repository
while true; do
if [ -d "${INSTALL_PATH}" ]; then
echo "Directory already exists. Skipping the cloning process."
break
elif git clone https://gitlab.com/pulsechaincom/staking-deposit-cli.git "${INSTALL_PATH}"; then
echo "Cloned staking-deposit-cli repository into ${INSTALL_PATH}"
break
else
echo ""
echo "Failed to clone staking-deposit-cli repository. Please check your internet connection and try again."
echo ""
read -p "Press 'r' to retry, any other key to exit: " choice
if [ "$choice" != "r" ]; then
exit 1
fi
fi
done
# Give execution permission to deposit.sh and run it
clear
echo "granting Permissions to stakingcli and installing requierments"
echo "Press Enter to Continue"
read -p ""
cd ${INSTALL_PATH}
chmod +x deposit.sh
sudo ./deposit.sh install
sudo chmod -R 777 "${INSTALL_PATH}"
sudo chown $main_user:$main_user "${INSTALL_PATH}"
echo "generating offline_key.sh script"
NEWKEY='generate_new_validator_key() {
clear
echo ""
echo "Generating the validator keys via staking-cli"
echo ""
echo "Please follow the instructions and make sure to READ! and understand everything on screen"
echo ""
echo -e "${RED}Attention:${NC}"
echo ""
echo "The next steps require you to enter the wallet address that you would like to use for receiving"
echo "validator rewards while validating and withdrawing your funds when you exit the validator pool."
echo -e "This is the ${GREEN}Withdrawal- or Execution-Wallet (they are the same)${NC}"
echo ""
echo -e "Make sure ${RED}you have full access${NC} to this Wallet. ${RED}Once set, it cannot be changed${NC}"
echo ""
echo -e "You need to provide this Wallet-Adresss in the ${GREEN}proper format (checksum)${NC}."
echo -e "One way to achieve this, is to copy your address from the Blockexplorer"
echo ""
read -p "I have read this information and understand the importance of using the right Withdrawal-Wallet Address. (y/n): " confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
echo "Exiting script now."
exit 1
fi
echo ""
# Check if the address is a valid address, loop until it is...
while true; do
read -e -p "Please enter your Execution/Withdrawal-Wallet address: " withdrawal_wallet
if [[ "${withdrawal_wallet}" =~ ^0x[a-fA-F0-9]{40}$ ]]; then
break
else
echo "Invalid address format. Please enter a valid PRC20 address."
fi
done
# Running staking-cli to Generate the new validator_keys
echo ""
echo "Starting staking-cli to Generate the new validator_keys"
echo ""
cd "${INSTALL_PATH}"
./deposit.sh new-mnemonic \
--mnemonic_language=english \
--chain=pulsechain \
--folder="${INSTALL_PATH}" \
--eth1_withdrawal_address="${withdrawal_wallet}"
chmod -R 777 "${INSTALL_PATH}/validator_keys" >/dev/null 2>&1
echo ""
echo "Press Enter to quit"
read -p ""
}'
RESTORE_KEY='Restore_from_MN() {
clear
echo ""
echo "Generating the validator keys via staking-cli"
echo ""
echo "Please follow the instructions and make sure to READ! and understand everything on screen"
echo ""
echo -e "${RED}Attention:${NC}"
echo ""
echo "The next steps require you to enter the wallet address that you would like to use for receiving"
echo "validator rewards while validating and withdrawing your funds when you exit the validator pool."
echo -e "This is the ${GREEN}Withdrawal- or Execution-Wallet (they are the same)${NC}"
echo ""
echo -e "Make sure ${RED}you have full access${NC} to this Wallet. ${RED}Once set, it cannot be changed${NC}"
echo ""
echo -e "You need to provide this Wallet-Adresss in the ${GREEN}proper format (checksum)${NC}."
echo -e "One way to achieve this, is to copy your address from the Blockexplorer"
echo ""
read -p "I have read this information and understand the importance of using the right Withdrawal-Wallet Address. (y/n): " confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
echo "Exiting script now."
exit 1
fi
# Check if the address is a valid address, loop until it is...
while true; do
read -e -p "Please enter your Execution/Withdrawal-Wallet address: " withdrawal_wallet
if [[ "${withdrawal_wallet}" =~ ^0x[a-fA-F0-9]{40}$ ]]; then
break
else
echo "Invalid address format. Please enter a valid PRC20 address."
fi
done
echo ""
cd "${INSTALL_PATH}"
./deposit.sh existing-mnemonic \
--chain=pulsechain \
--folder="${INSTALL_PATH}" \
--eth1_withdrawal_address="${withdrawal_wallet}"
chmod -R 777 "${INSTALL_PATH}/validator_keys"
echo "Your keys can be found in "${INSTALL_PATH}/validator_keys""
echo ""
echo "Press Enter to quit"
read -p ""
}'
clear
echo "Generating keygen script"
echo "Press Enter to Continue"
read -p ""
cat > offline_key.sh << EOL
#!/bin/bash
INSTALL_PATH="$INSTALL_PATH"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
${NEWKEY}
${RESTORE_KEY}
echo "-----------------------------------------"
echo "| Validator Key Setup |"
echo "-----------------------------------------"
echo ""
while true; do
echo "1) Generate new validator keys. (Fresh, with a new Seed)"
echo ""
echo "2) Restore or Add from a Seed Phrase/Mnemonic (Using an existing Seed)"
echo ""
echo "0) Exit/Cancel"
read -p $'\nChoose an option (1-3): ' choice
if [[ \$choice == 1 ]]; then
generate_new_validator_key
break
elif [[ \$choice == 2 ]]; then
Restore_from_MN
break
elif [[ \$choice == 0 ]]; then
echo "Exiting..."
exit 0
else
echo "Invalid option. Please choose option (1,2 or 0)."
fi
done
EOL
chmod +x offline_key.sh
sudo ln -s "$(pwd)/offline_key.sh" /usr/local/bin/keygen
desktop_file="${HOME}/Desktop/offline_keygen.desktop"
cat > "${desktop_file}" << EOL
[Desktop Entry]
Version=1.0
Type=Application
Name=Offline Keygen
Comment=Generate validator keys offline
Exec=${INSTALL_PATH}/offline_key.sh
Icon=utilities-terminal
Terminal=true
Categories=Utility;
EOL
chmod +x "${desktop_file}"
clear
echo -e "${GREEN}Setup complete${NC}"
echo ""
echo "Please disconnect your device from the Internet now."
echo ""
echo -e "You can launch the validator key setup anytime via the command ${GREEN}keygen${NC} from the terminal, or the Desktop-Icon \"Offline Keygen\""
echo "you can find the main_script here: ${INSTALL_PATH}/offline_key.sh."
echo ""
echo "Keys will be generated in this folder: ${INSTALL_PATH}/validator_keys"
echo ""
echo "Press Enter to continue"
read -p ""
echo ""
echo "Brought to you by:"
echo "██████__██_██████__███████_██_______█████__██____██_███████_██████__"
echo "██___██_██_██___██_██______██______██___██__██__██__██______██___██_"
echo "██___██_██_██████__███████_██______███████___████___█████___██████__"
echo "██___██_██_██___________██_██______██___██____██____██______██___██_"
echo "██████__██_██______███████_███████_██___██____██____███████_██___██_"
echo -e "${GREEN}For Donations use \nERC20: 0xCB00d822323B6f38d13A1f951d7e31D9dfDED4AA${NC}"
echo ""