Add the install-symlinks.sh script
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 18 Feb 2010 23:18:30 +0000 (15:18 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 18 Feb 2010 23:18:30 +0000 (15:18 -0800)
install-symlinks.sh [new file with mode: 0755]

diff --git a/install-symlinks.sh b/install-symlinks.sh
new file mode 100755 (executable)
index 0000000..3588ed2
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+#
+# install-symlinks.sh
+#
+# Script for installing symlinks to these rc files into your home directory.
+# It's assumed that your home directory is the directory immediately above this
+# one.
+#
+# Colin McCabe
+#
+
+die() {
+       echo "$@"
+       exit 1
+}
+
+FULLPATH=`readlink -f $0`
+BASEDIR=`dirname ${FULLPATH}`
+for file in ${BASEDIR}/.[^.]*; do
+       # get base file name, like ".gitconfig"
+       basefile=`basename ${file}`
+
+       # get relative file name, like "cmccabe-etc/.gitconfig"
+       relfile=`echo ${file} | sed 's_.*/\([^/]*/[^/]*\)$_\1_'`
+
+       # skip files which we don't want to link
+       if [ "${basefile}" == ".git" ]; then
+               continue;
+       fi
+
+       pushd .. > /dev/null
+       if [ -L ${basefile} ]; then
+               # Someone already created this link. Pass over it in silence
+               :
+       elif [ -z ${basefile} ]; then
+               # Create the link
+               ln -s ${relfile} || die "failed to link ${relfile}"
+               echo "created ${relfile}..."
+       elif [ -f ${basefile} ]; then
+               echo "${basefile} already exists as a regular file"
+       else
+               echo "${basefile} already exists"
+       fi
+       popd > /dev/null
+done