]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - lib.sh
lib.sh: Move warning code to own function.
[config/dotfiles.git] / lib.sh
diff --git a/lib.sh b/lib.sh
index 88b7b98a26f2ba84cf2c141191bc296dbac48ddc..6cd3d2f8d79adf7cb662ae6347fd394c8966e172 100644 (file)
--- a/lib.sh
+++ b/lib.sh
@@ -17,11 +17,14 @@ 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.
+# Prints the current OS. Supported are Debian (debian), Gentoo (gentoo) 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 [ -f /etc/gentoo-release ]; then
+        echo gentoo
     elif [ x`uname` = xDarwin ]; then
         echo darwin
     else
@@ -69,6 +72,17 @@ link() {
     unset pwd base source target
 }
 
+# Write a warning to $1 to make clear it should not be modified. $2 is the
+# source for the generated file.
+setup_warning() {
+    echo "###################################" > $1
+    echo "# WARNING! DO NOT EDIT THIS FILE! #" >> $1
+    echo "###################################" >> $1
+    echo >> $1
+    echo "# It was generated from $2 on `date`." >> $1
+    echo >> $1
+}
+
 # m4 wrapper which uses $1.m4 as template file, feeds it to m4 and writes it
 # to $1 with a warning at the beginning to not edit the generated file.
 #
@@ -83,13 +97,8 @@ m4() {
     file=$1
     shift
 
-    # Write a warning to the generated file.
-    echo "###################################" > $file
-    echo "# WARNING! DO NOT EDIT THIS FILE! #" >> $file
-    echo "###################################" >> $file
-    echo >> $file
-    echo "# It was generated from $file.m4 on `date`." >> $file
-    echo >> $file
+    # Write a warning to the generated file to not edit it.
+    setup_warning $file $file.m4
 
     # Process $1.m4 with m4 using the given options.
     echo "m4(): generating '$file' from '$file.m4' with options '$*'"
@@ -97,7 +106,7 @@ m4() {
     (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
+        cat $file.m4) | $m4 "$@" >> $file
 
     unset file
 }