You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.4 KiB
Plaintext

BITCOIN_CORE_VERSION_DIR_AARCH64=bitcoin-25.1
BITCOIN_CORE_URL_AARCH64=https://bitcoincore.org/bin/bitcoin-core-25.1/bitcoin-25.1-aarch64-linux-gnu.tar.gz
BITCOIN_CORE_SHA256_AARCH64=69b49bd4eda484a8b8e0e806649e5b7ae9b93b3dbb9889af23696437359bc52c
# binaries and config root; data is elsewhere, in /ssd/bitcoind as per conf file.
BITCOIN_HOME=/home/bitcoind
# no root slash since it's combined with other path prefixes.
BITCOIN_SVDIR=etc/sv/bitcoind
bitcoin_core_bin_install() {
cd $BITCOIN_HOME
local targz=$BITCOIN_CORE_VERSION_DIR_AARCH64.tar.gz
test -f $BITCOIN_CORE_VERSION_DIR_AARCH64/bin/bitcoind && return 0;
curl -sSL -o $targz "$BITCOIN_CORE_URL_AARCH64"
if [ $? -ne 0 ]; then
printf "ERROR: unable to download $BITCOIN_CORE_URL_AARCH64\n" 1>&2
return 1
fi
printf "$BITCOIN_CORE_SHA256_AARCH64 $targz" | sha256sum --check
[ $? -ne 0 ] && return 1
tar -C $BITCOIN_HOME --no-same-owner -xf $targz
rm -f $targz
return $?
}
bitcoind_svc_install() {
# service directories
mkdir -p /$BITCOIN_SVDIR
mkdir -p /$BITCOIN_SVDIR/log
# logging facility
if [ ! -f /$BITCOIN_SVDIR/log/run ]; then
cp $SYSUPDATES_ROOTDIR/files/$BITCOIN_SVDIR/log/run /$BITCOIN_SVDIR/log/
chmod +x /$BITCOIN_SVDIR/log/run
fi
# the actual bitcoin service
cat <<EOF > /$BITCOIN_SVDIR/run.new
#!/bin/sh
exec chpst -u bitcoind $BITCOIN_HOME/$BITCOIN_CORE_VERSION_DIR_AARCH64/bin/bitcoind -conf=$BITCOIN_HOME/mainnet.conf 2>&1
EOF
chmod +x /$BITCOIN_SVDIR/run.new
test -f /$BITCOIN_SVDIR/run && diff /$BITCOIN_SVDIR/run /$BITCOIN_SVDIR/run.new
if [ $? -ne 0 ]; then
mv /$BITCOIN_SVDIR/run.new /$BITCOIN_SVDIR/run
# don't touch the actual service if on manual control - the down file
test -f /$BITCOIN_SVDIR/down && return 0
sv -w 600 stop bitcoind || printf "ERROR: sv stop bitcoind failed\n" 1>&2
sv start bitcoind || printf "ERROR: sv start bitcoind failed\n" 1>&2
fi
rm -f /$BITCOIN_SVDIR/run.new
}
bitcoin_cli_install() {
mkdir -p /opt/bin
cat <<EOF > /opt/bin/bitcoin-cli.sh
#!/bin/sh
set -eu
CLI=$BITCOIN_HOME/$BITCOIN_CORE_VERSION_DIR_AARCH64/bin/bitcoin-cli
DATA=/ssd/bitcoind/mainnet
CHAIN=main
exec doas -u bitcoind \$CLI -datadir=\$DATA -chain=\$CHAIN "\$@"
EOF
chmod +x /opt/bin/bitcoin-cli.sh
}
bitcoin_apply() {
bitcoin_core_bin_install || return 1
bitcoind_svc_install || return 1
bitcoin_cli_install || return 1
}