Skip to content

Instantly share code, notes, and snippets.

@gadgetmies
Last active April 30, 2023 20:54
Show Gist options
  • Save gadgetmies/f23865458741155982c3455f1b53e26c to your computer and use it in GitHub Desktop.
Save gadgetmies/f23865458741155982c3455f1b53e26c to your computer and use it in GitHub Desktop.
Scripts for syncing tracks to a CDJ-compatible drive on a Mac
#!/bin/sh
# Use this script to remove special characters from the names of your files to make it easier to sync them between filesystems (e.g. APFS, NTFS and FAT32)
DIR=
EXTENSION="*.mp3"
# DEBUG=true # Remove '#' from the beginning of the line to also print out files not being renamed
if [ -z $DIR ]; then
echo "DIR not set. Please set it to the folder containing your files to be renamed"
fi
IFS=$'\n'; set -f # Prevent space or special characters from breaking the filenames and paths
for f in $(find /volume1/Storage/Purchased/ -name "$EXTENSION"); do
filename="${f##*/}" # get filename
dirname="${f%/*}" # get directory/path name
renamed="$(printf '%s\n' "$filename" | sed 's/[^\x20-\x7e]/_/g')" # Replace all characters with underscore that are not between x20 - x7e in ASCII
if [ "$filename" != "$renamed" ]; then
mv -- "$f" "$dirname"/"$renamed"
echo "Renamed $filename to $renamed"
elif [ $DEBUG ]
echo "Not renaming $filename"
fi
done
unset IFS; set +f
#!/bin/sh
# Use this to sync files from your main storage (e.g. folder on your laptop or NAS) to a secondary storage (e.g. removable drive like USB stick or SSD)
# This script should work with CDJ-compatible (i.e. FAT32) filesystems. (rsync by default does not work properly with MacOS/Linux and FAT32 filesystems: https://serverfault.com/a/144475)
BACKUP_DIR=~/Documents/Sync_backup
SOURCE_DIR=
DESTINATION_DIR=
if [ -z $SOURCE_DIR ] | [ -z $DESTINATION_DIR ]; then
echo "Please set SOURCE_DIR and DESTINATION_DIR by editing the script"
exit 1
fi
echo "Syncing from $SOURCE_DIR to $DESTINATION_DIR and backing up deleted files to $BACKUP_DIR"
mkdir -p $BACKUP_DIR
rsync -rltDvh --size-only --backup --backup-dir $BACKUP_DIR --partial --progress --delete "$SOURCE_DIR/" "$DESTINATION_DIR/"
echo "Sync complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment