-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathhemixyz.sh
147 lines (124 loc) · 4.88 KB
/
hemixyz.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
#!/bin/bash
curl -s https://raw.githubusercontent.com/zunxbt/logo/main/logo.sh | bash
sleep 3
ARCH=$(uname -m)
show() {
echo -e "\033[1;35m$1\033[0m"
}
if ! command -v jq &> /dev/null; then
show "jq not found, installing..."
sudo apt-get update
sudo apt-get install -y jq > /dev/null 2>&1
if [ $? -ne 0 ]; then
show "Failed to install jq. Please check your package manager."
exit 1
fi
fi
check_latest_version() {
for i in {1..3}; do
LATEST_VERSION=$(curl -s https://api.github.com/repos/hemilabs/heminetwork/releases/latest | jq -r '.tag_name')
if [ -n "$LATEST_VERSION" ]; then
show "Latest version available: $LATEST_VERSION"
return 0
fi
show "Attempt $i: Failed to fetch the latest version. Retrying..."
sleep 2
done
show "Failed to fetch the latest version after 3 attempts. Please check your internet connection or GitHub API limits."
exit 1
}
check_latest_version
download_required=true
if [ "$ARCH" == "x86_64" ]; then
if [ -d "heminetwork_${LATEST_VERSION}_linux_amd64" ]; then
show "Latest version for x86_64 is already downloaded. Skipping download."
cd "heminetwork_${LATEST_VERSION}_linux_amd64" || { show "Failed to change directory."; exit 1; }
download_required=false # Set flag to false
fi
elif [ "$ARCH" == "arm64" ]; then
if [ -d "heminetwork_${LATEST_VERSION}_linux_arm64" ]; then
show "Latest version for arm64 is already downloaded. Skipping download."
cd "heminetwork_${LATEST_VERSION}_linux_arm64" || { show "Failed to change directory."; exit 1; }
download_required=false # Set flag to false
fi
fi
if [ "$download_required" = true ]; then
if [ "$ARCH" == "x86_64" ]; then
show "Downloading for x86_64 architecture..."
wget --quiet --show-progress "https://github.com/hemilabs/heminetwork/releases/download/$LATEST_VERSION/heminetwork_${LATEST_VERSION}_linux_amd64.tar.gz" -O "heminetwork_${LATEST_VERSION}_linux_amd64.tar.gz"
tar -xzf "heminetwork_${LATEST_VERSION}_linux_amd64.tar.gz" > /dev/null
cd "heminetwork_${LATEST_VERSION}_linux_amd64" || { show "Failed to change directory."; exit 1; }
elif [ "$ARCH" == "arm64" ]; then
show "Downloading for arm64 architecture..."
wget --quiet --show-progress "https://github.com/hemilabs/heminetwork/releases/download/$LATEST_VERSION/heminetwork_${LATEST_VERSION}_linux_arm64.tar.gz" -O "heminetwork_${LATEST_VERSION}_linux_arm64.tar.gz"
tar -xzf "heminetwork_${LATEST_VERSION}_linux_arm64.tar.gz" > /dev/null
cd "heminetwork_${LATEST_VERSION}_linux_arm64" || { show "Failed to change directory."; exit 1; }
else
show "Unsupported architecture: $ARCH"
exit 1
fi
else
show "Skipping download as the latest version is already present."
fi
echo
show "Select only one option:"
show "1. Use new wallet for PoP mining"
show "2. Use existing wallet for PoP mining"
read -p "Enter your choice (1/2): " choice
echo
if [ "$choice" == "1" ]; then
show "Generating a new wallet..."
./keygen -secp256k1 -json -net="testnet" > ~/popm-address.json
if [ $? -ne 0 ]; then
show "Failed to generate wallet."
exit 1
fi
cat ~/popm-address.json
echo
read -p "Have you saved the above details? (y/N): " saved
echo
if [[ "$saved" =~ ^[Yy]$ ]]; then
pubkey_hash=$(jq -r '.pubkey_hash' ~/popm-address.json)
show "Join: https://discord.gg/hemixyz"
show "Request faucet from faucet channel to this address: $pubkey_hash"
echo
read -p "Have you requested faucet? (y/N): " faucet_requested
if [[ "$faucet_requested" =~ ^[Yy]$ ]]; then
priv_key=$(jq -r '.private_key' ~/popm-address.json)
read -p "Enter static fee (numerical only, recommended: 100-200): " static_fee
echo
fi
fi
elif [ "$choice" == "2" ]; then
read -p "Enter your Private key: " priv_key
read -p "Enter static fee (numerical only, recommended: 100-200): " static_fee
echo
fi
if systemctl is-active --quiet hemi.service; then
show "hemi.service is currently running. Stopping and disabling it..."
sudo systemctl stop hemi.service
sudo systemctl disable hemi.service
else
show "hemi.service is not running."
fi
cat << EOF | sudo tee /etc/systemd/system/hemi.service > /dev/null
[Unit]
Description=Hemi Network popmd Service
After=network.target
[Service]
WorkingDirectory=$(pwd)
ExecStart=$(pwd)/popmd
Environment="POPM_BFG_REQUEST_TIMEOUT=60s"
Environment="POPM_BTC_PRIVKEY=$priv_key"
Environment="POPM_STATIC_FEE=$static_fee"
Environment="POPM_BFG_URL=wss://testnet.rpc.hemi.network/v1/ws/public"
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sleep 15
sudo systemctl enable hemi.service
sudo systemctl start hemi.service
echo
show "PoP mining is successfully srtated"