Skip to content

Instantly share code, notes, and snippets.

@fritolays
Last active March 11, 2024 15:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fritolays/da5b835080ad0a4f8a48013b7b7745d8 to your computer and use it in GitHub Desktop.
Save fritolays/da5b835080ad0a4f8a48013b7b7745d8 to your computer and use it in GitHub Desktop.
This script enables the Mover Tuning plugin for Unraid to be able to exclude files and/or folders.
#!/bin/bash
# (https://forums.unraid.net/topic/70783-plugin-mover-tuning/)
# This script enables the Mover Tuning plugin for Unraid to be able to exclude files and/or folders.
# Script activity can be viewed in Unraid's system log (Tools -> System Log).
# First, it reads lists of directories and files from provided text files.
# Then, it converts any Windows line endings to Unix line endings in these lists.
# Next, it checks if the paths listed in the files are valid directories or files.
# Finally, valid file and directory paths are compiled into a single output file for use by the Mover Tuning plugin.
# Mover Tuning plugin settings:
# "Ignore files listed inside of a text file" - set to Yes
# "File list path" - set to output file path (mover_tuning_exclusions.txt)
# "Script to run before mover (No checks, always runs)" - set to the script file path (mover_tuning_exclusions.sh)
# "Move Now button follows plug-in filters" - set to yes
# Note: Ensure this script file has execute permission and the correct owner and group IDs.
# Set permission and owner/group IDs with the following commands:
# chmod +x /path/to/this/script.sh
# chown 99:100 /path/to/this/script.sh
# Script folder path
SCRIPT_FOLDER="/mnt/user/appdata/misc"
# Temporary file for intermediate processing
TEMP_FILE="$SCRIPT_FOLDER/mover_tuning_temp.txt"
# File containing the list of directories to recursively search for files (one per line)
EXCLUDED_DIRECTORIES_LIST="$SCRIPT_FOLDER/mover_tuning_excluded_directories.txt"
# File containing a list of individual files to exclude, each with a complete path (one per line)
EXCLUDED_FILES_LIST="$SCRIPT_FOLDER/mover_tuning_excluded_files.txt"
# Output file that will contain the complete, validated list of excluded files
OUTPUT_EXCLUSIONS="$SCRIPT_FOLDER/mover_tuning_exclusions.txt"
# Function to clean up temporary file on exit
cleanup() {
rm -f "$TEMP_FILE"
}
trap cleanup EXIT
# Function to convert line endings and validate paths
convert_line_endings_and_validate_paths() {
local file_list=$1
local check_type=$2 # 'file' or 'directory'
local line_number=0
# Convert Windows line endings to Unix line endings
sed -i 's/\r$//' "$file_list"
while IFS= read -r path || [ -n "$path" ]; do
((line_number++))
if [ "$check_type" = "file" ] && [ -f "$path" ]; then
echo "$path" >> "$TEMP_FILE"
elif [ "$check_type" = "directory" ] && [ -d "$path" ]; then
find "$path" -type f -print >> "$TEMP_FILE"
else
echo "script: Error: Skipping invalid $check_type path, line $line_number in $(basename "$file_list")"
fi
done < "$file_list"
}
echo "script: Generating exclusions list..."
# Process excluded files list if it exists
if [ -f "$EXCLUDED_FILES_LIST" ]; then
echo "script: Validating $EXCLUDED_FILES_LIST"
convert_line_endings_and_validate_paths "$EXCLUDED_FILES_LIST" "file"
else
echo "script: Warning: Skipping excluded files, cannot find $EXCLUDED_FILES_LIST"
fi
# Process excluded directories list if it exists
if [ -f "$EXCLUDED_DIRECTORIES_LIST" ]; then
echo "script: Validating $EXCLUDED_DIRECTORIES_LIST"
convert_line_endings_and_validate_paths "$EXCLUDED_DIRECTORIES_LIST" "directory"
else
echo "script: Warning: Skipping excluded directories, cannot find $EXCLUDED_DIRECTORIES_LIST"
fi
# Remove blank lines and move the temporary file to the final output
sed '/^$/d' "$TEMP_FILE" > "$OUTPUT_EXCLUSIONS"
# Signal completion of the process with a message
echo "script: Generated exclusions list $OUTPUT_EXCLUSIONS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment