From 01bba8d29be5b59ddb02cc6787cf49fec3c76922 Mon Sep 17 00:00:00 2001 From: RandomNinjaAtk Date: Tue, 8 Nov 2022 16:48:58 -0500 Subject: [PATCH] New script, only for manual use.... Removes unmapped folders --- root/scripts/UnmappedFolderCleaner.bash | 45 +++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 root/scripts/UnmappedFolderCleaner.bash diff --git a/root/scripts/UnmappedFolderCleaner.bash b/root/scripts/UnmappedFolderCleaner.bash new file mode 100644 index 0000000..cb515b2 --- /dev/null +++ b/root/scripts/UnmappedFolderCleaner.bash @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +scriptVersion="1.0.0" + +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 + 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 + +# auto-clean up log file to reduce space usage +if [ -f "/config/logs/UnmappedFolderCleaner.txt" ]; then + find /config/logs -type f -name "UnmappedFolderCleaner.txt" -size +1024k -delete +fi + +exec &>> "/config/logs/UnmappedFolderCleaner.txt" +chmod 666 "/config/logs/UnmappedFolderCleaner.txt" + +log () { + m_time=`date "+%F %T"` + echo $m_time" :: UnmappedFolderCleaner :: $scriptVersion :: "$1 +} + +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..." + exit +fi +for folder in $(echo "$unmappedFolders"); do + log "Removing $folder" + rm -rf "$folder" +done +IFS="$OLDIFS" + +exit