1 # Setup functions and settings used in subdirectories.
3 # Their setup.sh script sources this file.
6 # csh gives the error "Unknown colorls variable `su'." when used with newer
7 # options supported by zsh or GNU ls.
10 # Get path to m4 because it's later redefined as function.
14 # Check if the given program is installed. Returns 0 if it exists, 1
15 # otherwise; so it can be used in if.
17 which $1 | grep -E '^/' > /dev/null
20 # Prints the current OS. Supported are Debian (debian) and Mac OS X (darwin)
21 # at the moment. If an unsupported OS is used an error is printed.
23 if [ -f /etc/debian_version ]; then
25 elif [ x`uname` = xDarwin ]; then
28 echo unsupported OS! >&2
33 # Creates a symbolic link for file $1 in dirname of $2 with name of basenmae
36 # `./link.sh example ~/.examplerc` creates a symbolic link to example
37 # (wherever it is located) in ~/ named .examplerc.
39 # Get all necessary paths.
42 source=`echo -n "$pwd/$1" | sed "s|$base/||"`
43 target=`basename "$2"`
45 # Go to the directory where the link is going to be created.
48 # Abort if the target file exists and is no symbolic link. Prevents
49 # overwriting real files.
50 if [ -e "$target" -a ! -h "$target" ]; then
51 echo "link(): target '$target' exists already and is no symbolic link!" >&2
55 # Make sure the source exists.
56 if [ ! -e "$source" ]; then
57 echo "link(): source '$source' doesn't exist!" >&2
61 # Create the new symbolic link; remove the old one if necessary.
62 echo "link(): linking '$source' to '$target'"
64 ln -s "$source" "$target"
66 # Go back to the directory where we were before.
69 unset pwd base source target
72 # m4 wrapper which uses $1.m4 as template file, feeds it to m4 and writes it
73 # to $1 with a warning at the beginning to not edit the generated file.
75 # All arguments (except the first which is the filename) are passed to m4.
77 # The following macros are defined: IF and FI. Example:
82 # First argument is file name.
86 # Write a warning to the generated file.
87 echo "###################################" > $file
88 echo "# WARNING! DO NOT EDIT THIS FILE! #" >> $file
89 echo "###################################" >> $file
91 echo "# It was generated from $file.m4 on `date`." >> $file
94 # Process $1.m4 with m4 using the given options.
95 echo "m4(): generating '$file' from '$file.m4' with options '$*'"
97 (echo "define(\`IF', \`ifelse(\`\$1', \`\$2',dnl')dnl
98 define(\`FI', \`)dnl')dnl";
99 # Run the file (and the default macros) through m4.
100 cat $file.m4) | $m4 $* >> $file