]> ruderich.org/simon Gitweb - config/dotfiles.git/blob - link.sh
Add better debug output to m4.sh and link.sh.
[config/dotfiles.git] / link.sh
1 #!/bin/sh
2
3 # Creates a symbolic link for file $1 in dirname of $2 with name of basenmae
4 # $2.
5 #
6 # `./link.sh example ~/.examplerc` creates a symbolic link to example
7 # (wherever it is located) in ~/ named .examplerc.
8
9
10 # Get all necessary paths.
11 pwd=`pwd`
12 base=`dirname "$2"`
13 source=`echo -n "$pwd/$1" | sed "s|$base/||"`
14 target=`basename "$2"`
15
16 # Go to the directory where the link is going to be created.
17 cd "$base"
18
19 # Abort if the target file exists and is no symbolic link. Prevents
20 # overwriting real files.
21 if [ -e "$target" -a ! -h "$target" ]; then
22     echo "link.sh: target '$target' exists already and is no symbolic link!" >&2
23     exit 1
24 fi
25
26 # Make sure the source exists.
27 if [ ! -e "$source" ]; then
28     echo "link.sh: source '$source' doesn't exist!" >&2
29     exit 1
30 fi
31
32 # Create the new symbolic link; remove the old one if necessary.
33 echo "link.sh: linking '$source' to '$target'"
34 rm -f "$target"
35 ln -s "$source" "$target"