Last active
February 19, 2022 04:21
-
-
Save mariodian/6edea1c69896fcdaaec22294f66faa81 to your computer and use it in GitHub Desktop.
Install LND
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Get number of cores to speed up the compilation time | |
CORES=$(( $(lscpu | awk '/^Socket/{ print $2 }') * $(lscpu | awk '/^Core/{ print $4 }') )) | |
# Other vars | |
IP=$(dig +short myip.opendns.com @resolver1.opendns.com) | |
BTC_CONF=~/.bitcoin/bitcoin.conf | |
LND_DIR=~/.lnd | |
LND_CONF=lnd.conf | |
# Is bitcoind installed? | |
which bitcoind > /dev/null || (echo "Install bitcoind first" && exit) | |
# What is the shell environment? | |
if echo $SHELL | grep --quiet bash; then | |
echo "bash" | |
SHELL_FILE=~/.bashrc | |
elif echo $SHELL | grep --quiet zsh; then | |
echo "zsh" | |
SHELL_FILE=~/.zshrc | |
else | |
echo "This script only works with bash and zsh" | |
exit | |
fi | |
# Install golang | |
sudo apt-get update && sudo apt-get upgrade -y | |
sudo apt-get install golang-1.10-go | |
# Create a directory for golang repos | |
mkdir ~/go | |
# Add golang dir to the $PATH | |
echo "export GOPATH=~/go" >> $SHELL_FILE | |
echo "export PATH=$GOPATH/bin:/usr/lib/go-1.10/bin:/usr/local/bin:$PATH" >> $SHELL_FILE | |
source $SHELL_FILE | |
# Check if golang and $PATH is proper | |
if go version | grep --quiet go1.10; then | |
echo "Go language has been installed and is recognized by the system" | |
else | |
echo "Go either hasn't been installed or isn't recognized by the system. Make sure to add /usr/lib/go-1.10/bin to your \$PATH" | |
exit | |
fi | |
# Clone the LND repostiroy | |
git clone https://github.com/lightningnetwork/lnd $GOPATH/src/github.com/lightningnetwork/lnd | |
cd $GOPATH/src/github.com/lightningnetwork/lnd | |
# Install LND | |
make -j$CORES && make install | |
# Create some configurations for bitcoind if it doesn't exist | |
RPC_USER=$(cat $BTC_CONF | grep rpcuser || echo "rpcuser=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w64 | head -n1)" | tee -a $BTC_CONF) | |
RPC_PASS=$(cat $BTC_CONF | grep rpcpass || echo "rpcpass=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w64 | head -n1)" | tee -a $BTC_CONF) | |
ZMQPUBRAWBLOCK=$(cat $BTC_CONF | grep zmqpubrawblock || echo "zmqpubrawblock=tcp://127.0.0.1:18501" | tee -a $BTC_CONF) | |
ZMQPUBRAWTX=$(cat $BTC_CONF | grep zmqpubrawtx || echo "zmqpubrawtx=tcp://127.0.0.1:18502" | tee -a $BTC_CONF) | |
mkdir $LND_DIR && cd $LND_DIR | |
touch $LND_CONF | |
# Create lnd.conf | |
echo "debuglevel=info | |
listen=$IP | |
externalip=$IP | |
maxpendingchannels=8 | |
bitcoin.mainnet=1 | |
bitcoin.active=1 | |
bitcoin.node=bitcoind | |
bitcoind.$RPC_USER | |
bitcoind.$RPC_PASS | |
bitcoind.$ZMQPUBRAWBLOCK | |
bitcoind.$ZMQPUBRAWTX" > $LND_CONF | |
# Open ports | |
sudo iptables -A INPUT -p tcp --dport 9735 -j ACCEPT | |
sudo iptables -A INPUT -p udp --dport 9735 -j ACCEPT | |
sudo iptables-save | |
# Create systemd service | |
cd /lib/systemd/system | |
sudo echo "[Unit] | |
Description=LND Lightning Daemon | |
Requires=bitcoind.service | |
After=bitcoind.service | |
[Service] | |
ExecStart=$HOME/go/bin/lnd | |
ExecStop=$HOME/go/bin/lncli stop | |
PIDFile=$HOME/.lnd/lnd.pid | |
User=$(whoami) | |
Group=$(whoami) | |
Type=simple | |
KillMode=process | |
TimeoutStartSec=60 | |
TimeoutStopSec=60 | |
Restart=always | |
RestartSec=60 | |
[Install] | |
WantedBy=multi-user.target" > lnd.service | |
# Enable the service | |
sudo systemctl enable lnd | |
cd $LND_DIR | |
# Create self-signed certificate | |
openssl ecparam -genkey -name prime256v1 -out tls.key | |
openssl req -new -sha256 \ | |
-key tls.key \ | |
-subj "/CN=localhost/O=lnd" \ | |
-reqexts SAN \ | |
-config <(cat /etc/ssl/openssl.cnf \ | |
<(printf "\n[SAN]\nsubjectAltName=\ | |
DNS:localhost,\ | |
IP:$IP\ | |
")) \ | |
-out csr.csr | |
openssl req -in csr.csr -text -noout | |
openssl req -x509 -sha256 -days 36500 \ | |
-key tls.key \ | |
-in csr.csr -out tls.cert \ | |
-extensions SAN \ | |
-config <(cat /etc/ssl/openssl.cnf \ | |
<(printf "\n[SAN]\nsubjectAltName=\ | |
DNS:localhost,\ | |
IP:$IP\ | |
")) | |
openssl x509 -in tls.cert -text -noout | |
# Post install instructions | |
echo "You can now run lnd with: sudo service lnd start &" | |
echo "Create a lightning wallet first with: lncli create" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment