From 7c9d0f694afdd2185c19294baa05c4c0e4e50b06 Mon Sep 17 00:00:00 2001 From: openoms Date: Sat, 15 Aug 2020 15:15:40 +0100 Subject: [PATCH] offers: add the offer book and improve logic fixes: https://github.com/rootzoll/raspiblitz/issues/1425 --- scripts/menu.offerbook.sh | 110 ++++++++++++++++++++++++++++++++++++ scripts/menu.sh | 31 ++-------- scripts/start.ob-watcher.sh | 38 ------------- 3 files changed, 115 insertions(+), 64 deletions(-) create mode 100755 scripts/menu.offerbook.sh delete mode 100755 scripts/start.ob-watcher.sh diff --git a/scripts/menu.offerbook.sh b/scripts/menu.offerbook.sh new file mode 100755 index 0000000..bc1614e --- /dev/null +++ b/scripts/menu.offerbook.sh @@ -0,0 +1,110 @@ +#!/bin/bash + +source /home/joinmarket/joinin.conf +source /home/joinmarket/menu.functions.sh + +function stopOfferBook() { +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 +} + +function showOfferBookAddress() { +running=$(ps $(pidof python) | grep -c "python ob-watcher.py") +if [ $running -gt 0 ]; then + TOR_ADDRESS=$(sudo cat $HiddenServiceDir/ob-watcher/hostname) + whiptail --title "Started the ob-watcher service" \ + --msgbox "\nVisit the address in the Tor Browser:\n$TOR_ADDRESS" 9 66 +else + startOfferBook + showOfferBookAddress +fi +} + +function startOfferBook() { +echo "# Checking matplotlib" +. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate +depend=$(pip show matplotlib | grep -c "matplotlib") +if [ $depend -lt 1 ]; then + pip install matplotlib +else + echo "matplotlib is installed" +fi + +stopOfferBook + +echo " +[Unit] +Description=ob-watcher + +[Service] +WorkingDirectory=/home/joinmarket/joinmarket-clientserver/scripts/obwatch +ExecStart=/bin/sh -c \ +'. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate && \ +python ob-watcher.py' +User=joinmarket +Group=joinmarket +Type=simple +KillMode=process +TimeoutSec=600 +Restart=no + +[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 + +# create the Hidden Service +/home/joinmarket/install.hiddenservice.sh ob-watcher 80 62601 + +echo "" +echo "Started watching the Offer 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 140 + +} + +# BASIC MENU INFO +HEIGHT=11 +WIDTH=48 +CHOICE_HEIGHT=20 +TITLE="JoininBox" +MENU=" +Offer Book options:" +OPTIONS=() +BACKTITLE="JoininBox GUI" + +# Basic Options +OPTIONS+=(\ + START "Start watching locally" \ + SHOW "Show the local Offer Book address" \ + STOP "Stop the background process" +) + +CHOICE=$(dialog --clear \ + --backtitle "$BACKTITLE" \ + --title "$TITLE" \ + --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT \ + "${OPTIONS[@]}" \ + 2>&1 >/dev/tty) + +case $CHOICE in + START) + startOfferBook + ;; + SHOW) + showOfferBookAddress + ;; + STOP) + stopOfferBook + echo "Press ENTER to return to the menu..." + read key + ;; +esac \ No newline at end of file diff --git a/scripts/menu.sh b/scripts/menu.sh index 7f0ea50..9e02843 100755 --- a/scripts/menu.sh +++ b/scripts/menu.sh @@ -45,7 +45,7 @@ OPTIONS+=(\ FREEZE "Exercise coin control within a mixdepth" \ PAYJOIN "Send/Receive between JoinMarket wallets" "" "" - OFFERS "Watch the offer book locally" \ + OFFERS "Watch the Offer Book locally" \ "" "" CONFIG "Edit the joinmarket.cfg" \ UPDATE "Update the JoininBox scripts and menu" \ @@ -87,8 +87,6 @@ Leave the box empty to show the addresses in all five" 10 64 2> $mixdepth ;; QTGUI) /home/joinmarket/info.qtgui.sh - echo "Returning to the menu..." - sleep 1 /home/joinmarket/menu.sh ;; MAKER) @@ -97,35 +95,18 @@ Leave the box empty to show the addresses in all five" 10 64 2> $mixdepth ;; SEND) /home/joinmarket/menu.send.sh + /home/joinmarket/menu.sh ;; FREEZE) /home/joinmarket/menu.freeze.sh + /home/joinmarket/menu.sh ;; PAYJOIN) /home/joinmarket/menu.payjoin.sh + /home/joinmarket/menu.sh ;; OFFERS) - #TODO show hidden service only if already running - /home/joinmarket/start.ob-watcher.sh - errorOnInstall=$? - if [ ${errorOnInstall} -eq 0 ]; then - TOR_ADDRESS=$(sudo cat $HiddenServiceDir/ob-watcher/hostname) - whiptail --title "Started the ob-watcher service" \ - --msgbox "\nVisit the address in the Tor Browser:\n$TOR_ADDRESS" 9 66 - else - DIALOGRC=.dialogrc.onerror dialog --title "Error during install" \ - --msgbox "\nPlease search or report at:\n https://github.com/openoms/joininbox/issues" 7 56 - fi - echo "" - echo "Started watching the Offer 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 140 - echo "Returning to the menu..." - sleep 1 + /home/joinmarket/menu.offerbook.sh /home/joinmarket/menu.sh ;; CONFIG) @@ -143,8 +124,6 @@ Leave the box empty to show the addresses in all five" 10 64 2> $mixdepth ;; UPDATE) /home/joinmarket/update.joininbox.sh - echo "Returning to the menu..." - sleep 1 /home/joinmarket/menu.sh ;; X) diff --git a/scripts/start.ob-watcher.sh b/scripts/start.ob-watcher.sh deleted file mode 100755 index aaf6919..0000000 --- a/scripts/start.ob-watcher.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -#install dependency -. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate - -echo "installing matplotlib" -pip install matplotlib - -SCRIPT="ob-watcher" - -sudo systemctl stop $SCRIPT -sudo systemctl disable $SCRIPT 2>/dev/null -sleep 5 - -echo " -[Unit] -Description=$SCRIPT - -[Service] -WorkingDirectory=/home/joinmarket/joinmarket-clientserver/scripts/obwatch -ExecStart=/bin/sh -c \ -'. /home/joinmarket/joinmarket-clientserver/jmvenv/bin/activate && \ -python ob-watcher.py' -User=joinmarket -Group=joinmarket -Type=simple -KillMode=process -TimeoutSec=600 -Restart=no - -[Install] -WantedBy=multi-user.target -" | sudo tee /etc/systemd/system/$SCRIPT.service 1>/dev/null -sudo systemctl enable $SCRIPT 2>/dev/null -sudo systemctl start $SCRIPT - -#create Hidden Service -/home/joinmarket/install.hiddenservice.sh ob-watcher 80 62601 \ No newline at end of file