From f8f7e51a536ed5517d37321b742d54e3e071e3bc Mon Sep 17 00:00:00 2001 From: itchymax Date: Wed, 18 May 2022 17:18:27 +1000 Subject: [PATCH 1/5] Add ItchySats Service --- README.md | 1 + home.admin/00mainMenu.sh | 6 + home.admin/00settingsMenuServices.sh | 18 +- home.admin/_provision_.sh | 9 + home.admin/config.scripts/bonus.itchysats.sh | 265 +++++++++++++++++++ 5 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 home.admin/config.scripts/bonus.itchysats.sh diff --git a/README.md b/README.md index 46cde3c8c..8a3191819 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ There are further Services that can be switched on: * **CL plugin: Sparko** (WalletUI & HTTP-RPC bridge) [details](https://github.com/fiatjaf/sparko#the-sparko-plugin) * **CL plugin: CLBOSS** (Automated Node Manager) [details](https://github.com/ZmnSCPxj/clboss#clboss-the-c-lightning-node-manager) * **Tallycoin Connect** (Use Tallycoin with your own node) [details](https://github.com/djbooth007/tallycoin_connect) +* **ItchySats** (Non-custodial peer-to-peer CFD trading) [details](https://github.com/itchysats/itchysats) You can connect the following Wallet-Apps to your RaspiBlitz: diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index cdc388edc..4aa474cdf 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -153,6 +153,9 @@ fi if [ "${tallycoinConnect}" == "on" ]; then OPTIONS+=(TALLY "Tallycoin Connect") fi +if [ "${itchysats}" == "on" ]; then + OPTIONS+=(ITCHYSATS "ItchySats") +fi # dont offer to switch to "testnet view for now" - so no wswitch back to mainnet needed #if [ ${chain} != "main" ]; then @@ -303,6 +306,9 @@ case $CHOICE in HELIPAD) sudo /home/admin/config.scripts/bonus.helipad.sh menu ;; + ITCHYSATS) + sudo /home/admin/config.scripts/bonus.itchysats.sh menu + ;; CHANTOOLS) sudo /home/admin/config.scripts/bonus.chantools.sh menu ;; diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh index 99e80293d..49dc2938f 100755 --- a/home.admin/00settingsMenuServices.sh +++ b/home.admin/00settingsMenuServices.sh @@ -29,6 +29,7 @@ if [ ${#spark} -eq 0 ]; then spark="off"; fi if [ ${#tallycoinConnect} -eq 0 ]; then tallycoinConnect="off"; fi if [ ${#helipad} -eq 0 ]; then helipad="off"; fi if [ ${#bitcoinminds} -eq 0 ]; then bitcoinminds="off"; fi +if [ ${#itchysats} -eq 0 ]; then itchysats="off"; fi # show select dialog echo "run dialog ..." @@ -45,9 +46,9 @@ if [ "${network}" == "bitcoin" ]; then OPTIONS+=(j 'BTC JoinMarket+JoininBox menu' ${joinmarket}) OPTIONS+=(w 'BTC Download Bitcoin Whitepaper' ${whitepaper}) OPTIONS+=(v 'BTC Install BitcoinMinds.org' ${bitcoinminds}) + OPTIONS+=(u 'BTC Install ItchySats' ${itchysats}) fi - # available for both LND & c-lightning if [ "${lnd}" == "on" ] || [ "${cl}" == "on" ]; then OPTIONS+=(i 'LNbits (Lightning Accounts)' ${LNBits}) @@ -578,6 +579,21 @@ else echo "# Spark Wallet on mainnet Setting unchanged." fi +# ItchySats process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "u") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${itchysats}" != "${choice}" ]; then + echo "ItchySats setting changed .." + anychange=1 + sudo -u admin /home/admin/config.scripts/bonus.itchysats.sh ${choice} + if [ "${choice}" = "on" ]; then + sudo systemctl start itchysats + sudo -u admin /home/admin/config.scripts/bonus.itchysats.sh menu + fi +else + echo "ItchySats 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/_provision_.sh b/home.admin/_provision_.sh index 8ce2aa5a0..2ee7ec7c7 100755 --- a/home.admin/_provision_.sh +++ b/home.admin/_provision_.sh @@ -724,6 +724,15 @@ else echo "Provisioning bitcoinminds.org - keep default" >> ${logFile} fi +# itchysats +if [ "${itchysats}" = "on" ]; then + echo "Provisioning ItchySats - run config script" >> ${logFile} + sudo sed -i "s/^message=.*/message='Setup ItchySats'/g" ${infoFile} + sudo -u admin /home/admin/config.scripts/bonus/itchysats.sh on >> ${logFile} 2>&1 +else + echo "ItchySats - keep default" >> ${logFile} +fi + # custom install script from user customInstallAvailable=$(ls /mnt/hdd/app-data/custom-installs.sh 2>/dev/null | grep -c "custom-installs.sh") if [ ${customInstallAvailable} -gt 0 ]; then diff --git a/home.admin/config.scripts/bonus.itchysats.sh b/home.admin/config.scripts/bonus.itchysats.sh new file mode 100644 index 000000000..d0ee9af7c --- /dev/null +++ b/home.admin/config.scripts/bonus.itchysats.sh @@ -0,0 +1,265 @@ +#!/bin/bash + +#https://github.com/itchysats/itchysats + +ITCHYSATS_USER=itchsyats +ITCHYSATS_HOME_DIR=/home/$ITCHYSATS_USER +ITCHYSATS_DATA_DIR=/mnt/hdd/app-data/itchysats +ITCHYSATS_BUILD_DIR=$ITCHYSATS_HOME_DIR/itchysats +ITCHYSATS_HTTP_PORT=8888 +ITCHYSATS_HTTPS_PORT=8889 +ITCHYSATS_CARGO_BIN=/home/$ITCHYSATS_USER/.cargo/bin/cargo +ITCHYSATS_BIN=$ITCHYSATS_HOME_DIR/.cargo/bin/taker + + +ITCHYSATS_VERSION=$( curl -s https://api.github.com/repos/itchysats/itchysats/releases | jq -r '.[].tag_name' | grep -v "rc" | head -n1) +ITCHYSATS_REPOSITORY_URL="https://github.com/itchysats/itchysats" + +# check and load raspiblitz config +# to know which network is running +source /home/admin/raspiblitz.info +source /mnt/hdd/raspiblitz.conf + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "config script to install or uninstall itchysats" + echo "$0 [on|off|menu|update]" + echo "install $ITCHYSATS_VERSION by default" + exit 1 +fi + +############### +# MENU +############### + +# get network info +localip=$(hostname -I | awk '{print $1}') + +# show info menu +if [ "$1" = "menu" ]; then + + toraddress=$(sudo cat /mnt/hdd/tor/itchysats/hostname 2>/dev/null) + fingerprint=$(openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout | cut -d"=" -f2) + + if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then + # Info with TOR + /home/admin/config.scripts/blitz.display.sh qr "${toraddress}" + whiptail --title " ItchySats " --msgbox "Open in your local web browser: +http://${localip}:${ITCHYSATS_HTTP_PORT}\n +https://${localip}:${ITCHYSATS_HTTPS_PORT} with Fingerprint: +${fingerprint}\n\n +Hidden Service address for TOR Browser (see LCD for QR):\n${toraddress} +" 16 67 + /home/admin/config.scripts/blitz.display.sh hide + else + # Info without TOR + whiptail --title " ItchySats " --msgbox "Open in your local web browser & accept self-signed cert: +http://${localip}:${ITCHYSATS_HTTP_PORT}\n +https://${localip}:${ITCHYSATS_HTTPS_PORT} with Fingerprint: +${fingerprint}\n +Use 'itchysats' as username and your Password B to login.\n +Activate TOR to access the web interface from outside your local network. +" 15 57 + fi + echo "please wait ..." + exit 0 +fi + +# add default value to raspi config if needed +if ! grep -Eq "^itchysats=" /mnt/hdd/raspiblitz.conf; then + echo "itchysats=off" >> /mnt/hdd/raspiblitz.conf +fi + +# stop services +echo "making sure services are not running" +sudo systemctl stop itchysats 2>/dev/null + +############### +# SWITCH ON +############### + +#check if install exists: + +if [ "$1" = "1" ] || [ "$1" = "on" ]; then + echo + echo "*** INSTALL ITCHYSATS ***" + echo + + isInstalled=$(sudo ls /etc/systemd/system/itchysats.service 2>/dev/null | grep -c 'itchysats.service') + if ! [ ${isInstalled} -eq 0 ]; then + echo "ItchySats already installed." + else + ############### + # INSTALL + ############### + + # create itchysats user: + sudo adduser --disabled-password --gecos "" $ITCHYSATS_USER + + # install Rust dependencies: + echo + echo "*** Installing rustup for the ItchySats user ***" + echo + curl --proto '=https' --tlsv1.2 -sSs https://sh.rustup.rs | sudo -u $ITCHYSATS_USER sh -s -- -y + + # download source + sudo -u $ITCHYSATS_USER mkdir -p $ITCHYSATS_BUILD_DIR + sudo rm -fR $ITCHYSATS_BUILD_DIR/* + cd $ITCHYSATS_BUILD_DIR || exit 1 + sudo -u $ITCHYSATS_USER git clone $ITCHYSATS_REPOSITORY_URL + cd itchysats || exit 1 + + # checkout latest version + sudo -u $ITCHYSATS_USER git reset --hard $ITCHYSATS_VERSION + + echo + echo "*** Building ItchySats $ITCHYSATS_VERSION. This will take some time.." + echo + # build from source + sudo -u $ITCHYSATS_USER $ITCHYSATS_CARGO_BIN install --path taker --locked || exit 1 + + ############### + # CONFIG + ############### + + # make sure itchysats is member of lndadmin + sudo /usr/sbin/usermod --append --groups lndadmin $ITCHYSATS_USER + + # persist settings in app-data + sudo mkdir -p $ITCHYSATS_DATA_DIR + sudo chown $ITCHYSATS_USER: $ITCHYSATS_DATA_DIR + + ################# + # FIREWALL + ################# + + # open the firewall + echo "*** Updating Firewall ***" + sudo ufw allow from any to any port $ITCHYSATS_HTTP_PORT comment 'allow ItchySats HTTP' + sudo ufw allow from any to any port $ITCHYSATS_HTTPS_PORT comment 'allow ItchySats HTTPS' + echo "" + + echo + echo "*** Getting RPC credentials from the bitcoin.conf" + echo + PASSWORD_B=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcpassword | cut -c 13-) + + ################## + # SYSTEMD SERVICE + ################## + + itchysats_network="mainnet" + if [ "${chain}" = "test" ]; then + itchysats_network="testnet" + fi + + echo "*** Install ItchySats systemd for ${network} on ${itchysats_network}" + echo " +# Systemd unit for ItchySats +# /etc/systemd/system/itchysats.service +[Unit] +Description=ItchySats daemon +Wants=bitcoind.service +After=bitcoind.service +[Service] +WorkingDirectory=$ITCHYSATS_BUILD_DIR/ +ExecStart=$ITCHYSATS_BIN --http-address=0.0.0.0:$ITCHYSATS_HTTP_PORT --password=$PASSWORD_B ${itchysats_network} +User=$ITCHYSATS_USER +Restart=always +TimeoutSec=120 +RestartSec=30 +Environment=ENVIRONMENT=RASPIBLITZ +[Install] +WantedBy=multi-user.target +" | sudo tee /etc/systemd/system/itchysats.service + + sudo systemctl enable itchysats + + # setting value in raspiblitz config + sudo sed -i "s/^itchysats=.*/itchysats=on/g" /mnt/hdd/raspiblitz.conf + + # Hidden Service for ItchySats if Tor is active + TOR_HTTP=8890 + TOR_HTTPS=8891 + if [ "${runBehindTor}" = "on" ]; then + # make sure to keep in sync with internet.tor.sh script + /home/admin/config.scripts/tor.onion-service.sh itchysats 80 "$TOR_HTTP" 443 "$TOR_HTTPS" + fi + + source /home/admin/raspiblitz.info + if [ "${state}" == "ready" ]; then + echo "# OK - the itchysats.service is enabled, system is ready so starting service" + sudo systemctl start itchysats + else + echo "# OK - the itchysats.service is enabled, to start manually use: 'sudo systemctl start itchysats'" + fi + + fi + exit 0 +fi + +############### +# UPDATE +############### +if [ "$1" = "update" ]; then + echo "# Updating ItchySats" + + # Remove ItchySats, keeping database + /home/admin/config.scripts/bonus.itchysats.sh off --keep-data + + # Reinstall ItchySats witch existing database + /home/admin/config.scripts/bonus.itchysats.sh on + + exit 0 +fi + +############### +# SWITCH OFF +############### +if [ "$1" = "0" ] || [ "$1" = "off" ]; then + + + # Keep or delete ItchySats data? + deleteData=0 + if [ "$2" = "--delete-data" ]; then + deleteData=1 + elif [ "$2" = "--keep-data" ]; then + deleteData=0 + else + if (whiptail --title " DELETE ITCHYSATS DATA? " --yesno "Do you want to delete\nthe ItchySats data?" 8 30); then + deleteData=1 + else + deleteData=0 + fi + fi + echo "# deleteData(${deleteData})" + + echo "*** REMOVING ITCHYSATS ***" + # remove systemd service + sudo systemctl disable itchysats + sudo rm -f /etc/systemd/system/itchysats.service + sudo rm -fR $ITCHYSATS_BUILD_DIR + if [ ${deleteData} -eq 1 ]; then + echo "# deleting ItchySats data" + sudo rm -fR $ITCHYSATS_DATA_DIR + else + echo "# keeping ItchySats data" + fi + # delete user and home directory + sudo userdel -rf $ITCHYSATS_USER + # close ports on firewall + sudo ufw deny $ITCHYSATS_HTTP_PORT + sudo ufw deny $ITCHYSATS_HTTPS_PORT + + # Hidden Service if Tor is active + if [ "${runBehindTor}" = "on" ]; then + /home/admin/config.scripts/tor.onion-service.sh off itchysats + fi + + echo "OK ItchySats removed." + + # setting value in raspi blitz config + sudo sed -i "s/^itchysats=.*/itchysats=off/g" /mnt/hdd/raspiblitz.conf + + exit 0 +fi From d81a978a884b36554e5bfcf825a56ba4852feb17 Mon Sep 17 00:00:00 2001 From: itchymax Date: Wed, 18 May 2022 17:17:52 +1000 Subject: [PATCH 2/5] Add config for tor and ssl --- .../nginx/sites-available/itchysats_ssl.conf | 33 +++++++++++++++++++ .../nginx/sites-available/itchysats_tor.conf | 25 ++++++++++++++ .../sites-available/itchysats_tor_ssl.conf | 28 ++++++++++++++++ home.admin/config.scripts/bonus.itchysats.sh | 29 ++++++++++++++++ home.admin/config.scripts/tor.network.sh | 1 + 5 files changed, 116 insertions(+) create mode 100644 home.admin/assets/nginx/sites-available/itchysats_ssl.conf create mode 100644 home.admin/assets/nginx/sites-available/itchysats_tor.conf create mode 100644 home.admin/assets/nginx/sites-available/itchysats_tor_ssl.conf diff --git a/home.admin/assets/nginx/sites-available/itchysats_ssl.conf b/home.admin/assets/nginx/sites-available/itchysats_ssl.conf new file mode 100644 index 000000000..6e64a9ba1 --- /dev/null +++ b/home.admin/assets/nginx/sites-available/itchysats_ssl.conf @@ -0,0 +1,33 @@ +## itchysats_ssl.conf + +server { + listen 8889 ssl; + listen [::]:8889 ssl; + server_name _; + + include /etc/nginx/snippets/ssl-params.conf; + include /etc/nginx/snippets/ssl-certificate-app-data.conf; + + access_log /var/log/nginx/access_itchysats.log; + error_log /var/log/nginx/error_itchysats.log; + + location / { + proxy_pass http://127.0.0.1:8888; + proxy_pass_header Authorization; + + include /etc/nginx/snippets/ssl-proxy-params.conf; + + proxy_set_header Authorization $http_authorization; + proxy_set_header X-Forwarded-User $remote_user; + proxy_pass_header Authorization; + + # for SSE + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + + } + +} diff --git a/home.admin/assets/nginx/sites-available/itchysats_tor.conf b/home.admin/assets/nginx/sites-available/itchysats_tor.conf new file mode 100644 index 000000000..28a5db255 --- /dev/null +++ b/home.admin/assets/nginx/sites-available/itchysats_tor.conf @@ -0,0 +1,25 @@ +## itchysats_tor.conf + +server { + listen localhost:8890; + server_name _; + + access_log /var/log/nginx/access_itchysats.log; + error_log /var/log/nginx/error_itchysats.log; + + location / { + proxy_pass http://127.0.0.1:8888; + proxy_pass_header Authorization; + + include /etc/nginx/snippets/ssl-proxy-params.conf; + proxy_set_header Authorization $http_authorization; + proxy_set_header X-Forwarded-User $remote_user; + + # for SSE + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + } +} diff --git a/home.admin/assets/nginx/sites-available/itchysats_tor_ssl.conf b/home.admin/assets/nginx/sites-available/itchysats_tor_ssl.conf new file mode 100644 index 000000000..7d8d6b902 --- /dev/null +++ b/home.admin/assets/nginx/sites-available/itchysats_tor_ssl.conf @@ -0,0 +1,28 @@ +## itchysats_tor_ssl.conf + +server { + listen localhost:8891 ssl; + server_name _; + + include /etc/nginx/snippets/ssl-params.conf; + include /etc/nginx/snippets/ssl-certificate-app-data-tor.conf; + + access_log /var/log/nginx/access_itchysats.log; + error_log /var/log/nginx/error_itchysats.log; + + location / { + proxy_pass http://127.0.0.1:8888; + proxy_pass_header Authorization; + + include /etc/nginx/snippets/ssl-proxy-params.conf; + proxy_set_header Authorization $http_authorization; + proxy_set_header X-Forwarded-User $remote_user; + + # for SSE + proxy_set_header Connection ''; + proxy_http_version 1.1; + chunked_transfer_encoding off; + proxy_buffering off; + proxy_cache off; + } +} diff --git a/home.admin/config.scripts/bonus.itchysats.sh b/home.admin/config.scripts/bonus.itchysats.sh index d0ee9af7c..c8a0a4186 100644 --- a/home.admin/config.scripts/bonus.itchysats.sh +++ b/home.admin/config.scripts/bonus.itchysats.sh @@ -129,6 +129,25 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then sudo mkdir -p $ITCHYSATS_DATA_DIR sudo chown $ITCHYSATS_USER: $ITCHYSATS_DATA_DIR + ################## + # NGINX + ################## + # setup nginx symlinks + if ! [ -f /etc/nginx/sites-available/itchysats_ssl.conf ]; then + sudo cp -f /home/admin/assets/nginx/sites-available/itchysats_ssl.conf /etc/nginx/sites-available/itchysats_ssl.conf + fi + if ! [ -f /etc/nginx/sites-available/itchysats_tor.conf ]; then + sudo cp /home/admin/assets/nginx/sites-available/itchysats_tor.conf /etc/nginx/sites-available/itchysats_tor.conf + fi + if ! [ -f /etc/nginx/sites-available/itchysats_tor_ssl.conf ]; then + sudo cp /home/admin/assets/nginx/sites-available/itchysats_tor_ssl.conf /etc/nginx/sites-available/itchysats_tor_ssl.conf + fi + sudo ln -sf /etc/nginx/sites-available/itchysats_ssl.conf /etc/nginx/sites-enabled/ + sudo ln -sf /etc/nginx/sites-available/itchysats_tor.conf /etc/nginx/sites-enabled/ + sudo ln -sf /etc/nginx/sites-available/itchysats_tor_ssl.conf /etc/nginx/sites-enabled/ + sudo nginx -t + sudo systemctl reload nginx + ################# # FIREWALL ################# @@ -251,6 +270,16 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then sudo ufw deny $ITCHYSATS_HTTP_PORT sudo ufw deny $ITCHYSATS_HTTPS_PORT + # remove nginx symlinks + sudo rm -f /etc/nginx/sites-enabled/itchysats_ssl.conf + sudo rm -f /etc/nginx/sites-enabled/itchysats_tor.conf + sudo rm -f /etc/nginx/sites-enabled/itchysats_tor_ssl.conf + sudo rm -f /etc/nginx/sites-available/itchysats_ssl.conf + sudo rm -f /etc/nginx/sites-available/itchysats_tor.conf + sudo rm -f /etc/nginx/sites-available/itchysats_tor_ssl.conf + sudo nginx -t + sudo systemctl reload nginx + # Hidden Service if Tor is active if [ "${runBehindTor}" = "on" ]; then /home/admin/config.scripts/tor.onion-service.sh off itchysats diff --git a/home.admin/config.scripts/tor.network.sh b/home.admin/config.scripts/tor.network.sh index e61d7f1b9..655264de3 100755 --- a/home.admin/config.scripts/tor.network.sh +++ b/home.admin/config.scripts/tor.network.sh @@ -129,6 +129,7 @@ case "$1" in if [ "${helipad}" = "on" ]; then /home/admin/config.scripts/tor.onion-service.sh helipad 2112 2113 fi + [ "${itchysats}" = "on" ] && /home/admin/config.scripts/tor.onion-service.sh itchysats 80 8890 443 8891 echo "Setup logrotate" # add logrotate config for modified Tor dir on ext. disk From 37f97f4231995f536d41f2e8b4d257fa9727fdcf Mon Sep 17 00:00:00 2001 From: itchymax Date: Thu, 19 May 2022 08:52:30 +1000 Subject: [PATCH 3/5] Download release binary instead of build --- home.admin/config.scripts/bonus.itchysats.sh | 71 ++++++++++++++------ 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/home.admin/config.scripts/bonus.itchysats.sh b/home.admin/config.scripts/bonus.itchysats.sh index c8a0a4186..32c0c0c0a 100644 --- a/home.admin/config.scripts/bonus.itchysats.sh +++ b/home.admin/config.scripts/bonus.itchysats.sh @@ -5,15 +5,13 @@ ITCHYSATS_USER=itchsyats ITCHYSATS_HOME_DIR=/home/$ITCHYSATS_USER ITCHYSATS_DATA_DIR=/mnt/hdd/app-data/itchysats -ITCHYSATS_BUILD_DIR=$ITCHYSATS_HOME_DIR/itchysats +ITCHYSATS_DOWNLOAD_DIR=$ITCHYSATS_HOME_DIR/download ITCHYSATS_HTTP_PORT=8888 ITCHYSATS_HTTPS_PORT=8889 -ITCHYSATS_CARGO_BIN=/home/$ITCHYSATS_USER/.cargo/bin/cargo -ITCHYSATS_BIN=$ITCHYSATS_HOME_DIR/.cargo/bin/taker +ITCHYSATS_BIN=$ITCHYSATS_HOME_DIR/bin/taker ITCHYSATS_VERSION=$( curl -s https://api.github.com/repos/itchysats/itchysats/releases | jq -r '.[].tag_name' | grep -v "rc" | head -n1) -ITCHYSATS_REPOSITORY_URL="https://github.com/itchysats/itchysats" # check and load raspiblitz config # to know which network is running @@ -96,27 +94,58 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then # create itchysats user: sudo adduser --disabled-password --gecos "" $ITCHYSATS_USER - # install Rust dependencies: echo - echo "*** Installing rustup for the ItchySats user ***" + echo "*** Detect CPU architecture ..." echo - curl --proto '=https' --tlsv1.2 -sSs https://sh.rustup.rs | sudo -u $ITCHYSATS_USER sh -s -- -y + architecture=$(uname -m) + isAARCH64=$(uname -m | grep -c 'aarch64') + isX86_64=$(uname -m | grep -c 'x86_64') + if [ ${isAARCH64} -eq 0 ] && [ ${isX86_64} -eq 0 ] ; then + echo "*** !!! FAIL !!!" + echo "*** Can only build on aarch64 or x86_64 not on:" + uname -m + exit 1 + else + echo "*** OK running on $architecture architecture." + fi - # download source - sudo -u $ITCHYSATS_USER mkdir -p $ITCHYSATS_BUILD_DIR - sudo rm -fR $ITCHYSATS_BUILD_DIR/* - cd $ITCHYSATS_BUILD_DIR || exit 1 - sudo -u $ITCHYSATS_USER git clone $ITCHYSATS_REPOSITORY_URL - cd itchysats || exit 1 + # create directories + sudo -u $ITCHYSATS_USER mkdir -p $ITCHYSATS_DOWNLOAD_DIR + sudo rm -fR $ITCHYSATS_DOWNLOAD_DIR/* + cd $ITCHYSATS_DOWNLOAD_DIR || exit 1 - # checkout latest version - sudo -u $ITCHYSATS_USER git reset --hard $ITCHYSATS_VERSION + echo + echo "*** Downloading Binary" + echo + binaryName="taker_${ITCHYSATS_VERSION}_Linux_${architecture}.tar" + sudo -u $ITCHYSATS_USER wget -N https://github.com/itchysats/itchysats/releases/download/${ITCHYSATS_VERSION}/${binaryName} + checkDownload=$(ls ${binaryName} 2>/dev/null | grep -c ${binaryName}) + if [ ${checkDownload} -eq 0 ]; then + echo "*** !!! FAIL !!!" + echo "*** Downloading the binary failed" + exit 1 + fi + # set PATH for the user + sudo bash -c "echo 'PATH=\$PATH:/home/itchysats/bin/' >> /home/itchysats/.profile" + + # install + echo + echo "*** unzip binary: ${binaryName}" echo - echo "*** Building ItchySats $ITCHYSATS_VERSION. This will take some time.." + sudo -u $ITCHYSATS_USER tar -xvf ${binaryName} echo - # build from source - sudo -u $ITCHYSATS_USER $ITCHYSATS_CARGO_BIN install --path taker --locked || exit 1 + echo "*** install binary" + echo + sudo -u $ITCHYSATS_USER mkdir -p $ITCHYSATS_HOME_DIR/bin + sudo install -m 0755 -o $ITCHYSATS_USER -g $ITCHYSATS_USER -t $ITCHYSATS_HOME_DIR/bin taker + sleep 3 + + installed=$(sudo -u $ITCHYSATS_USER $ITCHYSATS_BIN --help) + if [ ${#installed} -eq 0 ]; then + echo "error='install failed'" + exit 1 + fi ############### # CONFIG @@ -181,7 +210,7 @@ Description=ItchySats daemon Wants=bitcoind.service After=bitcoind.service [Service] -WorkingDirectory=$ITCHYSATS_BUILD_DIR/ +WorkingDirectory=$ITCHYSATS_HOME_DIR/ ExecStart=$ITCHYSATS_BIN --http-address=0.0.0.0:$ITCHYSATS_HTTP_PORT --password=$PASSWORD_B ${itchysats_network} User=$ITCHYSATS_USER Restart=always @@ -257,10 +286,10 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then # remove systemd service sudo systemctl disable itchysats sudo rm -f /etc/systemd/system/itchysats.service - sudo rm -fR $ITCHYSATS_BUILD_DIR + sudo rm -fR $ITCHYSATS_DOWNLOAD_DIR if [ ${deleteData} -eq 1 ]; then echo "# deleting ItchySats data" - sudo rm -fR $ITCHYSATS_DATA_DIR + sudo rm -fR $ITCHYSATS_DATA_DIR else echo "# keeping ItchySats data" fi From aaf33db24c65ff54759087972052b28bfa09c955 Mon Sep 17 00:00:00 2001 From: itchymax Date: Thu, 19 May 2022 11:28:53 +1000 Subject: [PATCH 4/5] Add option to update itchysats --- home.admin/99updateMenu.sh | 7 ++ home.admin/config.scripts/bonus.itchysats.sh | 83 ++++++++++++++------ 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/home.admin/99updateMenu.sh b/home.admin/99updateMenu.sh index f7c395edf..b9156108c 100755 --- a/home.admin/99updateMenu.sh +++ b/home.admin/99updateMenu.sh @@ -489,6 +489,10 @@ if [ "${runBehindTor}" == "on" ]; then OPTIONS+=(TOR "Update Tor from the source code") fi +if [ "${itchysats}" == "on" ]; then + OPTIONS+=(ITCHYSATS "Update ItchySats") +fi + CHOICE_HEIGHT=$(("${#OPTIONS[@]}/2+1")) HEIGHT=$((CHOICE_HEIGHT+6)) CHOICE=$(dialog --clear \ @@ -538,4 +542,7 @@ case $CHOICE in MEMPOOL) /home/admin/config.scripts/bonus.mempool.sh update ;; + ITCHYSATS) + /home/admin/config.scripts/bonus.itchysats.sh update + ;; esac diff --git a/home.admin/config.scripts/bonus.itchysats.sh b/home.admin/config.scripts/bonus.itchysats.sh index 32c0c0c0a..c4d532aff 100644 --- a/home.admin/config.scripts/bonus.itchysats.sh +++ b/home.admin/config.scripts/bonus.itchysats.sh @@ -78,22 +78,7 @@ sudo systemctl stop itchysats 2>/dev/null #check if install exists: -if [ "$1" = "1" ] || [ "$1" = "on" ]; then - echo - echo "*** INSTALL ITCHYSATS ***" - echo - - isInstalled=$(sudo ls /etc/systemd/system/itchysats.service 2>/dev/null | grep -c 'itchysats.service') - if ! [ ${isInstalled} -eq 0 ]; then - echo "ItchySats already installed." - else - ############### - # INSTALL - ############### - - # create itchysats user: - sudo adduser --disabled-password --gecos "" $ITCHYSATS_USER - +downloadBinary() { echo echo "*** Detect CPU architecture ..." echo @@ -126,9 +111,6 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then exit 1 fi - # set PATH for the user - sudo bash -c "echo 'PATH=\$PATH:/home/itchysats/bin/' >> /home/itchysats/.profile" - # install echo echo "*** unzip binary: ${binaryName}" @@ -146,6 +128,37 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then echo "error='install failed'" exit 1 fi +} + +if [ "$1" = "1" ] || [ "$1" = "on" ]; then + echo + echo "*** INSTALL ITCHYSATS ***" + echo + + isInstalled=$(sudo ls /etc/systemd/system/itchysats.service 2>/dev/null | grep -c 'itchysats.service') + if ! [ ${isInstalled} -eq 0 ]; then + echo "ItchySats already installed." + else + ############### + # INSTALL + ############### + + # create itchysats user: + sudo adduser --disabled-password --gecos "" $ITCHYSATS_USER + + if downloadBinary; then + echo + echo "*** Download successful" + echo + else + echo + echo "*** Download binary failed" + echo + exit 1 + fi + + # set PATH for the user + sudo bash -c "echo 'PATH=\$PATH:/home/itchysats/bin/' >> /home/itchysats/.profile" ############### # CONFIG @@ -250,15 +263,35 @@ fi # UPDATE ############### if [ "$1" = "update" ]; then - echo "# Updating ItchySats" + echo + echo "*** Updating ItchySats" + echo - # Remove ItchySats, keeping database - /home/admin/config.scripts/bonus.itchysats.sh off --keep-data + echo + echo "*** Making sure service is not running" + echo + sudo systemctl stop itchysats - # Reinstall ItchySats witch existing database - /home/admin/config.scripts/bonus.itchysats.sh on + echo + echo "*** Removing old binary and downloading new" + echo + if downloadBinary; then + echo + echo "*** Upgrade successful" + echo + else + echo + echo "*** Upgrade failed" + echo + exit 1 + fi - exit 0 + echo + echo "*** Restarting service" + echo + sudo systemctl start itchysats + + exit 0 fi ############### From 2c38e4b114161df5232b2e33e2f0a71e74122179 Mon Sep 17 00:00:00 2001 From: itchymax Date: Thu, 19 May 2022 11:36:04 +1000 Subject: [PATCH 5/5] Cleanup after download --- home.admin/config.scripts/bonus.itchysats.sh | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/home.admin/config.scripts/bonus.itchysats.sh b/home.admin/config.scripts/bonus.itchysats.sh index c4d532aff..840d332a7 100644 --- a/home.admin/config.scripts/bonus.itchysats.sh +++ b/home.admin/config.scripts/bonus.itchysats.sh @@ -102,9 +102,9 @@ downloadBinary() { echo echo "*** Downloading Binary" echo - binaryName="taker_${ITCHYSATS_VERSION}_Linux_${architecture}.tar" - sudo -u $ITCHYSATS_USER wget -N https://github.com/itchysats/itchysats/releases/download/${ITCHYSATS_VERSION}/${binaryName} - checkDownload=$(ls ${binaryName} 2>/dev/null | grep -c ${binaryName}) + archiveName="taker_${ITCHYSATS_VERSION}_Linux_${architecture}.tar" + sudo -u $ITCHYSATS_USER wget -N https://github.com/itchysats/itchysats/releases/download/${ITCHYSATS_VERSION}/${archiveName} + checkDownload=$(ls ${archiveName} 2>/dev/null | grep -c ${archiveName}) if [ ${checkDownload} -eq 0 ]; then echo "*** !!! FAIL !!!" echo "*** Downloading the binary failed" @@ -113,9 +113,9 @@ downloadBinary() { # install echo - echo "*** unzip binary: ${binaryName}" + echo "*** unzip binary: ${archiveName}" echo - sudo -u $ITCHYSATS_USER tar -xvf ${binaryName} + sudo -u $ITCHYSATS_USER tar -xvf ${archiveName} echo echo "*** install binary" echo @@ -128,6 +128,13 @@ downloadBinary() { echo "error='install failed'" exit 1 fi + + echo + echo "*** Cleaning up download artifacts" + echo + + sudo -u $ITCHYSATS_USER rm -f "${archiveName}" + sudo -u $ITCHYSATS_USER rm -f taker } if [ "$1" = "1" ] || [ "$1" = "on" ]; then