+#! /bin/sh
+### -*-sh-*-
+###
+### Make autoconf-like substitutions in files
+###
+### (c) 2008 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of the Common Files Distribution (`common').
+###
+### `Common' is free software; you can redistribute it and/or modify
+### it under the terms of the GNU General Public License as published by
+### the Free Software Foundation; either version 2 of the License, or
+### (at your option) any later version.
+###
+### `Common' is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+### GNU General Public License for more details.
+###
+### You should have received a copy of the GNU General Public License
+### along with `common'; if not, write to the Free Software Foundation,
+### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+set -e
+
+VERSION="@VERSION@"
+
+###--------------------------------------------------------------------------
+### Parse command line arguments.
+
+while [ $# -gt 0 ]; do
+ case $1 in
+ -h | --h | --he | --hel | --help)
+ cat <<EOF
+Usage: confsubst FILE TAG=VALUE...
+
+Replaces occurrences of @TAG@ in FILE with VALUE, and writes the result to
+standard output.
+EOF
+ exit 0
+ ;;
+ -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
+ echo "confsubst: Common Files Distribution version $VERSION"
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -)
+ break
+ ;;
+ -*)
+ echo "confsubst: unknown option \`$1'" >&2
+ exit 1
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
+
+if [ $# -lt 1 ]; then
+ echo >&2 "Usage: confsubst FILE TAG=VALUE..."
+ exit 1
+fi
+file=$1; shift
+
+###--------------------------------------------------------------------------
+### Main code.
+
+subst=""
+for fixup; do
+ case "$fixup" in
+ *?=*?) ;;
+ *) echo >&2 "$0: bad substitution: $fixup"; exit 1 ;;
+ esac
+ tag=$(echo "$fixup" | sed 's/=.*$//') && \
+ value=$(echo "$fixup" | sed 's/^[^=]*=//') && \
+ subst="$subst s\a@$tag@\a$value\ag;"
+done
+
+sed "$subst" $file || exit $?
+
+###----- That's all, folks --------------------------------------------------