From: Colin Patrick McCabe Date: Thu, 18 Feb 2010 23:18:30 +0000 (-0800) Subject: Add the install-symlinks.sh script X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a52fadc70df8054a6017d899f53a635f4fcdb82f;p=cmccabe-etc Add the install-symlinks.sh script --- diff --git a/install-symlinks.sh b/install-symlinks.sh new file mode 100755 index 0000000..3588ed2 --- /dev/null +++ b/install-symlinks.sh @@ -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