lidarr-dl/radarr/UnmappedFolderCleaner.bash

58 lines
1.4 KiB
Bash
Raw Normal View History

2023-07-15 21:39:43 +02:00
#!/usr/bin/env bash
2023-07-20 13:08:44 +02:00
scriptVersion="1.4"
2023-07-15 21:50:52 +02:00
scriptName="UnmappedFolderCleaner"
2023-07-15 21:39:43 +02:00
2023-07-20 13:08:44 +02:00
#### Import Settings
source /config/extended.conf
#### Import Functions
source /config/extended/functions
#### Create Log File
2023-07-19 16:45:37 +02:00
logfileSetup
2023-07-15 21:50:52 +02:00
verifyConfig () {
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
}
UnmappedFolderCleanerProcess () {
log "Finding UnmappedFolders to purge..."
OLDIFS="$IFS"
IFS=$'\n'
unmappedFolders=$(curl -s "$arrUrl/api/v3/rootFolder" -H "X-Api-Key: $arrApiKey" | jq -r ".[].unmappedFolders[].path")
unmappedFoldersCount=$(echo -n "$unmappedFolders" | wc -l)
log "$unmappedFoldersCount Folders Found!"
if [ $unmappedFoldersCount = 0 ]; then
log "No cleanup required, exiting..."
return
2023-07-15 21:50:52 +02:00
fi
for folder in $(echo "$unmappedFolders"); do
log "Removing $folder"
rm -rf "$folder"
done
IFS="$OLDIFS"
}
# Loop Script
for (( ; ; )); do
let i++
logfileSetup
log "Script starting..."
2023-07-15 21:50:52 +02:00
verifyConfig
getArrAppInfo
verifyApiAccess
UnmappedFolderCleanerProcess
2023-07-15 21:51:19 +02:00
log "Script sleeping for $unmappedFolderCleanerScriptInterval..."
sleep $unmappedFolderCleanerScriptInterval
2023-07-15 21:39:43 +02:00
done
exit