raspiblitz/home.admin/config.scripts/bonus.faraday.sh

209 lines
5.8 KiB
Bash
Raw Normal View History

2020-05-10 14:51:19 +02:00
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "Bonus App: faraday -> https://github.com/lightninglabs/faraday"
echo "lnd.faraday.sh [status|on|off]"
exit 1
fi
# version and trusted release signer
2020-05-10 16:21:05 +02:00
version="0.1.0-alpha"
2020-05-10 14:51:19 +02:00
PGPkeys="https://keybase.io/carlakirkcohen/pgp_keys.asc"
PGPcheck="15E7ECF257098A4EF91655EB4CA7FE54A6213C91"
# 1. parameter [info|verified|reckless]
mode="$1"
# GATHER DATA
source /mnt/hdd/raspiblitz.conf
# setting download directory
downloadDir="/home/admin/download"
# detect CPU architecture & fitting download link
cpuArchitecture=""
if [ $(uname -m | grep -c 'arm') -eq 1 ] ; then
cpuArchitecture="armv7"
fi
if [ $(uname -m | grep -c 'aarch64') -eq 1 ] ; then
cpuArchitecture="arm64"
fi
if [ $(uname -m | grep -c 'x86_64') -eq 1 ] ; then
cpuArchitecture="amd64"
fi
if [ $(uname -m | grep -c 'i386\|i486\|i586\|i686\|i786') -eq 1 ] ; then
cpuArchitecture="386"
fi
# check if already installed
2020-05-10 14:57:09 +02:00
installed=0
2020-05-10 16:18:09 +02:00
installedVersion=$(sudo -u admin frcli --version)
2020-05-10 14:57:09 +02:00
if [ ${#installedVersion} -gt 0 ]; then
installed=1
fi
2020-05-10 14:51:19 +02:00
# STATUS
if [ "${mode}" = "status" ]; then
echo "# status data"
echo "cpuArchitecture='${cpuArchitecture}'"
echo "version='${version}'"
echo "installed=${installed}"
exit 1
fi
# INSTALL
if [ "${mode}" = "on" ] || [ "${mode}" = "1" ]; then
echo "# INSTALL bonus.faraday.sh"
echo
echo "# clean & change into download directory"
sudo rm -r ${downloadDir}/*
cd "${downloadDir}"
echo "# extract the SHA256 hash from the manifest file for the corresponding platform"
2020-05-10 16:21:05 +02:00
downloadLink="https://github.com/lightninglabs/faraday/releases/download/v${version}/manifest-v${version}.txt"
2020-05-10 15:03:55 +02:00
sudo -u admin wget -N ${downloadLink}
2020-05-10 16:21:05 +02:00
checkDownload=$(ls manifest-v${version}.txt 2>/dev/null | grep -c manifest-v${version}.txt)
2020-05-10 14:51:19 +02:00
if [ ${checkDownload} -eq 0 ]; then
2020-05-10 15:03:55 +02:00
echo "downloadLink='${downloadLink}'"
2020-05-10 14:51:19 +02:00
echo "error='download manifest failed'"
exit 1
fi
2020-05-10 16:21:05 +02:00
SHA256=$(grep -i "linux-${cpuArchitecture}" manifest-v$version.txt | cut -d " " -f1)
2020-05-10 14:51:19 +02:00
echo "# SHA256 hash: $SHA256"
if [ ${#SHA256} -eq 0 ]; then
echo "error='getting checksum failed'"
exit 1
fi
echo
echo "# get Binary"
2020-05-10 16:21:05 +02:00
binaryName="faraday-linux-${cpuArchitecture}-v${version}.tar.gz"
sudo -u admin wget -N https://github.com/lightninglabs/faraday/releases/download/v${version}/${binaryName}
2020-05-10 14:51:19 +02:00
checkDownload=$(ls ${binaryName} 2>/dev/null | grep -c ${binaryName})
if [ ${checkDownload} -eq 0 ]; then
echo "error='download binary failed'"
exit 1
fi
echo
echo "# check binary was not manipulated (checksum test)"
2020-05-10 16:21:05 +02:00
sudo -u admin wget -N https://github.com/lightninglabs/faraday/releases/download/v${version}/manifest-v${version}.txt.sig
2020-05-10 14:51:19 +02:00
sudo -u admin wget -N -O "${downloadDir}/pgp_keys.asc" ${PGPkeys}
binaryChecksum=$(sha256sum ${binaryName} | cut -d " " -f1)
if [ "${binaryChecksum}" != "${SHA256}" ]; then
echo "error='checksum not matching'"
exit 1
fi
echo
echo "# getting gpg finger print"
gpg ./pgp_keys.asc
fingerprint=$(sudo gpg "${downloadDir}/pgp_keys.asc" 2>/dev/null | grep "${PGPcheck}" -c)
if [ ${fingerprint} -lt 1 ]; then
echo "error='PGP author check failed'"
exit 1
fi
echo "fingerprint='${fingerprint}'"
echo
echo "# checking PGP finger print"
gpg --import ./pgp_keys.asc
sleep 3
2020-05-10 16:21:05 +02:00
verifyResult=$(gpg --verify manifest-v${version}.txt.sig 2>&1)
2020-05-10 14:51:19 +02:00
goodSignature=$(echo ${verifyResult} | grep 'Good signature' -c)
echo "goodSignature='${goodSignature}'"
correctKey=$(echo ${verifyResult} | tr -d " \t\n\r" | grep "${PGPcheck}" -c)
echo "correctKey='${correctKey}'"
if [ ${correctKey} -lt 1 ] || [ ${goodSignature} -lt 1 ]; then
echo "error='PGP verify fail'"
exit 1
fi
# install
2020-05-10 16:18:09 +02:00
echo
2020-05-10 14:51:19 +02:00
echo "# unzip binary"
sudo -u admin tar -xzf ${binaryName}
# removing the tar.gz ending from the binary
directoryName="${binaryName%.*.*}"
echo "# install binary directory '${directoryName}'"
sudo install -m 0755 -o root -g root -t /usr/local/bin ${directoryName}/*
sleep 3
2020-05-10 16:18:09 +02:00
installed=$(sudo -u admin frcli --version)
2020-05-10 14:51:19 +02:00
if [ ${#installed} -eq 0 ]; then
echo "error='install failed'"
exit 1
fi
2020-05-15 17:28:53 +02:00
# make sure faraday user exists (this will run the farday server)
echo "# Add the 'faraday' user"
sudo adduser --disabled-password --gecos "" faraday
# add user to group with readonly access on lnd
sudo /usr/sbin/usermod --append --groups lndreadonly faraday
# install service
echo "*** Install systemd ***"
2020-05-15 18:22:54 +02:00
cat > /mnt/hdd/temp/faraday.service <<EOF
2020-05-15 17:28:53 +02:00
[Unit]
Description=faraday
Wants=lnd.service
After=lnd.service
[Service]
WorkingDirectory=/home/faraday/
2020-05-15 18:55:14 +02:00
ExecStart=faraday --macaroondir=/mnt/hdd/app-data/lnd/data/chain/${network}/${chain}net --macaroonfile=readonly.macaroon --tlscertpath=/mnt/hdd/app-data/lnd/tls.cert --rpcserver=127.0.0.1:10009
2020-05-15 17:28:53 +02:00
User=faraday
Restart=always
TimeoutSec=120
RestartSec=30
StandardOutput=null
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
2020-05-15 18:22:54 +02:00
sudo mv /mnt/hdd/temp/faraday.service /etc/systemd/system/faraday.service
2020-05-15 17:28:53 +02:00
sudo chown root:root /etc/systemd/system/faraday.service
sudo systemctl enable faraday
sudo systemctl start faraday
2020-05-10 14:51:19 +02:00
echo "# flag in raspiblitz config"
if [ ${#faraday} -eq 0 ]; then
2020-05-15 18:50:35 +02:00
echo "faraday='on'" >> /mnt/hdd/raspiblitz.conf
2020-05-10 14:51:19 +02:00
fi
2020-05-15 18:50:35 +02:00
sudo sed -i "s/^faraday=.*/faraday=on/g" /mnt/hdd/raspiblitz.conf
2020-05-10 14:51:19 +02:00
2020-05-15 17:28:53 +02:00
echo "# OK faraday Installed"
2020-05-10 14:51:19 +02:00
exit 1
fi
2020-05-15 17:28:53 +02:00
# DEINSTALL
2020-05-15 18:56:13 +02:00
if [ "${mode}" = "off" ] || [ "${mode}" = "0" ]; then
2020-05-15 17:28:53 +02:00
echo "# DEINSTALL"
echo "# remove systemd service"
sudo systemctl stop faraday
sudo systemctl disable faraday
sudo rm /etc/systemd/system/faraday.service
echo "# remove faraday user"
userdel -r -f faraday
echo "# modify config file"
sudo sed -i "s/^faraday=.*/faraday=off/g" /mnt/hdd/raspiblitz.conf
2020-05-10 14:51:19 +02:00
exit 1
fi
echo "error='parameter not known'"
exit 1