-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsetup_offline_keygen.sh
230 lines (202 loc) · 7.75 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
#!/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
# Step 2: Ensure Python 3.8 is installed
echo "Ensuring Python 3.8 is installed..."
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y python3.8 python3.8-venv python3.8-distutils python3.8-dev
# Verify Python 3.8 installation
#python3.8_version=$(python3.8 -V 2>&1)
#if [[ $python3.8_version != "Python 3.8"* ]]; then
# echo -e "${RED}Error: Python 3.8 is not installed correctly.${NC}"
# exit 1
#fi
echo -e "${GREEN}Python 3.8 is successfully installed.${NC}"
clear
# Prompt the user for the installation path
read -e -p "Please enter the installation path (Press Enter for default: ~/stakingcli): " INSTALL_PATH
# Check if the user has entered a path
if [ -z "$INSTALL_PATH" ]; then
INSTALL_PATH=~/stakingcli
fi
clear
echo "Checking if staking-cli is already installed..."
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
if [ ! -d "${INSTALL_PATH}" ]; then
echo "Cloning the staking-deposit-cli repository..."
git clone https://gitlab.com/pulsechaincom/staking-deposit-cli.git "${INSTALL_PATH}" || {
echo -e "${RED}Failed to clone the repository. Please check your internet connection.${NC}"
exit 1
}
else
echo "Directory already exists. Skipping the cloning process."
fi
# Step 3: Set up virtual environment
echo "Setting up Python 3.8 virtual environment..."
cd "${INSTALL_PATH}" || exit
python3.8 -m venv venv
source venv/bin/activate
# Install staking-cli dependencies inside venv
echo "Installing staking-cli dependencies inside the virtual environment..."
pip install --upgrade pip setuptools > /dev/null 2>&1
pip install -r requirements.txt > /dev/null 2>&1
pip install . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "${RED}Failed to install staking-cli dependencies.${NC}"
deactivate
exit 1
fi
echo -e "${GREEN}Staking-cli dependencies installed successfully inside the virtual environment.${NC}"
# Keygen script generation
echo "Generating keygen script..."
cat > "${INSTALL_PATH}/offline_key.sh" << EOL
#!/bin/bash
INSTALL_PATH="${INSTALL_PATH}"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
source "\${INSTALL_PATH}/venv/bin/activate"
generate_new_validator_key() {
clear
echo "Generating new validator keys..."
while true; do
read -e -p "Enter Withdrawal Wallet Address: " withdrawal_wallet
if [[ "\${withdrawal_wallet}" =~ ^0x[a-fA-F0-9]{40}$ ]]; then
break
else
echo "Invalid address format. Please try again."
fi
done
cd "\${INSTALL_PATH}"
./deposit.sh new-mnemonic \
--mnemonic_language=english \
--chain=pulsechain \
--folder="\${INSTALL_PATH}" \
--eth1_withdrawal_address="\${withdrawal_wallet}"
}
restore_from_mnemonic() {
clear
echo "Restoring keys from mnemonic..."
while true; do
read -e -p "Enter Withdrawal Wallet Address: " withdrawal_wallet
if [[ "\${withdrawal_wallet}" =~ ^0x[a-fA-F0-9]{40}$ ]]; then
break
else
echo "Invalid address format. Please try again."
fi
done
cd "\${INSTALL_PATH}"
./deposit.sh existing-mnemonic \
--chain=pulsechain \
--folder="\${INSTALL_PATH}" \
--eth1_withdrawal_address="\${withdrawal_wallet}"
}
echo "Choose an option:"
echo "1) Generate new validator keys"
echo "2) Restore keys from mnemonic"
echo "0) Exit"
read choice
case \$choice in
1) generate_new_validator_key ;;
2) restore_from_mnemonic ;;
0) exit ;;
*) echo "Invalid option." ;;
esac
EOL
chmod +x "${INSTALL_PATH}/offline_key.sh"
sudo ln -s "${INSTALL_PATH}/offline_key.sh" /usr/local/bin/keygen
# Desktop shortcut
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}"
# Deactivate virtual environment
deactivate
clear
echo -e "${GREEN}Setup complete.${NC}"
echo "Run 'keygen' or use the Desktop shortcut to start."
echo ""
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 ""