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

259 lines
11 KiB
Bash
Raw Normal View History

2020-03-23 16:22:00 +00:00
#!/bin/bash
# links:
# https://github.com/JoinMarket-Org/joinmarket-clientserver#quickstart---recommended-installation-method-linux-only
# https://github.com/openoms/bitcoin-tutorials/tree/master/joinmarket
# https://github.com/openoms/joininbox
2021-03-16 22:49:13 +00:00
JMVERSION="v0.8.2"
JBVERSION="v0.3.2"
2020-11-10 23:25:31 +00:00
2020-03-23 16:22:00 +00:00
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "JoinMarket install script to switch JoinMarket on or off"
echo "sudo /home/admin/config.scrips/bonus.joinmarket.sh on|off"
2021-03-16 22:49:13 +00:00
echo "Installs JoinMarket $pinnedVersion with JoininBox $JBVERSION"
2020-03-23 16:22:00 +00:00
exit 1
fi
# check if sudo
if [ "$EUID" -ne 0 ]
then echo "Please run as root (with sudo)"
exit
fi
source /mnt/hdd/raspiblitz.conf
# add default value to raspi config if needed
if ! grep -Eq "^joinmarket=" /mnt/hdd/raspiblitz.conf; then
echo "joinmarket=off" >> /mnt/hdd/raspiblitz.conf
fi
# show info menu
if [ "$1" = "menu" ]; then
whiptail --title " JoinMarket info " --msgbox "
2020-11-27 16:28:55 +00:00
Type: 'jm' in the command line to switch to the dedicated user and start the JoininBox menu.
Notes on usage:
https://github.com/openoms/bitcoin-tutorials/blob/master/joinmarket/README.md
2020-03-24 21:42:49 -07:00
Can log in directly with the 'joinmarket' user via ssh.
The user password is the PASSWORD_B.
" 13 81
exit 0
fi
2020-03-23 16:22:00 +00:00
# switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "*** INSTALL JOINMARKET ***"
# check if running Tor
2020-03-23 16:22:00 +00:00
if [ ${runBehindTor} = on ]; then
2020-08-25 11:13:41 +01:00
echo "# OK, running behind Tor"
2020-03-23 16:22:00 +00:00
else
2020-08-25 11:13:41 +01:00
echo "# Not running Tor"
echo "# Activate Tor from the SERVICES menu before installing JoinMarket."
2020-03-23 16:22:00 +00:00
exit 1
fi
# make sure the Bitcoin Core wallet is on
/home/admin/config.scripts/network.wallet.sh on
2020-03-23 16:22:00 +00:00
if [ ! -f "/home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate" ] ; then
2020-03-28 06:30:14 +00:00
2020-08-25 11:13:41 +01:00
echo "# cleaning before install"
2020-03-28 06:30:14 +00:00
sudo userdel -rf joinmarket 2>/dev/null
2020-08-25 11:13:41 +01:00
echo "# add the 'joinmarket' user"
2020-03-23 16:22:00 +00:00
adduser --disabled-password --gecos "" joinmarket
2020-08-25 11:13:41 +01:00
echo "# setting PASSWORD_B as the password for the 'joinmarket' user"
2020-03-23 16:22:00 +00:00
PASSWORD_B=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcpassword | cut -c 13-)
echo "joinmarket:$PASSWORD_B" | sudo chpasswd
# add to sudo group (required for installation)
adduser joinmarket sudo
# configure sudo for usage without password entry for the joinmarket user
echo 'joinmarket ALL=(ALL) NOPASSWD:ALL' | EDITOR='tee -a' visudo
2020-03-23 16:22:00 +00:00
# make a folder for authorized keys
sudo -u joinmarket mkdir -p /home/joinmarket/.ssh
chmod -R 700 /home/joinmarket/.ssh
# install the command-line fuzzy finder (https://github.com/junegunn/fzf)
bash -c "echo 'source /usr/share/doc/fzf/examples/key-bindings.bash' >> /home/joinmarket/.bashrc"
# store JoinMarket data on HDD
mkdir /mnt/hdd/app-data/.joinmarket 2>/dev/null
# copy old JoinMarket data to app-data
2020-03-27 22:10:51 +00:00
cp -rf /home/admin/joinmarket-clientserver/scripts/wallets /mnt/hdd/app-data/.joinmarket/ 2>/dev/null
2020-03-23 16:22:00 +00:00
chown -R joinmarket:joinmarket /mnt/hdd/app-data/.joinmarket
ln -s /mnt/hdd/app-data/.joinmarket /home/joinmarket/ 2>/dev/null
chown -R joinmarket:joinmarket /home/joinmarket/.joinmarket
# specify wallet.dat in old config for multiwallet for multiwallet support
if [ -f "/home/joinmarket/.joinmarket/joinmarket.cfg" ] ; then
2020-09-28 12:05:15 +01:00
sudo -u joinmarket sed -i "s/^rpc_wallet_file =.*/rpc_wallet_file = wallet.dat/g" \
/home/joinmarket/.joinmarket/joinmarket.cfg
2020-08-25 11:13:41 +01:00
echo "# specified to use wallet.dat in the recovered joinmarket.cfg"
fi
2020-03-23 16:22:00 +00:00
# install joinmarket
cd /home/joinmarket
2020-03-28 00:17:59 +00:00
# PySide2 for armf: https://packages.debian.org/buster/python3-pyside2.qtcore
2020-09-09 15:09:44 +01:00
echo "# installing ARM specific dependencies to run the QT GUI"
2020-09-28 12:05:15 +01:00
sudo apt install -y python3-pyside2.qtcore python3-pyside2.qtgui \
2020-11-10 23:25:31 +00:00
python3-pyside2.qtwidgets zlib1g-dev libjpeg-dev python3-pyqt5 libltdl-dev
# https://github.com/JoinMarket-Org/joinmarket-clientserver/issues/668#issuecomment-717815719
2020-11-18 17:00:55 +01:00
sudo apt install -y build-essential automake pkg-config libffi-dev python3-dev libgmp-dev
2020-11-10 23:25:31 +00:00
sudo -u joinmarket pip install libtool asn1crypto cffi pycparser coincurve
2020-08-25 11:13:41 +01:00
echo "# installing JoinMarket"
2020-03-28 00:17:59 +00:00
sudo -u joinmarket git clone https://github.com/Joinmarket-Org/joinmarket-clientserver
cd joinmarket-clientserver
2021-03-16 22:49:13 +00:00
sudo -u joinmarket git reset --hard $JMVERSION
# make install.sh set up jmvenv with -- system-site-packages
2020-09-09 15:09:44 +01:00
# and import the PySide2 armf package from the system
2020-09-28 12:05:15 +01:00
sudo -u joinmarket sed -i \
"s#^ virtualenv -p \"\${python}\" \"\${jm_source}/jmvenv\" || return 1#\
2020-09-09 15:09:44 +01:00
virtualenv --system-site-packages -p \"\${python}\" \"\${jm_source}/jmvenv\" || return 1 ;\
/home/joinmarket/joinmarket-clientserver/jmvenv/bin/python -c \'import PySide2\'\
#g" install.sh
2020-09-28 12:05:15 +01:00
# do not stop at installing debian dependencies
sudo -u joinmarket sed -i \
"s#^ if ! sudo apt-get install \${deb_deps\[@\]}; then#\
if ! sudo apt-get install -y \${deb_deps\[@\]}; then#g" install.sh
2020-09-09 15:09:44 +01:00
# don't install PySide2 - using the system-site-package instead
sudo -u joinmarket sed -i "s#^PySide2##g" requirements/gui.txt
# don't install PyQt5 - using the system package instead
sudo -u joinmarket sed -i "s#^PyQt5==5.14.2##g" requirements/gui.txt
sudo -u joinmarket ./install.sh --with-qt
2021-03-16 22:49:13 +00:00
echo "# installed JoinMarket $JMVERSION"
2020-06-19 11:45:46 +01:00
2020-08-25 11:13:41 +01:00
echo "# adding the joininbox menu"
2020-06-19 11:45:46 +01:00
sudo rm -rf /home/joinmarket/joininbox
sudo -u joinmarket git clone https://github.com/openoms/joininbox.git /home/joinmarket/joininbox
# check the latest at:
# https://github.com/openoms/joininbox/releases/
2021-03-16 22:49:13 +00:00
sudo -u joinmarket git reset --hard $JBVERSION
2020-06-19 11:45:46 +01:00
sudo -u joinmarket cp /home/joinmarket/joininbox/scripts/* /home/joinmarket/
sudo -u joinmarket cp /home/joinmarket/joininbox/scripts/.* /home/joinmarket/ 2>/dev/null
sudo chmod +x /home/joinmarket/*.sh
# Tor config
# add the joinmarket user to the Tor group
usermod -a -G debian-tor joinmarket
# fix Tor config
sudo sed -i "s:^CookieAuthFile*:#CookieAuthFile:g" /etc/tor/torrc
if ! grep -Eq "^CookieAuthentication 1" /etc/tor/torrc; then
echo "CookieAuthentication 1" | sudo tee -a /etc/tor/torrc
sudo systemctl restart tor
2020-06-19 11:45:46 +01:00
fi
if ! grep -Eq "^AllowOutboundLocalhost 1" /etc/tor/torsocks.conf; then
2020-06-19 11:45:46 +01:00
echo "AllowOutboundLocalhost 1" | sudo tee -a /etc/tor/torsocks.conf
sudo systemctl restart tor
fi
# joinin.conf settings
sudo -u joinmarket touch /home/joinmarket/joinin.conf
# add default Tor value to joinin.conf if needed
if ! grep -Eq "^runBehindTor" /home/joinmarket/joinin.conf; then
echo "runBehindTor=off" | sudo -u joinmarket tee -a /home/joinmarket/joinin.conf
fi
# setting Tor value in joinin config
if grep -Eq "^runBehindTor=on" /mnt/hdd/raspiblitz.conf; then
2020-06-19 11:45:46 +01:00
sudo -u joinmarket sed -i "s/^runBehindTor=.*/runBehindTor=on/g" /home/joinmarket/joinin.conf
fi
2020-08-25 11:13:41 +01:00
echo "# setting the autostart script for joinmarket"
2020-06-19 11:45:46 +01:00
echo "
# automatically start startup.sh for joinmarket unless
# when running in a tmux session
if [ -z \"\$TMUX\" ]; then
/home/joinmarket/startup.sh
fi
# always activate jmvenv with PySide2 and cd to scripts'
. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate
/home/joinmarket/joinmarket-clientserver/jmvenv/bin/python -c \"import PySide2\"
cd /home/joinmarket/joinmarket-clientserver/scripts/
# shortcut commands
source /home/joinmarket/_commands.sh
# automatically start main menu for joinmarket unless
# when running in a tmux session
if [ -z \"\$TMUX\" ]; then
/home/joinmarket/menu.sh
fi
2020-06-19 12:34:35 +01:00
" | sudo -u joinmarket tee -a /home/joinmarket/.bashrc
2020-03-23 16:22:00 +00:00
cat > /home/admin/startup.sh <<EOF
# check for joinmarket.cfg
2020-06-19 11:45:46 +01:00
if [ ! -f "/home/joinmarket/.joinmarket/joinmarket.cfg" ] ; then
2020-08-25 11:13:41 +01:00
echo "# generating the joinmarket.cfg"
2020-03-23 16:22:00 +00:00
echo ""
. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate &&\
cd /home/joinmarket/joinmarket-clientserver/scripts/
python wallet-tool.py generate --datadir=/home/joinmarket/.joinmarket
sudo chmod 600 /home/joinmarket/.joinmarket/joinmarket.cfg || exit 1
echo ""
2020-08-25 11:13:41 +01:00
echo "# editing the joinmarket.cfg"
sed -i "s/^rpc_user =.*/rpc_user = raspibolt/g" /home/joinmarket/.joinmarket/joinmarket.cfg
2020-03-23 16:22:00 +00:00
PASSWORD_B=\$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcpassword | cut -c 13-)
sed -i "s/^rpc_password =.*/rpc_password = \$PASSWORD_B/g" /home/joinmarket/.joinmarket/joinmarket.cfg
2020-03-23 16:22:00 +00:00
echo "Filled the bitcoin RPC password (PASSWORD_B)"
sed -i "s/^rpc_wallet_file =.*/rpc_wallet_file = wallet.dat/g" /home/joinmarket/.joinmarket/joinmarket.cfg
echo "Using the bitcoind wallet: wallet.dat"
2020-03-23 16:22:00 +00:00
#communicate with IRC servers via Tor
sed -i "s/^host = irc.darkscience.net/#host = irc.darkscience.net/g" /home/joinmarket/.joinmarket/joinmarket.cfg
sed -i "s/^#host = darksci3bfoka7tw.onion/host = darksci3bfoka7tw.onion/g" /home/joinmarket/.joinmarket/joinmarket.cfg
sed -i "s/^host = irc.hackint.org/#host = irc.hackint.org/g" /home/joinmarket/.joinmarket/joinmarket.cfg
sed -i "s/^#host = ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion/host = ncwkrwxpq2ikcngxq3dy2xctuheniggtqeibvgofixpzvrwpa77tozqd.onion/g" /home/joinmarket/.joinmarket/joinmarket.cfg
sed -i "s/^socks5 = false/#socks5 = false/g" /home/joinmarket/.joinmarket/joinmarket.cfg
sed -i "s/^#socks5 = true/socks5 = true/g" /home/joinmarket/.joinmarket/joinmarket.cfg
sed -i "s/^#port = 6667/port = 6667/g" /home/joinmarket/.joinmarket/joinmarket.cfg
sed -i "s/^#usessl = false/usessl = false/g" /home/joinmarket/.joinmarket/joinmarket.cfg
2020-08-25 11:13:41 +01:00
echo "# edited the joinmarket.cfg to communicate over Tor only."
2020-03-23 16:22:00 +00:00
fi
EOF
mv /home/admin/startup.sh /home/joinmarket/startup.sh
chown joinmarket:joinmarket /home/joinmarket/startup.sh
chmod +x /home/joinmarket/startup.sh
2020-03-23 16:22:00 +00:00
else
echo "JoinMarket is already installed"
echo ""
2020-03-23 16:22:00 +00:00
fi
if [ -f "/home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate" ] ; then
2020-03-24 21:42:49 -07:00
# setting value in raspi blitz config
sudo sed -i "s/^joinmarket=.*/joinmarket=on/g" /mnt/hdd/raspiblitz.conf
# starting info
2020-03-23 16:22:00 +00:00
echo ""
echo "Start to use by logging in to the 'joinmarket' user with:"
echo "sudo su joinmarket"
2020-03-23 16:22:00 +00:00
echo ""
echo "If logging in directly via ssh the password is the PASSWORD_B"
echo ""
else
echo " Failed to install JoinMarket"
exit 1
fi
2020-06-19 11:45:46 +01:00
exit 0
2020-03-23 16:22:00 +00:00
fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# setting value in raspi blitz config
sudo sed -i "s/^joinmarket=.*/joinmarket=off/g" /mnt/hdd/raspiblitz.conf
if [ -f "/home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate" ] ; then
echo "*** REMOVING JOINMARKET ***"
sudo userdel -rf joinmarket 2>/dev/null
2020-08-25 11:13:41 +01:00
echo "# OK JoinMarket is removed"
2020-03-23 16:22:00 +00:00
else
echo "JoinMarket is not installed."
fi
exit 0
fi
echo "FAIL - Unknown Parameter $1"
2020-09-28 12:05:15 +01:00
echo "may need reboot to run"
exit 1