LND_VERSION_DIR_AARCH64=lnd-linux-arm64-v0.17.4-beta LND_URL_AARCH64=https://github.com/lightningnetwork/lnd/releases/download/v0.17.4-beta/lnd-linux-arm64-v0.17.4-beta.tar.gz LND_SHA256_AARCH64=3c3472f3f1c93fef5b4e8989278c7538602c9d7c36c35092251c8bad0abf3cef # binaries and config root; data is elsewhere, in /ssd/lnd as per lnd conf. LND_HOME=/home/lnd # no root slash since it's combined with other path prefixes. LND_SVDIR=etc/sv/lnd lnd_bin_install() { cd $LND_HOME local lnd_targz=$LND_VERSION_DIR_AARCH64.tar.gz test -f $LND_VERSION_DIR_AARCH64/lnd && return 0; curl -sSL -o $lnd_targz "$LND_URL_AARCH64" if [ $? -ne 0 ]; then printf "ERROR: unable to download $LND_URL_AARCH64\n" 1>&2 return 1 fi printf "$LND_SHA256_AARCH64 $lnd_targz" | sha256sum --check [ $? -ne 0 ] && return 1 tar -C $LND_HOME --no-same-owner -xf $lnd_targz rm -f $lnd_targz return $? } lnd_svc_install() { # service directories mkdir -p /$LND_SVDIR mkdir -p /$LND_SVDIR/log # logging facility if [ ! -f /$LND_SVDIR/log/run ]; then cp $SYSUPDATES_ROOTDIR/files/$LND_SVDIR/log/run /$LND_SVDIR/log/ chmod +x /$LND_SVDIR/log/run fi # the actual lnd service cat < /$LND_SVDIR/run.new #!/bin/sh [ -r conf ] && . ./conf exec 2>&1 # wait for OS to acquire a clock sync. # random date in the past: Oct 22 06:40:00 PM UTC 2023 while [ "\$(date +%s)" -lt 1698000000 ] do echo "service start suspended until clock sync" sleep 5 done exec chpst -u lnd $LND_HOME/$LND_VERSION_DIR_AARCH64/lnd -C /home/lnd/lnd.mainnet.conf 2>&1 EOF chmod +x /$LND_SVDIR/run.new test -f /$LND_SVDIR/run && diff /$LND_SVDIR/run /$LND_SVDIR/run.new if [ $? -ne 0 ]; then sv -w 600 stop lnd || printf "ERROR: sv stop lnd failed\n" 1>&2 mv /$LND_SVDIR/run.new /$LND_SVDIR/run sv start lnd || printf "ERROR: sv start lnd failed\n" 1>&2 fi rm -f /$LND_SVDIR/run.new # whatever happened above, try to ensure the service is up chmod +x /$LND_SVDIR/run [ ! -f /$LND_SVDIR/down ] && sv start lnd } lnd_cli_install() { mkdir -p /opt/bin cat < /opt/bin/lncli.sh #!/bin/sh set -e cli=$LND_HOME/$LND_VERSION_DIR_AARCH64/lncli exec doas -u lnd \$cli --macaroonpath /ssd/lnd/data/chain/bitcoin/mainnet/admin.macaroon "\$@" EOF chmod +x /opt/bin/lncli.sh } lnd_apply() { lnd_bin_install || return 1 lnd_svc_install || return 1 lnd_cli_install || return 1 }