From 459c966a711935bc50d8e0ff2826fb31ecec416e Mon Sep 17 00:00:00 2001 From: raulcano Date: Mon, 22 Mar 2021 19:36:21 -0300 Subject: [PATCH] adds service and command to download whitepaper (#2081) --- home.admin/00settingsMenuServices.sh | 17 +++++ home.admin/_commands.sh | 7 ++ home.admin/config.scripts/bonus.whitepaper.sh | 75 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 home.admin/config.scripts/bonus.whitepaper.sh diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh index b47cd5cc6..ee5faa922 100755 --- a/home.admin/00settingsMenuServices.sh +++ b/home.admin/00settingsMenuServices.sh @@ -20,6 +20,7 @@ if [ ${#pyblock} -eq 0 ]; then pyblock="off"; fi if [ ${#thunderhub} -eq 0 ]; then thunderhub="off"; fi if [ ${#sphinxrelay} -eq 0 ]; then sphinxrelay="off"; fi if [ ${#lit} -eq 0 ]; then lit="off"; fi +if [ ${#whitepaper} -eq 0 ]; then whitepaper="off"; fi # show select dialog echo "run dialog ..." @@ -38,6 +39,7 @@ OPTIONS+=(j 'JoinMarket' ${joinmarket}) OPTIONS+=(o 'Balance of Satoshis' ${bos}) OPTIONS+=(x 'Sphinx-Relay' ${sphinxrelay}) OPTIONS+=(y 'PyBLOCK' ${pyblock}) +OPTIONS+=(w 'Download Bitcoin Whitepaper' ${whitepaper}) CHOICES=$(dialog --title ' Additional Services ' --checklist ' use spacebar to activate/de-activate ' 20 45 12 "${OPTIONS[@]}" 2>&1 >/dev/tty) @@ -393,6 +395,21 @@ else echo "Mempool Explorer Setting unchanged." fi +# Whitepaper process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "w") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${whitepaper}" != "${choice}" ]; then + echo "Whitepaper setting changed .." + anychange=1 + sudo -u admin /home/admin/config.scripts/bonus.whitepaper.sh ${choice} + source /mnt/hdd/raspiblitz.conf + if [ "${whitepaper}" = "on" ]; then + sudo -u admin /home/admin/config.scripts/bonus.whitepaper.sh menu + fi +else + echo "Whitepaper setting unchanged." +fi + if [ ${anychange} -eq 0 ]; then dialog --msgbox "NOTHING CHANGED!\nUse Spacebar to check/uncheck services." 8 58 exit 0 diff --git a/home.admin/_commands.sh b/home.admin/_commands.sh index d6e050b93..2ab83f858 100755 --- a/home.admin/_commands.sh +++ b/home.admin/_commands.sh @@ -313,3 +313,10 @@ function notifyme() { content="${1:-Notified}" /home/admin/config.scripts/blitz.notify.sh send "${content}" } + +# command: whitepaper +# downloads the whitepaper from the blockchain to /home/admin/bitcoin.pdf +function whitepaper() { + cd /home/admin/config.scripts + ./bonus.whitepaper.sh on +} \ No newline at end of file diff --git a/home.admin/config.scripts/bonus.whitepaper.sh b/home.admin/config.scripts/bonus.whitepaper.sh new file mode 100644 index 000000000..7ab55a164 --- /dev/null +++ b/home.admin/config.scripts/bonus.whitepaper.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +WhitepaperVersion="v0.1" +DownloadPath="/home/admin/" +WhitepaperFilename="bitcoin.pdf" + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "# config script to download the Bitcoin whitepaper to your Raspiblitz directly from the blockchain" + echo "# on: downloads the Whitepaper to $DownloadPath$WhitepaperFilename" + echo "# off: deletes the Whitepaper from $DownloadPath$WhitepaperFilename" + echo "# bonus.whitepaper.sh [on|off|menu]" + echo "# Whitepaper downloader script $WhitepaperVersion" + exit 1 +fi + +source /mnt/hdd/raspiblitz.conf + +# add default value to raspi config if needed +if ! grep -Eq "^whitepaper=" /mnt/hdd/raspiblitz.conf; then + echo "whitepaper=off" >> /mnt/hdd/raspiblitz.conf +fi + +# show info menu +if [ "$1" = "menu" ]; then + dialog --title " Whitepaper Info" --msgbox " +This service downloads Satoshi's Whitepaper directly from the blockchain. +When enabled, the Whitepaper is downloaded to $DownloadPath$WhitepaperFilename +When disabled, the Whitepaper is deleted from $DownloadPath$WhitepaperFilename +Also, use the command 'whitepaper' from the command line to download the whitepaper directly +" 10 75 + exit 0 +fi + + +# switch on +if [ "$1" = "1" ] || [ "$1" = "on" ]; then + + echo "" + echo "# ***" + echo "# Downloading the Whitepaper to $DownloadPath$WhitepaperFilename..." + echo "# ***" + echo "" + + sudo -u bitcoin bitcoin-cli getblock 00000000000000ecbbff6bafb7efa2f7df05b227d5c73dca8f2635af32a2e949 0 | tail -c+92167 | for ((o=0;o<946;++o)) ; do read -rN420 x ; echo -n ${x::130}${x:132:130}${x:264:130} ; done | xxd -r -p | tail -c+9 | head -c184292 > $DownloadPath/$WhitepaperFilename + + # setting value in raspi blitz config + sudo sed -i "s/^whitepaper=.*/whitepaper=on/g" /mnt/hdd/raspiblitz.conf + + echo "# OK - Whitepaper downloaded to $DownloadPath$WhitepaperFilename" + + exit 0 +fi + +# switch off +if [ "$1" = "0" ] || [ "$1" = "off" ]; then + isInstalled=1 + if [ ${isInstalled} -eq 1 ]; then + + echo "" + echo "# ***" + echo "# Removing the Whitepaper from $DownloadPath$WhitepaperFilename..." + echo "# ***" + echo "" + # setting value in raspi blitz config + sudo sed -i "s/^whitepaper=.*/whitepaper=off/g" /mnt/hdd/raspiblitz.conf + + rm $DownloadPath/$WhitepaperFilename + + echo "# OK - Whitepaper removed." + else + echo "# The Whitepaper has not been downloaded yet." + fi + exit 0 +fi \ No newline at end of file