Fix bug in install-symlinks
[cmccabe-etc] / install-symlinks.sh
1 #!/bin/sh
2
3 #
4 # install-symlinks.sh
5 #
6 # Script for installing symlinks to these rc files into your home directory.
7 # It's assumed that your home directory is the directory immediately above this
8 # one.
9 #
10 # Colin McCabe
11 #
12
13 die() {
14         echo "$@"
15         exit 1
16 }
17
18 FULLPATH=`readlink -f $0`
19 BASEDIR=`dirname ${FULLPATH}`
20 for file in ${BASEDIR}/.[^.]*; do
21         # get base file name, like ".gitconfig"
22         basefile=`basename ${file}`
23
24         # get relative file name, like "cmccabe-etc/.gitconfig"
25         relfile=`echo ${file} | sed 's_.*/\([^/]*/[^/]*\)$_\1_'`
26
27         # skip files which we don't want to link
28         if [ "${basefile}" == ".git" ]; then
29                 continue;
30         fi
31
32         pushd .. > /dev/null
33         if [ -L ${basefile} ]; then
34                 # Someone already created this link. Pass over it in silence
35                 :
36         elif [ ! -a ${basefile} ]; then
37                 # Create the link
38                 ln -s ${relfile} || die "failed to link ${relfile}"
39                 echo "created ${relfile}..."
40         elif [ -f ${basefile} ]; then
41                 echo "${basefile} already exists as a regular file"
42         else
43                 echo "${basefile} already exists"
44         fi
45         popd > /dev/null
46 done