+# $Id: vserver-build.rpm,v 1.6 2005/07/03 13:17:38 ensc Exp $ --*- sh -*--
+
+# Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
+#
+# This program 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; version 2 of the License.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+tmp=$(getopt -o +d:b:e --long debug,empty -n "$0" -- "$@") || exit 1
+eval set -- "$tmp"
+
+. "$_LIB_VSERVER_BUILD_FUNCTIONS_RPM"
+. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
+
+set -e
+
+
+BASEDIR=$(pwd)
+DISTRIBUTION=
+EMPTY=
+
+echo "$@"
+
+while true; do
+ case "$1" in
+ (-d) DISTRIBUTION=$2; shift;;
+ (-b) BASEDIR=$2; shift;;
+ (-e|--empty) EMPTY=1;;
+ (--debug) set -x;;
+ (--) shift; break ;;
+ (*) echo "vserver-build.rpm: internal error: unrecognized option '$1'" >&2
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+
+####### some basic initializations
+
+getDistribution "template"
+
+base.init
+pkgmgmt.initVariables
+rpm.initVariables
+
+if test -z "$EMPTY" -a "$#" -eq 0; then
+ rpmlist.initByDistribution rpm_lists "$DISTRIBUTION"
+ set -- "${rpm_lists[@]}"
+fi
+
+test -n "$EMPTY" -o "$#" -gt 0 || \
+ panic $"\
+No rpm-lists specified and no list found for distribution '$DISTRIBUTION'.
+When this is really indented, please use the '--empty' option."
+
+rpm_dflt_opts=()
+test "$OPTION_DEBUG" -lt 2 || rpm_dflt_opts=( "${rpm_dflt_opts[@]}" -v )
+test "$OPTION_DEBUG" -lt 3 || rpm_dflt_opts=( "${rpm_dflt_opts[@]}" -v )
+test -n "$OPTION_SILENT" || rpm_dflt_opts=( "${rpm_dflt_opts[@]}" -vh )
+
+
+###### init the filesystem
+
+base.initFilesystem "$OPTION_FORCE"
+pkgmgmt.initFilesystem "$OPTION_FORCE"
+rpm.initFilesystem
+
+setup_writeOption "$VSERVER_NAME"
+setup_writeInitialFstab
+
+
+# when basedir is a non-local location, rpm will download it into the
+# current directory. Therefore, create and go into a temporay directory
+# before doing the operations.
+tmpdir=$($_MKTEMPDIR /var/tmp/vserver-build.rpm.XXXXXX)
+manifest=$($_MKTEMP /tmp/vserver-build.rpm.manifest.XXXXXX)
+trap "rm -rf $tmpdir $manifest" EXIT
+cd "$tmpdir"
+
+
+###### do the real work
+
+test -z "$BUILD_INITPRE" || "$BUILD_INITPRE" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+rpm.initDB "$SETUP_CONFDIR"
+rpm.importGPGPubKeys "$SETUP_CONFDIR" \
+ "$__CONFDIR/.distributions/$DISTRIBUTION/pubkeys" \
+ "$__CONFDIR/.distributions/.common/pubkeys" \
+ "$__DISTRIBDIR/$DISTRIBUTION/pubkeys"
+
+opts=()
+for i; do
+ case "$i" in
+ (--force|--nodeps) opts=( "${opts[@]}" "$i" ); continue;;
+ esac
+
+ rpmlist.install "$VSERVER_NAME" "$BASEDIR" "$manifest" "$i" "${rpm_dflt_opts[@]}" "${opts[@]}"
+ opts=()
+done
+
+test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+
+base.setSuccess