v1.2 - Actually remove data and clear entries from Lidarr
This commit is contained in:
parent
70781aa42b
commit
cd6578a965
1 changed files with 21 additions and 13 deletions
|
@ -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,12 +10,14 @@ 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")
|
||||||
if [ -d "$unmappedFileDirectory" ]; then
|
unmappedFileName=$(basename "$unmappedFilePath")
|
||||||
log "Deleting \"$unmappedFileDirectory\""
|
unmappedFileDirectory=$(dirname "$unmappedFilePath")
|
||||||
rm -rf "$unmappedFileDirectory"
|
if [ -d "$unmappedFileDirectory" ]; then
|
||||||
fi
|
log "Deleting \"$unmappedFileDirectory\""
|
||||||
|
rm -rf "$unmappedFileDirectory"
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue