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

216 lines
7.0 KiB

3 years ago
#!/bin/sh
# Bare Metal Alchemist, 2022
#############################################
# Gold - ☼ #
#############################################
# One of the principal goals of alchemy is the transmutation of base
# metals into gold. Likewise. one of the purposes of these scripts
# is the transmutation of bare metal into digital gold, AKA bitcoin
# This ingredient is to be used whenever a recipe requires use of
# the Bitcoin ecosystem
install_bitcoin() {
say "${BOLD}Installing Bitcoin Core${RESET}"
3 years ago
3 years ago
# We're building bitcoin from source here. It might be slower than
# downloading the pre-built binaries but this is more reliable
if [ ! -e 🜍/bitcoin-22.0* ]; then
wget https://bitcoincore.org/bin/bitcoin-core-22.0/bitcoin-22.0.tar.gz -P 🜍/
3 years ago
fi
3 years ago
# This still relies on package management though
case $DISTRO in
"arch")
install_if_needed boost autoconf
;;
"debian")
install_if_needed build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libssl-dev libevent-dev libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev libminiupnpc-dev libzmq3-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler git libsqlite3-dev ccache
;;
*)
say "hol up, I don't know what to do with $DISTRO"
ask_for nothing "press enter to continue, at your own PERIL!!"
;;
esac
3 years ago
3 years ago
tar -xvf 🜍/bitcoin-22.0.tar.gz
sleep 1
cd bitcoin-22.0
3 years ago
chmod +x autogen.sh
./autogen.sh
./configure --without-bdb # Someday, someone will complain here
make
sudo make install
cd ..
3 years ago
rm -rf bitcoin-22.0
}
install_lightning() {
say "${BOLD}Installing lightningd${RESET}"
3 years ago
git clone https://github.com/ElementsProject/lightning.git ./lightning
cd lightning
3 years ago
git checkout v0.10.2
./configure
# The latest version of mistune breaks lightning install
pip uninstall mistune
pip install --user mistune==0.8.4
pip install --user mrkd
make
sudo make install
cd ..
3 years ago
rm -rf lightning
}
install_clboss() {
say "${BOLD}Installing clboss${RESET}"
3 years ago
git clone https://github.com/ZmnSCPxj/clboss.git ./clboss
pushd ./clboss
git checkout 0.11B
mkdir -p m4
autoreconf -fi
./configure
make
sudo make install
popd
rm -rf clboss
}
configure_bitcoin() {
say "${BOLD}Configuring Bitcoin${RESET}"
3 years ago
mkdir -p ~/.bitcoin
if [ -f $HOME/.bitcoin/bitcoin.conf ]; then
say "Looks like you already have a ${BLUE}bitcoin.conf${RESET} file!"
say ""
3 years ago
cat $HOME/.bitcoin/bitcoin.conf
say ""
ask_for btc_reconf "Would you like to reset it? ${BLUE}(y/n)${RESET}: "
3 years ago
case $btc_reconf in
"y" | "Y")
cp resources/sample_bitcoin.conf $HOME/.bitcoin/bitcoin.conf
say 'Reset bitcoin configuration file'
3 years ago
;;
"n" | "N")
say "Cool, we'll leave it as is then".
3 years ago
;;
esac
else
cp resources/sample_bitcoin.conf $HOME/.bitcoin/bitcoin.conf
say 'Created default bitcoin config'
3 years ago
fi
if [ -n "$BTC_PASS" ]; then
ask_for new_deets "Would you like to generate new authentication credentials for bitcoin? ${BLUE} (y/n): ${RESET}"
case $new_deets in
"y"|"Y")
AUTHDEETS=$(python3 scripts/rpcauth.py ao)
AUTHLINE=$(say "$AUTHDEETS" | sed '2q;d' )
PASSLINE=$(say "$AUTHDEETS" | sed '4q;d' )
NEWCREDS=1
remember "BTC_PASS=${PASSLINE}"
say "${GREEN}New credentials!${RESET}"
;;
"n"|"N")
say "Skipping re-credentulation"
;;
esac
else
AUTHDEETS=$(python3 scripts/rpcauth.py ao)
AUTHLINE=$(say "$AUTHDEETS" | sed '2q;d' )
PASSLINE=$(say "$AUTHDEETS" | sed '4q;d' )
NEWCREDS=1
remember "BTC_PASS=${PASSLINE}"
fi
if [ -n "$NEWCREDS" ]; then
sed -iE -e "s/BTC_LOGIN|^rpcauth.*/${AUTHLINE}/" $HOME/.bitcoin/bitcoin.conf
fi
say ""
3 years ago
ask_for prune "Next question - would you like to operate bitcoin in pruned mode? \
This reduces its file size from ~500GB to something more portable ${BLUE}(y/n)${RESET}: "
say ""
case $prune in
y | Y)
say "Let's ${GREEN}enable pruning${RESET} to keep the file size down, then."
prune_size=0
while [ "$prune_size" -lt 550 ]; do
ask_for prune_size "How many Mb are you willing to put towards btc? Min 550: "
done
sed -i "s/txindex=1/prune=${prune_size}/" $HOME/.bitcoin/bitcoin.conf
;;
*)
say "Okay great! We'll leave the bitcoin config it as it is."
;;
esac
}
3 years ago
configure_lightning() {
mkdir -p $HOME/.lightning
if [ -f $HOME/.lightning/config ]; then
say "Looks like you already have a ${BLUE}lightning config${RESET} file!"
say ""
3 years ago
cat $HOME/.lightning/config
say ""
ask_for ln_reconf "Would you like to reset it? ${BLUE}(y/n)${RESET}: "
3 years ago
case $ln_reconf in
"y" | "Y")
cp resources/sample_lightning_config $HOME/.lightning/config
say "${GREEN}Reset lightning configuration file${RESET}"
3 years ago
;;
"n" | "N")
say "Cool, we'll leave it as is then".
3 years ago
;;
esac
else
cp resources/sample_lightning_config $HOME/.lightning/config
say "${GREEN}Created default lightning config${RESET}"
3 years ago
fi
say ""
ask_for clboss_enable "Would you like to use clboss to automatically open lightning channels? ${BLUE}(y/n)${RESET}: "
3 years ago
case $clboss_enable in
"y" | "Y")
if ! check_for clboss; then
install_clboss
fi
3 years ago
sed -i "s/#plugin/plugin/" $HOME/.lightning/config
sed -i "s/#log/log/" $HOME/.lightning/config
echo ""
say "${GREEN}clboss successfully configured!${RESET}"
3 years ago
;;
"n" | "N")
say ""
say "Sounds good. You might want to open some channels manually to participate in the network!".
3 years ago
;;
esac
3 years ago
}
bitcoin_is_synced() {
if [ -f "$HOME/.bitcoin/debug.log" ]; then
progress=$(tac ~/.bitcoin/debug.log | grep -m1 UpdateTip | awk '{print $10}')
case $progress in
*"=1"*)
say "Bitcoin is synced!"
return 0
;;
*)
say "Bitcoin is not synced yet"
return 1
;;
esac
else
say "Not sure where your bitcoin log is!"
return 2
fi
}
3 years ago
GOLD=1