Created
April 4, 2024 22:47
-
-
Save Serneum/2f615f9490972677b36ad6c4ab8eee7f to your computer and use it in GitHub Desktop.
Hardlink or clean up existing files when new files are detected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
inotifywait -m -r /data/media/Anime -e create -e moved_to -e delete --format "%w%f@%e" | | |
while read -r fullpathwithevent; do | |
ev="${fullpathwithevent##*@}" | |
echo "Event: $ev" | |
fullpath=$(echo $fullpathwithevent | sed 's/@.*//') | |
echo "Full path: $fullpath" | |
file="${fullpath##*/}" | |
echo "File name: $file" | |
directory=$(dirname "${fullpath}") | |
echo "Directory name: $directory" | |
if [[ "$ev" == "DELETE" ]]; then | |
escaped_filename=$(echo $file | sed 's/\([][]\)/\\\1/g') | |
echo "$file was deleted. Deleting /data/media/ShokoAnime/dest/**/$file" | |
echo "find \"/data/media/ShokoAnime/dest\" -type f -name \"$escaped_filename\" -delete" | |
find "/data/media/ShokoAnime/dest" -type f -name "$escaped_filename" -delete | |
else | |
echo "Found file '$file' in directory '$directory'" | |
if [[ -f "$fullpath" ]]; then | |
echo "Moving '$file' to Shoko import directory" | |
echo "ln $fullpath /data/media/ShokoAnime/source/$file" | |
ln "$fullpath" "/data/media/ShokoAnime/source/$file" | |
fi | |
fi | |
echo "" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment