@@ -61,34 +61,41 @@ Supported programs:
6161
6262 # Program database name array
6363 declare -A aFILE=()
64- # - Sonarr
65- if [[ ${INPUT_PROG:- sonarr} == ' sonarr' ]]
66- then
67- # v3
68- if [[ -f ' /mnt/dietpi_userdata/sonarr/sonarr.db' || -f ' /mnt/dietpi_userdata/sonarr/sonarr.db.bak' ]]
64+
65+ Init_Programs ()
66+ {
67+ aFILE=()
68+ # - Sonarr
69+ if [[ ${INPUT_PROG:- sonarr} == ' sonarr' ]]
6970 then
70- aFILE[sonarr]=' sonarr.db'
71- # v2
72- else
73- aFILE[sonarr]=' nzbdrone.db'
71+ # v3
72+ if [[ -f ' /mnt/dietpi_userdata/sonarr/sonarr.db' || -f ' /mnt/dietpi_userdata/sonarr/sonarr.db.bak' ]]
73+ then
74+ aFILE[sonarr]=' sonarr.db'
75+ # v2
76+ else
77+ aFILE[sonarr]=' nzbdrone.db'
78+ fi
7479 fi
75- fi
76- # - Radarr
77- if [[ ${INPUT_PROG:- radarr} == ' radarr' ]]
78- then
79- # v3
80- if [[ -f ' /mnt/dietpi_userdata/radarr/radarr.db' || -f ' /mnt/dietpi_userdata/radarr/radarr.db.bak' ]]
80+ # - Radarr
81+ if [[ ${INPUT_PROG:- radarr} == ' radarr' ]]
8182 then
82- aFILE[radarr]=' radarr.db'
83- # v2
84- else
85- aFILE[radarr]=' nzbdrone.db'
83+ # v3
84+ if [[ -f ' /mnt/dietpi_userdata/radarr/radarr.db' || -f ' /mnt/dietpi_userdata/radarr/radarr.db.bak' ]]
85+ then
86+ aFILE[radarr]=' radarr.db'
87+ # v2
88+ else
89+ aFILE[radarr]=' nzbdrone.db'
90+ fi
8691 fi
87- fi
88- # - Lidarr
89- [[ ${INPUT_PROG:- lidarr} == ' lidarr' ]] && aFILE[lidarr]=' lidarr.db'
90- # - Prowlarr
91- [[ ${INPUT_PROG:- prowlarr} == ' prowlarr' ]] && aFILE[prowlarr]=' prowlarr.db'
92+ # - Lidarr
93+ [[ ${INPUT_PROG:- lidarr} == ' lidarr' ]] && aFILE[lidarr]=' lidarr.db'
94+ # - Prowlarr
95+ [[ ${INPUT_PROG:- prowlarr} == ' prowlarr' ]] && aFILE[prowlarr]=' prowlarr.db'
96+ }
97+
98+ Init_Programs
9299
93100 # Check for valid input program
94101 (( ${# aFILE[@]} )) || { error=1 Print " Invalid input program ($INPUT_PROG ). Aborting...
@@ -151,7 +158,7 @@ $USAGE"; exit 1; }
151158 then
152159 Print " Creating $FP_DISK /dietpi-servarr_to_ram.sh to be used as ${i^} custom script"
153160 # shellcheck disable=SC2320
154- echo -e ' #!/bin/dash\n/boot/dietpi/misc/ dietpi-servarr_to_ram 2 ' " $i " > " $FP_DISK /dietpi-servarr_to_ram.sh" || { error=$? Print " Creating $FP_DISK /dietpi-servarr_to_ram.sh failed." ; }
161+ echo -e ' #!/bin/dash\n/boot/dietpi/dietpi-servarr_to_ram 2 ' " $i " > " $FP_DISK /dietpi-servarr_to_ram.sh" || { error=$? Print " Creating $FP_DISK /dietpi-servarr_to_ram.sh failed." ; }
155162 chmod +x " $FP_DISK /dietpi-servarr_to_ram.sh" || { error=$? Print " Applying $FP_DISK /dietpi-servarr_to_ram.sh execute permissions failed." ; }
156163 chown " $i :dietpi" " $FP_DISK /dietpi-servarr_to_ram.sh" || { error=$? Print " Applying $FP_DISK /dietpi-servarr_to_ram.sh ownership failed." ; }
157164 fi
@@ -304,8 +311,8 @@ Before=sonarr.service radarr.service lidarr.service prowlarr.service
304311Type=oneshot
305312RemainAfterExit=yes
306313# We want to preserve logs from the last service stop, to know whether there were issues storing the database back to disk.
307- ExecStart=-/bin/dash -c '/boot/dietpi/misc/ dietpi-servarr_to_ram 1 2>&1 >> /var/tmp/dietpi/logs/dietpi-servarr_to_ram.log'
308- ExecStop=/bin/dash -c '/boot/dietpi/misc/ dietpi-servarr_to_ram 0 2>&1 > /var/tmp/dietpi/logs/dietpi-servarr_to_ram.log'
314+ ExecStart=-/bin/dash -c '/boot/dietpi/dietpi-servarr_to_ram 1 2>&1 >> /var/tmp/dietpi/logs/dietpi-servarr_to_ram.log'
315+ ExecStop=/bin/dash -c '/boot/dietpi/dietpi-servarr_to_ram 0 2>&1 > /var/tmp/dietpi/logs/dietpi-servarr_to_ram.log'
309316
310317[Install]
311318WantedBy=multi-user.target
@@ -325,12 +332,14 @@ _EOF_
325332 # /////////////////////////////////////////////////////////////////////////////////////
326333 # Main Loop
327334 # /////////////////////////////////////////////////////////////////////////////////////
335+ GLOBALS_LOADED=0
328336 # Assure SQLite is available
329337 if ! command -v sqlite3 & > /dev/null
330338 then
331339 Print ' Installing SQLite, used by this script to create database backups...'
332340 . /boot/dietpi/func/dietpi-globals
333- readonly G_PROGRAM_NAME=' DietPi-Servarr_to_RAM'
341+ G_PROGRAM_NAME=' DietPi-Servarr_to_RAM'
342+ GLOBALS_LOADED=1
334343 G_AGUP
335344 G_AGI sqlite3
336345 fi
@@ -347,6 +356,94 @@ _EOF_
347356 " ${INPUT^} _On_Boot"
348357 (( $EXIT_CODE )) && Print ' [ERROR] An issue has occurred. Please check the above output for details.'
349358
359+ # Interactive TUI mode
360+ elif [[ ! $INPUT ]]; then
361+
362+ (( $GLOBALS_LOADED )) || . /boot/dietpi/func/dietpi-globals
363+ G_PROGRAM_NAME=' DietPi-Servarr_to_RAM'
364+ G_INIT
365+
366+ Menu_Program ()
367+ {
368+ G_WHIP_MENU_ARRAY=(
369+ ' all' ' : Apply to all installed programs'
370+ ' sonarr' ' : Apply to Sonarr only'
371+ ' radarr' ' : Apply to Radarr only'
372+ ' lidarr' ' : Apply to Lidarr only'
373+ ' prowlarr' ' : Apply to Prowlarr only'
374+ )
375+ G_WHIP_BUTTON_CANCEL_TEXT=' Back'
376+ G_WHIP_MENU ' Please select a program to apply this to:' || return 1
377+ INPUT_PROG=$G_WHIP_RETURNED_VALUE
378+ [[ $INPUT_PROG == ' all' ]] && INPUT_PROG=' '
379+ Init_Programs
380+ }
381+
382+ Menu_Main ()
383+ {
384+ local boot_status=' disabled'
385+ systemctl -q is-enabled dietpi-servarr_to_ram && boot_status=' enabled'
386+
387+ local header=" DietPi-Servarr_to_RAM: Link Sonarr, Radarr, Lidarr and Prowlarr databases to RAM"
388+ if [[ $boot_status == ' enabled' && -f ' /var/tmp/dietpi/logs/dietpi-servarr_to_ram.log' ]]
389+ then
390+ header+=" \n\nService status:\n$( tail -2 /var/tmp/dietpi/logs/dietpi-servarr_to_ram.log) "
391+ fi
392+
393+ G_WHIP_MENU_ARRAY=(
394+ ' ' ' ●─ Program '
395+ ' Program' " [${INPUT_PROG:- all} ] Select program to apply operations to"
396+ ' ' ' ●─ Database '
397+ ' Link to RAM' " : Link ${INPUT_PROG:- all} databases to RAM"
398+ ' Store to disk' " : Store ${INPUT_PROG:- all} databases back to disk"
399+ ' Backup' " : Update ${INPUT_PROG:- all} database backups"
400+ ' ' ' ●─ Boot service '
401+ ' Service' " [$boot_status ] Link to RAM all databases on system boot"
402+ )
403+
404+ G_WHIP_BUTTON_CANCEL_TEXT=' Exit'
405+ G_WHIP_MENU " $header " || return 1
406+
407+ case $G_WHIP_RETURNED_VALUE in
408+
409+ ' Program' )
410+ Menu_Program
411+ return 0
412+ ;;
413+
414+ ' Link to RAM' )
415+ INPUT=1
416+ Toggle_Link_To_Ram
417+ ;;
418+
419+ ' Store to disk' )
420+ INPUT=0
421+ Toggle_Link_To_Ram
422+ ;;
423+
424+ ' Backup' )
425+ INPUT=2
426+ Toggle_Link_To_Ram
427+ ;;
428+
429+ ' Service' )
430+ if [[ $boot_status == ' enabled' ]]
431+ then
432+ Disable_On_Boot
433+ else
434+ Enable_On_Boot
435+ fi
436+ ;;
437+
438+ * ) : ;;
439+ esac
440+
441+ (( $EXIT_CODE )) && read -rp " [ERROR] An issue has occurred. Please check the above output for details. Press Enter or Return to return to $G_PROGRAM_NAME ."
442+ EXIT_CODE=0
443+ }
444+
445+ while : ; do Menu_Main || break ; done
446+
350447 else
351448
352449 error=1 Print " Invalid input command (${INPUT:- <empty>} ). Aborting...
0 commit comments