-
Notifications
You must be signed in to change notification settings - Fork 41
/
create_wallet.sh
96 lines (85 loc) · 2.84 KB
/
create_wallet.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
#!/bin/bash
# Install required packages
echo "Checking if 'unzip' and 'jq' are installed..."
sudo apt update
sudo apt install -y unzip jq
# Automatically detect the user's home directory
USER_HOME="$HOME"
GETH_DIR="$USER_HOME"
PASSWORD_FILE="$USER_HOME/wallet_password.txt"
ADDRESS_FILE="$USER_HOME/wallet_address.txt"
WALLET_DIR="$USER_HOME/keystore"
# Function to choose Geth version
choose_version() {
echo "Fetching available Core Geth versions..."
VERSIONS=$(curl -s https://api.github.com/repos/etclabscore/core-geth/releases | jq -r '.[].tag_name')
echo "Available Core Geth Versions:"
select VERSION in $VERSIONS; do
if [[ -n "$VERSION" ]]; then
echo "Selected version: $VERSION"
break
else
echo "Invalid selection. Please choose a valid number."
fi
done
}
# Function to choose the ZIP file
choose_zip_file() {
echo "Fetching available ZIP files for version $VERSION..."
ASSETS=$(curl -s https://api.github.com/repos/etclabscore/core-geth/releases/tags/$VERSION | jq -r '.assets[] | .browser_download_url')
echo "Available ZIP files:"
select ASSET in $ASSETS; do
if [[ -n "$ASSET" ]]; then
echo "Selected file: $ASSET"
break
else
echo "Invalid selection. Please choose a valid file."
fi
done
}
# Download and extract Geth
download_and_extract_geth() {
echo "Downloading Core Geth: $ASSET"
curl -L $ASSET -o "$GETH_DIR/core-geth.zip"
echo "Extracting Core Geth..."
unzip -q "$GETH_DIR/core-geth.zip" -d "$GETH_DIR"
chmod +x "$GETH_DIR/geth"
}
# Create wallet
create_wallet() {
echo "Please enter a password for the wallet:"
read -s WALLET_PASSWORD
echo "Please confirm the password:"
read -s WALLET_PASSWORD_CONFIRM
if [ "$WALLET_PASSWORD" != "$WALLET_PASSWORD_CONFIRM" ]; then
echo "Passwords do not match. Please try again."
exit 1
fi
echo "$WALLET_PASSWORD" > "$PASSWORD_FILE"
echo "Creating new wallet..."
WALLET_ADDRESS=$(./geth account new --password "$PASSWORD_FILE" | grep -o '0x[0-9a-fA-F]\{40\}')
if [ -z "$WALLET_ADDRESS" ]; then
echo "Error: Could not extract wallet address!"
exit 1
fi
echo "Wallet address: $WALLET_ADDRESS"
echo "$WALLET_ADDRESS" > "$ADDRESS_FILE"
echo "Core Geth successfully downloaded and installed at: $GETH_DIR/geth"
echo "Wallet address and password have been saved."
}
# Delete downloaded Core Geth ZIP file
delete_zip_file() {
echo "Deleting the downloaded ZIP file..."
rm -f "$GETH_DIR/core-geth.zip"
if [ ! -f "$GETH_DIR/core-geth.zip" ]; then
echo "The ZIP file was successfully deleted."
else
echo "Error deleting the ZIP file!"
fi
}
# Main process
choose_version
choose_zip_file
download_and_extract_geth
create_wallet
delete_zip_file