X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=lib.sh;h=88b7b98a26f2ba84cf2c141191bc296dbac48ddc;hb=8c731331a353d82adc61a81bd3cb92e79f3c2dc8;hp=582e1cffe66b1f440dcec0744c08f336fffeb8ea;hpb=f8404b8badbb07ea82dd043127838fd7ef562ba9;p=config%2Fdotfiles.git diff --git a/lib.sh b/lib.sh index 582e1cf..88b7b98 100644 --- a/lib.sh +++ b/lib.sh @@ -11,6 +11,25 @@ unset LS_COLORS m4=`which m4` +# Check if the given program is installed. Returns 0 if it exists, 1 +# otherwise; so it can be used in if. +installed() { + which $1 | grep -E '^/' > /dev/null +} + +# Prints the current OS. Supported are Debian (debian) and Mac OS X (darwin) +# at the moment. If an unsupported OS is used an error is printed. +os() { + if [ -f /etc/debian_version ]; then + echo debian + elif [ x`uname` = xDarwin ]; then + echo darwin + else + echo unsupported OS! >&2 + return 1 + fi +} + # Creates a symbolic link for file $1 in dirname of $2 with name of basenmae # $2. # @@ -54,6 +73,11 @@ link() { # to $1 with a warning at the beginning to not edit the generated file. # # All arguments (except the first which is the filename) are passed to m4. +# +# The following macros are defined: IF and FI. Example: +# IF(OS, debian) +# ... +# FI m4() { # First argument is file name. file=$1 @@ -69,7 +93,11 @@ m4() { # Process $1.m4 with m4 using the given options. echo "m4(): generating '$file' from '$file.m4' with options '$*'" - $m4 $* $file.m4 >> $file + # Add useful macros. + (echo "define(\`IF', \`ifelse(\`\$1', \`\$2',dnl')dnl +define(\`FI', \`)dnl')dnl"; + # Run the file (and the default macros) through m4. + cat $file.m4) | $m4 $* >> $file unset file }