From 78e9fa7126acaa9fa73b0ae70dd183a1bb24072d Mon Sep 17 00:00:00 2001 From: Christian Rotzoll Date: Thu, 11 Apr 2019 17:32:50 +0100 Subject: [PATCH] #24 added to Service Menu --- home.admin/00settingsMenuServices.sh | 20 ++++++++++++++++++++ home.admin/50torrentHDD.sh | 25 ++++++++++++++++++++++++- home.admin/_bootstrap.sh | 6 ++---- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh index 51f592d..32386bf 100644 --- a/home.admin/00settingsMenuServices.sh +++ b/home.admin/00settingsMenuServices.sh @@ -11,6 +11,7 @@ if [ ${#autoUnlock} -eq 0 ]; then autoUnlock="off"; fi if [ ${#runBehindTor} -eq 0 ]; then runBehindTor="off"; fi if [ ${#rtlWebinterface} -eq 0 ]; then rtlWebinterface="off"; fi if [ ${#chain} -eq 0 ]; then chain="main"; fi +if [ ${#backupTorrentSeeding} -eq 0 ]; then backupTorrentSeeding="off"; fi echo "map chain to on/off" chainValue="off" @@ -41,6 +42,7 @@ CHOICES=$(dialog --title ' Additional Services ' --checklist ' use spacebar to a 4 'Run behind TOR' ${runBehindTor} \ 5 'RTL Webinterface' ${rtlWebinterface} \ 6 'LND Auto-Unlock' ${autoUnlock} \ +7 'Backup Torrent Seeding' ${backupTorrentSeeding} \ 2>&1 >/dev/tty) dialogcancel=$? echo "done dialog" @@ -213,6 +215,24 @@ else echo "LND Autounlock Setting unchanged." fi +# Backup Torrent Seeding +choice="off"; check=$(echo "${CHOICES}" | grep -c "7") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${backupTorrentSeeding}" != "${choice}" ]; then + echo "BACKUP TORRENT SEEDING Setting changed .." + anychange=1 + if [ "${choice}" = "on" ]; then + + echo "BACKUP TORRENT SEEDING IS NOW ON" + else + echo "Stopping Torrents and Cleaning Up ..." + sudo /home/admin/50torrentHDD.sh backup-torrent-hosting-cleanup + echo "BACKUP TORRENT SEEDING IS NOW OFF" + fi +else + echo "LND Autounlock Setting unchanged." +fi + if [ ${anychange} -eq 0 ]; then dialog --pause "Hint: Use Spacebar to check/uncheck services." 8 58 5 exit 0 diff --git a/home.admin/50torrentHDD.sh b/home.admin/50torrentHDD.sh index 1c68c44..5b42485 100755 --- a/home.admin/50torrentHDD.sh +++ b/home.admin/50torrentHDD.sh @@ -2,6 +2,7 @@ # START with parameter "backup-torrent-hosting" to just kick of the torrent downloads in the background during # regular RaspiBlitz running. So you support torrent hosting and have a blockchain backup ready just in case. +# START with parameter "backup-torrent-hosting-cleanup" to stop background torrents and clean up ## get basic info source /home/admin/raspiblitz.info @@ -44,9 +45,21 @@ sudo mkdir ${sessionDir}/update/ 2>/dev/null # BACKUP TORRENT SEEDING if [ "$1" == "backup-torrent-hosting-cleanup" ]; then + echo "Stopping Torrents ..." + sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs) + if [ ${#sessionPID} -gt 0 ]; then + sudo pkill -P ${sessionPID} + fi + sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs) + if [ ${#sessionPID} -gt 0 ]; then + sudo pkill -P ${sessionPID} + fi echo "Deleting all possible old (version) torrent data ..." sudo rm -r /home/admin/.rtorrent.session 2>/dev/null sudo rm -r /mnt/hdd/torrent 2>/dev/null + echo "Changing config ..." + sudo sed -i "s/^backupTorrentSeeding=.*/backupTorrentSeeding=off/g" /mnt/hdd/raspiblitz.conf + echo "DONE" exit fi @@ -106,10 +119,20 @@ if [ ${torrentComplete2} -eq 0 ]; then fi sleep 2 +############################## # BACKUP TORRENT SEEDING +############################## # just let torrent start and run in the background + if [ "$1" == "backup-torrent-hosting" ]; then - echo "Done BACKUP TORRENT HOSTING .." + # changing config - so it can be startup again after a reboot by bootstrap + source /mnt/hdd/raspiblitz.conf + if [ ${#backupTorrentSeeding} -eq 0 ]; then + echo "backupTorrentSeeding=on" >> /mnt/hdd/raspiblitz.conf + else + sudo sed -i "s/^backupTorrentSeeding=.*/backupTorrentSeeding=on/g" /mnt/hdd/raspiblitz.conf + fi + echo "Done BACKUP TORRENT HOSTING" exit fi diff --git a/home.admin/_bootstrap.sh b/home.admin/_bootstrap.sh index c506dc3..adc5066 100644 --- a/home.admin/_bootstrap.sh +++ b/home.admin/_bootstrap.sh @@ -440,10 +440,8 @@ sudo /home/admin/config.scripts/blitz.stresstest.sh /home/admin/stresstest.repor ################################ if [ "${backupTorrentSeeding}" == "on" ]; then - echo "Starting BACKUP TORRENT HOSTING in background ..." >> $logFile - sudo /home/admin/50torrentHDD.sh backup-torrent-hosting - sleep 5 - + echo "Starting BACKUP TORRENT HOSTING in background ..." >> $logFile + sudo /home/admin/50torrentHDD.sh backup-torrent-hosting fi echo "DONE BOOTSTRAP" >> $logFile