install-symlinks.sh: chmod 600 everything in the .ssh dir
[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 if [ -f ../.bashrc ]; then
19     if [ -L ../.bashrc ]; then
20         :
21     else
22         echo "moving old .bashrc to .bashrc-old"
23         mv -f ../.bashrc ../.bashrc-old
24     fi
25 fi
26
27 copy_ssh_old=0
28 if [ -d ../.ssh ]; then
29     if [ -L ../.ssh ]; then
30         :
31     else
32         echo "moving old .ssh to .ssh-old"
33         mv -f ../.ssh ../.ssh-old
34         copy_ssh_old=1
35     fi
36 fi
37
38 BASEDIR=`pwd`
39 for file in ${BASEDIR}/.[^.]*; do
40         # get base file name, like ".gitconfig"
41         basefile=`basename ${file}`
42
43         # get relative file name, like "cmccabe-etc/.gitconfig"
44         relfile=`echo ${file} | sed 's_.*/\([^/]*/[^/]*\)$_\1_'`
45
46         # skip files which we don't want to link
47         [ "${basefile}" == ".git" ] && continue
48         [ "${basefile}" == ".gitignore" ] && continue
49
50         pushd .. > /dev/null
51         if [ -L ${basefile} ]; then
52                 # Someone already created this link. Pass over it in silence
53                 :
54         elif [ ! -a ${basefile} ]; then
55                 # Create the link
56                 ln -s ${relfile} || die "failed to link ${relfile}"
57                 echo "created ${relfile}..."
58         elif [ -f ${basefile} ]; then
59                 echo "${basefile} already exists as a regular file"
60         else
61                 echo "${basefile} already exists"
62         fi
63         popd > /dev/null
64 done
65
66 if [ $copy_ssh_old -eq 1 ]; then
67     echo "copying files from .ssh-old to .ssh"
68     cp -f ../.ssh-old/* ../.ssh
69     echo "chmod 600 ../.ssh/config"
70     chmod 600 ../.ssh/*
71 fi