d381326bc98d371fe026788dbd2d6183025a7773
[cmccabe-etc] / install-symlinks.sh
1 #!/bin/bash
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 BASEDIR=`pwd`
19 for file in ${BASEDIR}/.[^.]*; do
20         # get base file name, like ".gitconfig"
21         basefile=`basename ${file}`
22
23         # get relative file name, like "cmccabe-etc/.gitconfig"
24         relfile=`echo ${file} | sed 's_.*/\([^/]*/[^/]*\)$_\1_'`
25
26         # skip files which we don't want to link
27         if [ "${basefile}" == ".git" ]; then
28                 continue;
29         fi
30
31         pushd .. > /dev/null
32         if [ -L ${basefile} ]; then
33                 # Someone already created this link. Pass over it in silence
34                 :
35         elif [ ! -a ${basefile} ]; then
36                 # Create the link
37                 ln -s ${relfile} || die "failed to link ${relfile}"
38                 echo "created ${relfile}..."
39         elif [ -f ${basefile} ]; then
40                 echo "${basefile} already exists as a regular file"
41         else
42                 echo "${basefile} already exists"
43         fi
44         popd > /dev/null
45 done