Skip to content

Instantly share code, notes, and snippets.

@scheasbro
Created November 20, 2017 18:36
Show Gist options
  • Save scheasbro/723142d24b87d62b6436ba3b8bf4f933 to your computer and use it in GitHub Desktop.
Save scheasbro/723142d24b87d62b6436ba3b8bf4f933 to your computer and use it in GitHub Desktop.
Dropbox Resolve Conflicted Copies - SDC Version
#!/bin/bash
#Thx, http://stackoverflow.com/questions/20723868/batch-rename-dropbox-conflict-files
#Point to where you want the script to look and where it should backup files it replaces
folder=~/Volumes/Seagate\ 4TB/Dropbox\ \(C3\ Ottawa\)
backup=~/Desktop/Script_Backup
#colors
red='\033[0;31m'
purple='\033[1;35m'
NC='\033[0m' # No Color
clear
echo "This script will climb through the $folder tree and repair conflict files by deleting the OLDER of the the conflicted file and its counterpart"
if [[ $1 == "replace" ]]; then
echo -e "${red}This is NOT a drill.${NC} The script will backup the older of the conflicted files and then delete it from the Dropbox directory."
else
Run "./Dropbox.sh replace\"
fi
echo "Press any key to continue..."
echo "------------------------------"
read -n 1
find $folder -type f -print0 | while read -d $'\0' file; do
newname=$(echo "$file" | sed 's/ (.*conflicted copy.*)//')
if [ "$file" != "$newname" ]; then
if [ -f "$newname" ];then
# determine which is newer
if [ "$newname" -nt "$file" ]; then
echo "$newname is NEWER than $file"
file_to_move="$file"
file_to_keep="$newname"
else
echo "$newname is OLDER than $file"
file_to_move="$newname"
file_to_keep="$file"
fi
backupname=${newname/"$folder"/"$backup"}
if [[ $1 != "replace" ]]; then
echo "Would have moved $file_to_move to $backupname"
else
echo "Moving $file_to_move to $backupname"
mkdirp "$(dirname "$backupname")"
cp "$file_to_move" "$backupname"
mv "$file_to_keep" "$newname"
fi
else
# if the unconflicted version isn't there for some reason, just rename the original
if [[ $1 != "replace" ]]; then
echo "Didn't see an unconflicted counterpart for $file, so would have just renamed file"
else
echo "Didn't see an unconflicted counterpart for $file, so will replace"
mv "$file" "$newname"
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment