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.
11 # Check if the given program is installed. Returns 0 if it exists, 1
12 # otherwise; so it can be used in if.
14 which $1 2>&1 | perl -ne 'if (not m{^/}) { exit 1 }'
17 # Print the current OS. The following OS are supported at the moment:
21 # - Solaris/OpenSolaris (sun)
22 # If an unsupported OS is used an error is printed.
24 if [ -f /etc/debian_version ]; then
26 elif [ -f /etc/gentoo-release ]; then
28 elif [ x`uname` = xDarwin ]; then
30 elif [ x`uname` = xSunOS ]; then
33 echo unsupported OS! >&2
38 # Creates a symbolic link for file $1 in dirname of $2 with name of basename
41 # `./link.sh example ~/.examplerc` creates a symbolic link to example
42 # (wherever it is located) in ~/ named .examplerc.
44 # Get all necessary paths.
47 source=`echo "$pwd/$1" | sed "s|$base/||"`
48 target=`basename "$2"`
50 # Go to the directory where the link is going to be created.
53 # Abort if the target file exists and is no symbolic link. Prevents
54 # overwriting real files.
55 if [ -e "$target" -a ! -h "$target" ]; then
56 echo "link(): target '$target' exists already and is no symbolic link!" >&2
60 # Make sure the source exists.
61 if [ ! -e "$source" ]; then
62 echo "link(): source '$source' doesn't exist!" >&2
66 # Create the new symbolic link; remove the old one if necessary.
67 echo "link(): linking '$source' to '$target'"
69 ln -s "$source" "$target"
71 # Go back to the directory where we were before.
74 unset pwd base source target
77 # Write a warning to $1 to make clear it should not be modified. $2 is the
78 # source for the generated file. Also print a message to stdout that the file
79 # $1 was generated from $2 using the command $3 with options $4.
81 echo "###################################" > $1
82 echo "# WARNING! DO NOT EDIT THIS FILE! #" >> $1
83 echo "###################################" >> $1
85 echo "# It was generated from $2 on `date`." >> $1
88 # Display given options if there were any (Zsh has a problem with $options
92 option=" with options '$4'"
94 # Write message to stdout.
95 echo "$3: generating '$1' from '$2'$option"
100 # Generate a file using several methods. A warning not to edit it is
101 # automatically added to the created file and a message printed to stdout
104 # The following commands are possible; the file extension for the source file
107 # - m4 (.m4): pipe $2.m4 through m4 then write it to $2
108 # - awk (.in): pipe $2.in through awk then write it to $2
109 # - perl (.in): pipe $2.in through perl then write it to $2
110 # - cat ($3): copy $2$3 to $2
112 # Get command and target file.
115 # Remove arguments from list.
119 # Set extension for the used commands. When cat is used $3 is used as
121 if [ x"$command" = xm4 ]; then
123 elif [ x"$command" = xawk -o x"$command" = xperl ]; then
125 elif [ x"$command" = xcat ]; then
126 extension="$1" # is $3 in reality, $1 because of shifting
128 # Print a warning and exit if an unsupported command is used.
130 echo "generate(): command '$command' not supported!" >&2
134 # Add warning to file and write a message to stdout.
135 warning "$file" "$file$extension" $command "$*"
136 # Generate $file from $file$extension using the given command.
137 cat "$file$extension" | $command "$@" >> "$file"