v1.2 - Actually remove data and clear entries from Lidarr

This commit is contained in:
RandomNinjaAtk 2023-07-19 20:27:59 -04:00 committed by GitHub
parent 70781aa42b
commit cd6578a965
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
#!/usr/bin/with-contenv bash #!/usr/bin/with-contenv bash
scriptVersion="1.1" scriptVersion="1.2"
scriptName="UnmappedFilesCleaner" scriptName="UnmappedFilesCleaner"
log () { log () {
@ -10,11 +10,13 @@ log () {
logfileSetup () { logfileSetup () {
# auto-clean up log file to reduce space usage # auto-clean up log file to reduce space usage
if [ -f "/config/logs/$scriptName.txt" ]; then if [ -f "/config/logs/$scriptName.txt" ]; then
find /config/logs -type f -name "$scriptName.txt" -size +1024k -delete if find /config/logs -type f -name "$scriptName.txt" -size +1024k | read; then
echo "" > /config/logs/$scriptName.txt
fi
fi fi
if [ ! -f "/config/logs/$scriptName.txt" ]; then if [ ! -f "/config/logs/$scriptName.txt" ]; then
touch "/config/logs/$scriptName.txt" echo "" > /config/logs/$scriptName.txt
chmod 666 "/config/logs/$scriptName.txt" chmod 666 "/config/logs/$scriptName.txt"
fi fi
} }
@ -78,18 +80,24 @@ UnmappedFilesCleanerProcess () {
log "Finding UnmappedFiles to purge..." log "Finding UnmappedFiles to purge..."
OLDIFS="$IFS" OLDIFS="$IFS"
IFS=$'\n' IFS=$'\n'
unamppedFiles="$(curl -s "$arrUrl/api/v1/trackFile?unmapped=true" -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" | jq -r .[].path)" unamppedFilesData="$(curl -s "$arrUrl/api/v1/trackFile?unmapped=true" -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" | jq -r .[])"
if [ -z "$unamppedFiles" ]; then unamppedFileIds="$(curl -s "$arrUrl/api/v1/trackFile?unmapped=true" -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" | jq -r .[].id)"
if [ -z "$unamppedFileIds" ]; then
log "No unmapped files to process" log "No unmapped files to process"
return return
fi fi
for file in $(echo "$unamppedFiles"); do for id in $(echo "$unamppedFileIds"); do
unmappedFileDirectory=$(dirname "$file") unmappedFilePath=$(echo "$unamppedFilesData" | jq -r ". | select(.id==$id)| .path")
unmappedFileName=$(basename "$unmappedFilePath")
unmappedFileDirectory=$(dirname "$unmappedFilePath")
if [ -d "$unmappedFileDirectory" ]; then if [ -d "$unmappedFileDirectory" ]; then
log "Deleting \"$unmappedFileDirectory\"" log "Deleting \"$unmappedFileDirectory\""
rm -rf "$unmappedFileDirectory" rm -rf "$unmappedFileDirectory"
fi fi
log "Removing $unmappedFileName ($id) entry from lidarr..."
lidarrCommand=$(curl -s "$arrUrl/api/v1/trackFile/$id" -X DELETE -H "X-Api-Key: $arrApiKey")
done done
} }