Skip to content

Commit 348f6e8

Browse files
authored
Create ltc_prune_node.sh
How to run LTC Node [By codono]
1 parent 65e2825 commit 348f6e8

File tree

1 file changed

+157
-0
lines changed

1 file changed

+157
-0
lines changed

node-setup/ltc_prune_node.sh

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
#!/bin/bash
2+
3+
# Function to generate random strings
4+
generate_random_string() {
5+
local length=$1
6+
tr -dc 'A-Za-z0-9' </dev/urandom | head -c "$length"
7+
echo
8+
}
9+
10+
# Function to generate a random port between 30000 and 39999
11+
generate_random_port() {
12+
shuf -i 30000-39999 -n 1
13+
}
14+
15+
# Welcome message
16+
echo "Welcome to Codono Litecoin Prune Node Setup!"
17+
echo "This script will guide you through setting up a Litecoin node with pruning enabled."
18+
echo "It will:"
19+
echo " - Check for existing RPC configuration and reuse it if available."
20+
echo " - Install necessary software (screen, Litecoin Core) if not already installed."
21+
echo " - Configure Litecoin Core with a random RPC port and user credentials."
22+
echo " - Start the Litecoin node in a screen session for resume protection."
23+
echo " - Set up supervisor to manage the Litecoin node service."
24+
echo " - Create a default wallet and test the connection."
25+
26+
# Prompt user to continue
27+
read -p "Do you want to continue with the setup wizard? (y/n): " -n 1 -r
28+
echo
29+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
30+
echo "Setup aborted."
31+
exit 1
32+
fi
33+
34+
# Check if ltc_rpc.yml exists and load existing RPC information
35+
RPC_FILE="/opt/ltc_rpc.yml"
36+
if [ -f "$RPC_FILE" ]; then
37+
echo "ltc_rpc.yml exists. Loading existing RPC information..."
38+
RPCUser=$(grep 'rpcuser:' "$RPC_FILE" | cut -d' ' -f2)
39+
RPCPass=$(grep 'rpcpassword:' "$RPC_FILE" | cut -d' ' -f2)
40+
RPCPort=$(grep 'rpcport:' "$RPC_FILE" | cut -d' ' -f2)
41+
ACCESS_IP=$(grep 'access_ip:' "$RPC_FILE" | cut -d' ' -f2)
42+
else
43+
# Gather Information
44+
echo "Generating RPC credentials and port..."
45+
RPCUser=$(generate_random_string 16)
46+
RPCPass=$(generate_random_string 32)
47+
RPCPort=$(generate_random_port)
48+
49+
# Ask user for ACCESS_IP
50+
read -p "Enter the ACCESS_IP (or press Enter to use 0.0.0.0): " ACCESS_IP
51+
ACCESS_IP=${ACCESS_IP:-0.0.0.0}
52+
53+
echo "RPC User: $RPCUser"
54+
echo "RPC Password: $RPCPass"
55+
echo "RPC Port: $RPCPort"
56+
echo "Access IP: $ACCESS_IP"
57+
58+
# Save RPC information to ltc_rpc.yml
59+
mkdir -p /opt
60+
cat <<EOF > "$RPC_FILE"
61+
rpcuser: $RPCUser
62+
rpcpassword: $RPCPass
63+
rpcport: $RPCPort
64+
access_ip: $ACCESS_IP
65+
EOF
66+
fi
67+
68+
# Check if screen is installed, and install it if not
69+
if ! command -v screen &> /dev/null; then
70+
echo "Screen is not installed. Installing screen..."
71+
sudo apt-get update
72+
sudo apt-get install screen -y
73+
else
74+
echo "Screen is already installed."
75+
fi
76+
77+
# Check if Litecoin Core is installed, and install it if not
78+
if ! command -v litecoind &> /dev/null; then
79+
echo "Litecoin Core is not installed. Installing Litecoin Core..."
80+
cd /opt/
81+
wget https://download.litecoin.org/litecoin-0.21.4/linux/litecoin-0.21.4-x86_64-linux-gnu.tar.gz
82+
tar -xvf litecoin-0.21.4-x86_64-linux-gnu.tar.gz
83+
sudo install -m 0755 -o root -g root -t /usr/local/bin litecoin-0.21.4/bin/*
84+
else
85+
echo "Litecoin Core is already installed."
86+
fi
87+
88+
# Create default wallet if it doesn't exist
89+
if ! litecoin-cli listwallets | grep -q "default"; then
90+
echo "Creating default wallet..."
91+
litecoin-cli createwallet "default"
92+
else
93+
echo "Default wallet already exists."
94+
fi
95+
96+
# Create and configure litecoin.conf
97+
echo "Configuring litecoin.conf..."
98+
cd /root/.litecoin/
99+
cat <<EOF > litecoin.conf
100+
rpcuser=$RPCUser
101+
rpcpassword=$RPCPass
102+
rpcport=$RPCPort
103+
rpctimeout=5
104+
rpcallowip=$ACCESS_IP
105+
rpcbind=0.0.0.0
106+
testnet=0
107+
server=1
108+
prune=550
109+
addresstype=p2sh-segwit
110+
wallet=default
111+
#daemon=1
112+
EOF
113+
114+
# Start litecoind in a screen session
115+
echo "Starting litecoind in a screen session..."
116+
screen -S litecoin_node -d -m litecoind -server -rpcbind=0.0.0.0 -rpcport=$RPCPort -rpcallowip=$ACCESS_IP -rpcuser=$RPCUser -rpcpassword=$RPCPass -prune=550 -addresstype=p2sh-segwit
117+
118+
# Install and configure supervisor if not already configured
119+
if [ ! -f /etc/supervisor/conf.d/litecoin.conf ]; then
120+
echo "Installing and configuring supervisor..."
121+
sudo apt-get update
122+
sudo apt-get install supervisor -y
123+
124+
cd /etc/supervisor/conf.d/
125+
cat <<EOF > litecoin.conf
126+
[program:litecoin]
127+
command=/usr/local/bin/litecoind -datadir=/root/.litecoin -conf=/root/.litecoin/litecoin.conf
128+
autostart=true
129+
autorestart=true
130+
stderr_logfile=/var/log/supervisor/litecoin.err.log
131+
stdout_logfile=/var/log/supervisor/litecoin.out.log
132+
EOF
133+
134+
# Reload supervisor
135+
echo "Reloading supervisor..."
136+
supervisorctl reload
137+
else
138+
echo "Supervisor configuration already exists."
139+
fi
140+
141+
# Testing Connection
142+
echo "Testing connection..."
143+
curl --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://$RPCUser:$RPCPass@127.0.0.1:$RPCPort/
144+
145+
# Creating a wallet if it doesn't exist
146+
if ! litecoin-cli listwallets | grep -q "my_wallet"; then
147+
echo "Creating a wallet..."
148+
litecoin-cli createwallet "my_wallet"
149+
else
150+
echo "Wallet 'my_wallet' already exists."
151+
fi
152+
153+
# Check if wallet is connected
154+
echo "Checking wallet connection..."
155+
litecoin-cli getwalletinfo
156+
157+
echo "Litecoin node setup complete! You can resume the screen session with 'screen -r litecoin_node'. Credentials are stored in /opt/ltc_rpc.yml. Save them somewhere safe and delete the file if necessary."

0 commit comments

Comments
 (0)