#21
This commit is contained in:
RandomNinjaAtk 2023-07-16 13:32:42 -04:00 committed by GitHub
parent f00aa781db
commit baa47acdbb
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="0.1" scriptVersion="1.0"
scriptName="UnmappedFilesCleaner" scriptName="UnmappedFilesCleaner"
log () { log () {
@ -28,8 +28,8 @@ verifyConfig () {
sleep infinity sleep infinity
fi fi
if [ -z "$unmappedFilesCleanerScriptInterval" ]; then if [ -z "$unmappedFolderCleanerScriptInterval" ]; then
unmappedFilesCleanerScriptInterval="15m" unmappedFolderCleanerScriptInterval="15m"
fi fi
} }
@ -69,5 +69,36 @@ verifyApiAccess () {
done done
} }
UnmappedFilesCleanerProcess () {
log "Finding UnmappedFiles to purge..."
OLDIFS="$IFS"
IFS=$'\n'
unamppedFiles="$(curl -s "$arrUrl/api/v1/trackFile?unmapped=true" -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" | jq -r .[].path)"
if [ -z "$unamppedFiles" ]; then
log "No unmapped files to process"
return
fi
curl "$arrUrl/api/v1/trackFile?unmapped=true" -H 'Content-Type: application/json' -H "X-Api-Key: $arrApiKey" for file in $(echo "$unamppedFiles"); do
unmappedFileDirectory=$(dirname "$file")
if [ -d "$unmappedFileDirectory" ]; then
log "Deleting \"$unmappedFileDirectory\""
rm -rf "$unmappedFileDirectory"
fi
done
}
# Loop Script
for (( ; ; )); do
let i++
logfileSetup
log "Script starting..."
verifyConfig
getArrAppInfo
verifyApiAccess
UnmappedFilesCleanerProcess
log "Script sleeping for $unmappedFolderCleanerScriptInterval..."
sleep $unmappedFolderCleanerScriptInterval
done
exit