1.4 - Add new Script Interval, improve logging

#18
This commit is contained in:
RandomNinjaAtk 2023-07-15 16:04:24 -04:00 committed by GitHub
parent 08de9a7faf
commit f99f2aed74
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,21 +1,40 @@
#!/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
}
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
if [ -z "$autoExtrasScriptInterval" ]; then
autoExtrasScriptInterval="24h"
fi
}
getArrAppInfo () {
# Get Arr App information
if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then
@ -53,16 +72,6 @@ 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)
@ -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