joininbox/scripts/menu.orderbook.sh

150 lines
3.3 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
2022-09-28 11:52:15 +01:00
# menu.orderbook.sh -> starts the menu
# menu.orderbook.sh startOrderBookService starts the orderBookService
source /home/joinmarket/joinin.conf
source /home/joinmarket/_functions.sh
# the bitcoind wallet needs to be loaded for the ob-watcher.py also
checkRPCwallet
2020-10-27 15:07:16 +00:00
function stopOrderBook() {
echo "# Stopping the ob-watcher background service"
pkill -sigint -f "python ob-watcher.py"
sudo systemctl stop ob-watcher
sudo systemctl disable ob-watcher 2>/dev/null
}
2020-10-27 15:07:16 +00:00
function showOrderBookAddress() {
running=$(ps $(pidof python) | grep -c "python ob-watcher.py")
if [ "$running" -gt 0 ]; then
TOR_ADDRESS=$(sudo cat "$HiddenServiceDir"/ob-watcher/hostname)
clear
echo
echo "The local Order Book instance is running"
echo
2021-03-04 22:57:35 +00:00
echo "Visit the address in the Tor Browser (shown as a QR code also):"
echo "$TOR_ADDRESS"
2021-03-04 22:57:35 +00:00
echo
qrencode -t ANSIUTF8 "$TOR_ADDRESS"
else
startOrderBook
fi
}
2022-09-28 11:52:15 +01:00
function orderBookService() {
stopOrderBook
activateJMvenv
if [ "$(pip list | grep -c matplotlib)" -eq 0 ];then
echo "# Installing optional dependencies"
pip install matplotlib
fi
2022-04-06 19:54:00 +01:00
if [ "${RPCoverTor}" = "on" ];then
tor="torsocks"
else
tor=""
fi
echo "
[Unit]
Description=ob-watcher
[Service]
WorkingDirectory=/home/joinmarket/joinmarket-clientserver/scripts/obwatch
ExecStart=/bin/sh -c \
'. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate && \
2022-04-06 19:54:00 +01:00
$tor python ob-watcher.py'
User=joinmarket
Group=joinmarket
Type=simple
TimeoutSec=600
Restart=always
RestartSec=60
# Hardening measures
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/ob-watcher.service 1>/dev/null
sudo systemctl enable ob-watcher 2>/dev/null
sudo systemctl start ob-watcher
2022-09-28 11:52:15 +01:00
echo "# Started the ob-watcher.service on the local port 62601"
}
function startOrderBook() {
orderBookService
# create the Hidden Service
/home/joinmarket/install.hiddenservice.sh ob-watcher 80 62601
echo
echo "# Started watching the Order Book in the background"
echo
echo "# Showing the systemd status ..."
sleep 3
dialog \
--title "Monitoring the ob-watcher - press CTRL+C to exit" \
--prgbox "sudo journalctl -fn20 -u ob-watcher" 30 200
}
2022-09-28 11:52:15 +01:00
if [ "$1" = startOrderBookService ]; then
orderBookService
exit 0
fi
# BASIC MENU INFO
2020-10-14 09:39:28 +01:00
HEIGHT=9
WIDTH=48
CHOICE_HEIGHT=20
2020-10-27 15:07:16 +00:00
TITLE="Order Book options"
2020-10-14 09:39:28 +01:00
MENU=""
OPTIONS=()
BACKTITLE="JoininBox GUI"
# Basic Options
OPTIONS+=(\
START "Start watching locally" \
2020-10-27 15:07:16 +00:00
SHOW "Show the local Order Book address" \
STOP "Stop the background process"
)
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--ok-label "Select" \
--cancel-label "Back" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
case $CHOICE in
START)
2020-10-27 15:07:16 +00:00
startOrderBook
showOrderBookAddress
echo ""
2020-09-15 14:57:41 +01:00
echo "Press ENTER to return to the menu..."
read key
;;
SHOW)
2020-10-27 15:07:16 +00:00
showOrderBookAddress
echo ""
2020-09-15 14:57:41 +01:00
echo "Press ENTER to return to the menu..."
read key
;;
STOP)
2020-10-27 15:07:16 +00:00
stopOrderBook
echo ""
echo "Press ENTER to return to the menu..."
read key
;;
2022-09-28 11:52:15 +01:00
esac