raspiblitz/home.admin/config.scripts/cln.install.sh

227 lines
7.3 KiB
Bash
Raw Normal View History

2021-05-10 23:13:08 +01:00
#!/bin/bash
# https://lightning.readthedocs.io/
# https://github.com/ElementsProject/lightning/releases
2021-08-10 16:11:40 +01:00
CLVERSION=v0.10.1
# install the latest master by using the last commit id
2021-08-10 16:11:40 +01:00
# https://github.com/ElementsProject/lightning/commit/master
# CLVERSION="063366ed7e3b7cc12a8d1681acc2b639cf07fa23"
2021-05-10 23:13:08 +01:00
# vars
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
# help
if [ $# -eq 0 ]||[ "$1" = "-h" ]||[ "$1" = "--help" ];then
echo
echo "C-lightning install script"
echo "the default version is: $CLVERSION"
echo "setting up on ${chain}net unless otherwise specified"
2021-07-12 15:37:43 +01:00
echo "mainnet / testnet / signet instances can run parallel"
2021-05-10 23:13:08 +01:00
echo
echo "usage:"
2021-07-12 15:37:43 +01:00
echo "cln.install.sh on <mainnet|testnet|signet>"
echo "cln.install.sh off <mainnet|testnet|signet> <purge>"
echo "cln.install.sh [update <version>|experimental|testPR <PRnumber>]"
2021-05-10 23:13:08 +01:00
echo
exit 1
fi
# Tor
TORGROUP="debian-tor"
source <(/home/admin/config.scripts/network.aliases.sh getvars cln $2)
2021-05-10 23:13:08 +01:00
echo "# Running: 'cln.install.sh $*'"
echo "# Using the settings for: ${network} ${CHAIN}"
2021-05-10 23:13:08 +01:00
2021-05-22 11:27:16 +01:00
# add default value to raspi config if needed
2021-05-25 14:24:17 +01:00
if ! grep -Eq "^${netprefix}cln=" /mnt/hdd/raspiblitz.conf; then
echo "${netprefix}cln=off" | sudo tee -a /mnt/hdd/raspiblitz.conf
2021-05-22 11:27:16 +01:00
fi
source /mnt/hdd/raspiblitz.conf
if [ "$1" = on ]||[ "$1" = update ]||[ "$1" = experimental ]||[ "$1" = testPR ];then
if [ ! -f /usr/local/bin/lightningd ]||[ "$1" = update ]||[ "$1" = experimental ]||[ "$1" = testPR ];then
########################
# Install dependencies #
########################
2021-05-10 23:13:08 +01:00
echo "# apt update"
echo
sudo apt-get update
echo
echo "# Installing dependencies"
echo
sudo apt-get install -y \
autoconf automake build-essential git libtool libgmp-dev \
libsqlite3-dev python3 python3-mako net-tools zlib1g-dev libsodium-dev \
gettext
####################################
# Download and compile from source #
####################################
2021-05-10 23:13:08 +01:00
cd /home/bitcoin || exit 1
if [ "$1" = "update" ] || [ "$1" = "testPR" ] || [ "$1" = "experimental" ]; then
2021-05-10 23:13:08 +01:00
echo
echo "# Deleting the old source code"
sudo rm -rf lightning
fi
echo
echo "# Cloning https://github.com/ElementsProject/lightning.git"
echo
sudo -u bitcoin git clone https://github.com/ElementsProject/lightning.git
cd lightning || exit 1
if [ "$1" = "testPR" ]; then
PRnumber=$2 || exit 1
echo
echo "# Using the PR:"
echo "# https://github.com/ElementsProject/lightning/pull/$PRnumber"
sudo -u bitcoin git fetch origin pull/$PRnumber/head:pr$PRnumber || exit 1
sudo -u bitcoin git checkout pr$PRnumber || exit 1
echo "# Building with EXPERIMENTAL_FEATURES enabled"
echo
2021-05-10 23:13:08 +01:00
sudo -u bitcoin ./configure --enable-experimental-features
elif [ "$1" = "experimental" ]; then
2021-05-10 23:13:08 +01:00
echo
echo "# Updating to the latest commit in:"
echo "# https://github.com/ElementsProject/lightning"
echo
echo "# Building with EXPERIMENTAL_FEATURES enabled"
sudo -u bitcoin ./configure --enable-experimental-features
else
if [ "$1" = "update" ]; then
CLVERSION=$2
echo "# Updating to the version $CLVERSION"
fi
sudo -u bitcoin git reset --hard $CLVERSION
sudo -u bitcoin ./configure
fi
currentCLversion=$(cd /home/bitcoin/lightning 2>/dev/null; \
git describe --tags 2>/dev/null)
sudo -u bitcoin ./configure
echo
echo "# Building from source C-lightning $currentCLversion"
echo
sudo -u bitcoin make
echo
echo "# Built C-lightning $currentCLversion"
echo
echo "# Install to /usr/local/bin/"
echo
sudo make install || exit 1
# clean up
# cd .. && rm -rf lightning
else
installedVersion=$(sudo -u bitcoin /usr/local/bin/lightningd --version)
echo "# C-lightning ${installedVersion} is already installed"
fi
##########
# Config #
##########
2021-05-10 23:13:08 +01:00
echo "# Make sure bitcoin is in the ${TORGROUP} group"
sudo usermod -a -G ${TORGROUP} bitcoin
echo "# Add plugin-dir: /home/bitcoin/${netprefix}cln-plugins-enabled"
echo "# Add plugin-dir: /home/bitcoin/cln-plugins-available"
# note that the disk is mounted with noexec
sudo -u bitcoin mkdir /home/bitcoin/${netprefix}cln-plugins-enabled 2>/dev/null
sudo -u bitcoin mkdir /home/bitcoin/cln-plugins-available 2>/dev/null
2021-05-10 23:13:08 +01:00
echo "# Store the lightning data in /mnt/hdd/app-data/.lightning"
echo "# Symlink to /home/bitcoin/"
sudo rm -rf /home/bitcoin/.lightning # not a symlink, delete
sudo mkdir -p /mnt/hdd/app-data/.lightning
sudo ln -s /mnt/hdd/app-data/.lightning /home/bitcoin/
2021-08-10 17:06:06 +01:00
if [ ${CLNETWORK} != "bitcoin" ] && [ ! -d /home/bitcoin/.lightning/${CLNETWORK} ] ;then
sudo -u bitcoin mkdir /home/bitcoin/.lightning/${CLNETWORK}
fi
if ! sudo ls ${CLNCONF};then
echo "# Create ${CLNCONF}"
echo "# lightningd configuration for ${network} ${CHAIN}
2021-05-10 23:13:08 +01:00
network=${CLNETWORK}
2021-05-10 23:13:08 +01:00
announce-addr=127.0.0.1:${portprefix}9736
log-file=cl.log
log-level=debug
plugin-dir=/home/bitcoin/${netprefix}cln-plugins-enabled
2021-05-10 23:13:08 +01:00
# Tor settings
proxy=127.0.0.1:9050
bind-addr=127.0.0.1:${portprefix}9736
2021-07-06 10:12:08 +01:00
addr=statictor:127.0.0.1:9051/torport=${portprefix}9736
2021-05-10 23:13:08 +01:00
always-use-proxy=true
" | sudo tee ${CLNCONF}
2021-05-10 23:13:08 +01:00
else
echo "# The file ${CLNCONF} is already present"
2021-05-10 23:13:08 +01:00
fi
sudo chown -R bitcoin:bitcoin /mnt/hdd/app-data/.lightning
sudo chown -R bitcoin:bitcoin /home/bitcoin/
#################
# Backup plugin #
#################
/home/admin/config.scripts/cln-plugin.backup.sh on $CHAIN
###################
# Systemd service #
###################
/home/admin/config.scripts/cln.install-service.sh $CHAIN
2021-05-10 23:13:08 +01:00
echo
echo "# Adding aliases"
echo "\
2021-05-25 14:24:17 +01:00
alias ${netprefix}lightning-cli=\"sudo -u bitcoin /usr/local/bin/lightning-cli\
--conf=${CLNCONF}\"
alias ${netprefix}cln=\"sudo -u bitcoin /usr/local/bin/lightning-cli\
--conf=${CLNCONF}\"
alias ${netprefix}clnlog=\"sudo\
tail -n 30 -f /home/bitcoin/.lightning/${CLNETWORK}/cl.log\"
alias ${netprefix}clnconf=\"sudo\
nano ${CLNCONF}\"
" | sudo tee -a /home/admin/_aliases
2021-05-10 23:13:08 +01:00
echo "# The installed C-lightning version is: $(sudo -u bitcoin /usr/local/bin/lightningd --version)"
echo
echo "# To activate the aliases reopen the terminal or use:"
echo "source ~/_aliases"
2021-05-25 14:24:17 +01:00
echo "# Monitor the ${netprefix}lightningd with:"
echo "sudo journalctl -fu ${netprefix}lightningd"
echo "sudo systemctl status ${netprefix}lightningd"
2021-05-10 23:13:08 +01:00
echo "# logs:"
echo "sudo tail -f /home/bitcoin/.lightning/${CLNETWORK}/cl.log"
2021-05-10 23:13:08 +01:00
echo "# for the command line options use"
2021-05-25 14:24:17 +01:00
echo "${netprefix}lightning-cli help"
2021-05-10 23:13:08 +01:00
echo
2021-05-22 11:27:16 +01:00
# setting value in raspi blitz config
2021-05-25 14:24:17 +01:00
sudo sed -i "s/^${netprefix}cln=.*/${netprefix}cln=on/g" /mnt/hdd/raspiblitz.conf
2021-05-22 11:27:16 +01:00
exit 0
2021-05-10 23:13:08 +01:00
fi
if [ "$1" = "off" ];then
2021-05-25 14:24:17 +01:00
echo "# Removing the ${netprefix}lightningd.service"
sudo systemctl disable ${netprefix}lightningd
sudo systemctl stop ${netprefix}lightningd
2021-05-10 23:13:08 +01:00
echo "# Removing the aliases"
sudo sed -i "/${netprefix}lightning-cli/d" /home/admin/_aliases
sudo sed -i "/${netprefix}cl/d" /home/admin/_aliases
2021-05-10 23:13:08 +01:00
if [ "$(echo "$@" | grep -c purge)" -gt 0 ];then
echo "# Removing the binaries"
sudo rm -f /usr/local/bin/lightningd
sudo rm -f /usr/local/bin/lightning-cli
fi
2021-05-22 11:27:16 +01:00
# setting value in raspi blitz config
2021-05-25 14:24:17 +01:00
sudo sed -i "s/^${netprefix}cln=.*/${netprefix}cln=off/g" /mnt/hdd/raspiblitz.conf
2021-05-10 23:13:08 +01:00
fi