Created
January 7, 2014 16:28
-
-
Save hinnerk/8301976 to your computer and use it in GitHub Desktop.
Soft-link all files/directories from current path into `~/Library/Application Support`. I used this some time ago to keep settings under revision management and, by extension, synched between multiple Mac OS X machines.
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/sh | |
DEBUG="yes" | |
filename="INIT_NO_FILE" | |
TODIR="$HOME/Library/Application Support" | |
FROMDIR="`pwd`" | |
# Functions | |
debugmessage() { | |
test $DEBUG = yes && | |
echo "`date +%H:%M:%S` #DEBUG: $filename: $1" | |
} | |
linkit() { | |
ln -si "$FROMDIR/$filename" "$TODIR/$filename" && | |
echo "OK: $filename: Link created." || | |
echo "ERR: $filename: Link *NOT* created." | |
} | |
# Main program | |
debugmessage "Started, DEBUG output enabled" | |
debugmessage "Traversing list of all files." | |
if [ $FROMDIR = $HOME ] ; then | |
debugmessage "Checking if the current directory is plausible." | |
echo "Directory not plausible ($FROMDIR), cancelling." | |
exit 1 | |
fi | |
debugmessage "Get the list of all files" | |
for filename in `echo "[A-Z]*"` | |
do | |
if [ -L "$TODIR/$filename" ] ; then | |
debugmessage "This is a link." | |
ls -l "$TODIR/$filename" | grep $FROMDIR >/dev/null | |
if [ $? = 0 ] ; then | |
debugmessage "Everything seems fine." | |
else | |
debugmessage "This link does not belong to us" | |
echo "ERR: $filename: Strange link target?" | |
fi | |
else | |
debugmessage "No link exists." | |
if [ -e "$TODIR/$filename" ] ; then | |
debugmessage "Exists but it is not a link. Checking with diff..." | |
diff -qr "$TODIR/$filename" "$FROMDIR/$filename" >/dev/null | |
if [ $? = 0 ] ; then | |
debugmessage "The files are identical (according to diff -rq), trying to remove one of them." | |
echo "$FROMDIR/$filename and $TODIR/$filename seem identical, remove the one existing in $TODIR?" | |
rm -ird "$TODIR/$filename" | |
if [ $? = 0 ] ; then | |
debugmessage "File was removed, creating link..." | |
linkit | |
else | |
debugmessage "Unable to remove file!" | |
echo "ERR: $TODIR/$filename: Please remove manually." | |
fi | |
else | |
debugmessage "Files differ, human attention needed." | |
echo "ERR: $filename: You need to cleanup manually." | |
fi | |
else | |
debugmessage "File does not exist, creating link..." | |
linkit | |
fi | |
fi | |
done | |
filename=END_NO_FILE | |
debugmessage "FINISHED." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment