v1.0 - Turn into a service
This commit is contained in:
parent
dc2c054023
commit
a035b3731e
1 changed files with 102 additions and 39 deletions
|
@ -1,18 +1,13 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
scriptVersion="1.0.2"
|
scriptVersion="1.0"
|
||||||
|
scriptName="UnmappedFolderCleaner"
|
||||||
|
|
||||||
if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then
|
log () {
|
||||||
arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
|
m_time=`date "+%F %T"`
|
||||||
if [ "$arrUrlBase" == "null" ]; then
|
echo $m_time" :: $scriptName :: $scriptVersion :: "$1
|
||||||
arrUrlBase=""
|
}
|
||||||
else
|
|
||||||
arrUrlBase="/$(echo "$arrUrlBase" | sed "s/\///g")"
|
|
||||||
fi
|
|
||||||
arrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)"
|
|
||||||
arrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)"
|
|
||||||
arrUrl="http://127.0.0.1:${arrPort}${arrUrlBase}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
logfileSetup () {
|
||||||
# auto-clean up log file to reduce space usage
|
# auto-clean up log file to reduce space usage
|
||||||
if [ -f "/config/logs/UnmappedFolderCleaner.txt" ]; then
|
if [ -f "/config/logs/UnmappedFolderCleaner.txt" ]; then
|
||||||
find /config/logs -type f -name "UnmappedFolderCleaner.txt" -size +1024k -delete
|
find /config/logs -type f -name "UnmappedFolderCleaner.txt" -size +1024k -delete
|
||||||
|
@ -20,15 +15,69 @@ fi
|
||||||
|
|
||||||
if [ ! -f "/config/logs/UnmappedFolderCleaner.txt" ]; then
|
if [ ! -f "/config/logs/UnmappedFolderCleaner.txt" ]; then
|
||||||
touch "/config/logs/UnmappedFolderCleaner.txt"
|
touch "/config/logs/UnmappedFolderCleaner.txt"
|
||||||
chmod 777 "/config/logs/UnmappedFolderCleaner.txt"
|
chmod 666 "/config/logs/UnmappedFolderCleaner.txt"
|
||||||
fi
|
fi
|
||||||
exec &> >(tee -a "/config/logs/UnmappedFolderCleaner.txt")
|
exec &> >(tee -a "/config/logs/UnmappedFolderCleaner.txt")
|
||||||
|
|
||||||
log () {
|
|
||||||
m_time=`date "+%F %T"`
|
|
||||||
echo $m_time" :: UnmappedFolderCleaner :: $scriptVersion :: "$1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
verifyConfig () {
|
||||||
|
#### Import Settings
|
||||||
|
source /config/extended.conf
|
||||||
|
|
||||||
|
if [ "$enableUnmappedFolderCleaner" != "true" ]; then
|
||||||
|
log "Script is not enabled, enable by setting enableUnmappedFolderCleaner to \"true\" by modifying the \"/config/extended.conf\" config file..."
|
||||||
|
log "Sleeping (infinity)"
|
||||||
|
sleep infinity
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$unmappedFolderCleanerScriptInterval" ]; then
|
||||||
|
unmappedFolderCleanerScriptInterval="1h"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
getArrAppInfo () {
|
||||||
|
# Get Arr App information
|
||||||
|
if [ -z "$arrUrl" ] || [ -z "$arrApiKey" ]; then
|
||||||
|
arrUrlBase="$(cat /config/config.xml | xq | jq -r .Config.UrlBase)"
|
||||||
|
if [ "$arrUrlBase" == "null" ]; then
|
||||||
|
arrUrlBase=""
|
||||||
|
else
|
||||||
|
arrUrlBase="/$(echo "$arrUrlBase" | sed "s/\///g")"
|
||||||
|
fi
|
||||||
|
arrName="$(cat /config/config.xml | xq | jq -r .Config.InstanceName)"
|
||||||
|
arrApiKey="$(cat /config/config.xml | xq | jq -r .Config.ApiKey)"
|
||||||
|
arrPort="$(cat /config/config.xml | xq | jq -r .Config.Port)"
|
||||||
|
arrUrl="http://127.0.0.1:${arrPort}${arrUrlBase}"
|
||||||
|
fi
|
||||||
|
if [ "$arrPort" == "7878" ]; then
|
||||||
|
recylcarrApp="radarr"
|
||||||
|
fi
|
||||||
|
if [ "$arrPort" == "8989" ]; then
|
||||||
|
recylcarrApp="sonarr"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
verifyApiAccess () {
|
||||||
|
until false
|
||||||
|
do
|
||||||
|
arrApiTest=""
|
||||||
|
arrApiVersion=""
|
||||||
|
if [ "$arrPort" == "8989" ] || [ "$arrPort" == "7878" ]; then
|
||||||
|
arrApiVersion="v3"
|
||||||
|
elif [ "$arrPort" == "8686" ] || [ "$arrPort" == "8787" ]; then
|
||||||
|
arrApiVersion="v1"
|
||||||
|
fi
|
||||||
|
arrApiTest=$(curl -s "$arrUrl/api/$arrApiVersion/system/status?apikey=$arrApiKey" | jq -r .instanceName)
|
||||||
|
if [ "$arrApiTest" == "$arrName" ]; then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
log "$arrName is not ready, sleeping until valid response..."
|
||||||
|
sleep 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
UnmappedFolderCleanerProcess () {
|
||||||
log "Finding UnmappedFolders to purge..."
|
log "Finding UnmappedFolders to purge..."
|
||||||
OLDIFS="$IFS"
|
OLDIFS="$IFS"
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
|
@ -44,5 +93,19 @@ for folder in $(echo "$unmappedFolders"); do
|
||||||
rm -rf "$folder"
|
rm -rf "$folder"
|
||||||
done
|
done
|
||||||
IFS="$OLDIFS"
|
IFS="$OLDIFS"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Loop Script
|
||||||
|
for (( ; ; )); do
|
||||||
|
let i++
|
||||||
|
logfileSetup
|
||||||
|
verifyConfig
|
||||||
|
getArrAppInfo
|
||||||
|
verifyApiAccess
|
||||||
|
UnmappedFolderCleanerProcess
|
||||||
|
log "Script sleeping for $recyclarrScriptInterval..."
|
||||||
|
sleep $recyclarrScriptInterval
|
||||||
|
done
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
Loading…
Reference in a new issue