From f99f2aed7417d73e508ab936b07e3c1c4f9ef5b1 Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Sat, 15 Jul 2023 16:04:24 -0400 Subject: [PATCH] 1.4 - Add new Script Interval, improve logging #18 --- sonarr/AutoExtras.service | 51 ++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/sonarr/AutoExtras.service b/sonarr/AutoExtras.service index f8df3fe..a24ee57 100644 --- a/sonarr/AutoExtras.service +++ b/sonarr/AutoExtras.service @@ -1,20 +1,39 @@ #!/usr/bin/env bash -scriptVersion="1.3" +scriptVersion="1.4" scriptName="AutoExtras" -#### Import Settings -source /config/extended.conf - log () { m_time=`date "+%F %T"` echo $m_time" :: $scriptName :: $scriptVersion :: "$1 } -if [ "$enableExtras" != "true" ]; then +logfileSetup () { + # auto-clean up log file to reduce space usage + if [ -f "/config/logs/$scriptName.txt" ]; then + find /config/logs -type f -name "$scriptName.txt" -size +1024k -delete + fi + + if [ ! -f "/config/logs/$scriptName.txt" ]; then + touch "/config/logs/$scriptName.txt" + chmod 666 "/config/logs/$scriptName.txt" + fi + exec &> >(tee -a "/config/logs/$scriptName.txt") +} + +verifyConfig () { + #### Import Settings + source /config/extended.conf + + if [ "$enableExtras" != "true" ]; then log "Script is not enabled, enable by setting enableExtras to \"true\" by modifying the \"/config/extended.conf\" config file..." log "Sleeping (infinity)" sleep infinity -fi + fi + + if [ -z "$autoExtrasScriptInterval" ]; then + autoExtrasScriptInterval="24h" + fi +} getArrAppInfo () { # Get Arr App information @@ -53,17 +72,7 @@ verifyApiAccess () { } AutoExtrasProcess () { - # auto-clean up log file to reduce space usage - if [ -f "/config/logs/AutoExtras.txt" ]; then - find /config/logs -type f -name "AutoExtras.txt" -size +1024k -delete - fi - - if [ ! -f "/config/logs/AutoExtras.txt" ]; then - touch "/config/logs/AutoExtras.txt" - chmod 666 "/config/logs/AutoExtras.txt" - fi - exec &> >(tee -a "/config/logs/AutoExtras.txt") - + sonarrSeriesList=$(curl -s --header "X-Api-Key:"${arrApiKey} --request GET "$arrUrl/api/v3/series") sonarrSeriesTotal=$(echo "${sonarrSeriesList}" | jq -r '.[].id' | wc -l) sonarrSeriesIds=$(echo "${sonarrSeriesList}" | jq -r '.[].id') @@ -84,14 +93,16 @@ AutoExtrasProcess () { done } -echo "Starting Script...." for (( ; ; )); do let i++ + logfileSetup + log "Script starting..." + verifyConfig getArrAppInfo verifyApiAccess AutoExtrasProcess - echo "Script sleeping for 24 hours..." - sleep 24h + echo "Script sleeping for $autoExtrasScriptInterval..." + sleep $autoExtrasScriptInterval done exit