From: Daniel Hermann <hermann@tkm.physik.uni-karlsruhe.de>

--- newvserver.orig	2005-04-17 17:46:11.000000000 +0200
+++ newvserver	2005-04-17 18:54:08.000000000 +0200
@@ -62,9 +62,6 @@
 # Default network interface for vservers:
 INTERFACE="eth0"
 
-# Copy vreboot/vhalt/vshutdown utility into /usr/local/sbin/
-COPY_VREBOOT="true"
-
 if [ -r /etc/vservers/util-vserver-vars ] ; then
     . /etc/vservers/util-vserver-vars
 fi
@@ -96,15 +93,13 @@
 {
 	cat << EOF
 Usage:	${0##*/} [OPTIONS] --hostname x --domain y.z --ip 1.2.3.4
-Creates a new Debian vserver by downloading packages via HTTP/FTP
+Creates a new Debian vserver by calling "vserver ... build"
 
 Options:
         -h, --help		this help
         -V, --version		copyright and version information
 	--arch			set target architecture (eg. --arch "i386")
 				(autodetected on Debian host if dpkg available)
-	--copy-vreboot		install "vreboot/vshutdown/vhalt"
-	--no-copy-vreboot	don't install "vreboot/vshutdown/vhalt"
 	--dist			defaults to "sarge", passed to debootstrap.
 	--fakeinit		use "/sbin/init" to boot vserver
 	--conffile		extra configuration file to load.
@@ -184,14 +179,6 @@
                        fi
                        shift 2
                        ;;
-		    --copy-vreboot)
-			COPY_VREBOOT="true"
-			shift
-			;;
-		    --no-copy-vreboot)
-			COPY_VREBOOT=""
-			shift
-			;;
 		    --dist)
 			case "$2" in
 			    [a-z]*)
@@ -341,16 +328,6 @@
 ##############################################################################
 
 
-# Check we've got debootstrap available
-if [ ! -x /usr/sbin/debootstrap ]; then
-  cat << EOF 1>&2
-${0##*/}: Requires the debootstrap package to bootstrap Debian
-  Debian Host:	apt-get install debootstrap
-  RPM Host:	rpm -i http://people.debian.org/~blade/install/debootstrap/debootstrap-0.1.17.3-2.i386.rpm
-EOF
-  exit 1
-fi
-
 if ! cat /proc/self/status | grep '^s_context:[^0-9]0$'; then
     echo "${0##*/} error:"
     echo "	Must be run from the host server (security context 0)" 1>&2
@@ -364,33 +341,19 @@
   exit 1
 fi
 
-# check for /vserver/$VHOST/etc/ incase we are on pre-mounted LVM partition
-# (used to just check for "/vserver/$VHOST/" existing
-if [ -d "$VROOTDIR/$VHOST/etc/" -o -f "/etc/vservers/$VHOST.conf" ] ; then
-  cat << EOF 1>&2
-${0##*/} error: Virtual Server "$VHOST" appears to already exist
-  check "/etc/vservers/$VHOST.conf" or "/vservers/$VHOST/etc/";
-EOF
-  exit 1
-fi
-
-# This is used to keep a cache of the downloaded .deb packges for next install
-if [ -d "$VROOTDIR/ARCHIVES/$DIST" ]; then
-    mkdir -p "$VROOTDIR/$VHOST/var/cache/apt/archives"
-    cp -a "$VROOTDIR/ARCHIVES/$DIST/"*.deb "$VROOTDIR/$VHOST/var/cache/apt/archives" > /dev/null 2>&1
-fi
-
 # We only want to pass the Architecture if we need to (autodectected otherwise)
 if [ -n "$ARCH" ]; then
     ARCH_ARGUMENT="--arch $ARCH"
 fi
 
-# Fire off `debootstrap' to do all the hard work
-# like downloading and installing
-if ! /usr/sbin/debootstrap $ARCH_ARGUMENT \
-	"--include=$INSTALL_PACKAGES" "--exclude=$REMOVE_PACKAGES" \
-	"$DIST" "$VROOTDIR/$VHOST" "$MIRROR" ; then
-    echo "${0##*/}: error: debootstrap failure. Cannot continue."
+## use "vserver ... build" to build the new vserver
+if ! /usr/sbin/vserver "$VHOST" build -m debootstrap \
+       --rootdir "$VROOTDIR" --hostname "$VHOST" --interface "$INTERFACE:$IP" \
+       -- -d "$DIST" -m "$MIRROR" \
+       -- $ARCH_ARGUMENT \
+        --include="$INSTALL_PACKAGES" --exclude="$REMOVE_PACKAGES"
+  then
+    echo "${0##*/}: error: vserver-build failure. Cannot continue."
     exit 1
 fi
 
@@ -406,15 +369,8 @@
 
 EOF
 
-# Fix up the available device nodes, for security
+# Fix up the available device nodes (mostly done by vserver-build above)
 if cd "$VROOTDIR/$VHOST/dev"; then
-    mkdir -p /var/lib/vserver-debiantools
-    tar cfp /var/lib/vserver-debiantools/dev.tar.$$ full null ptmx random tty urandom zero
-    rm -rf *
-    tar xfp /var/lib/vserver-debiantools/dev.tar.$$
-    rm -f /var/lib/vserver-debiantools/dev.tar.$$
-    mkdir pts
-    mkdir shm
     ln -s /proc/self/fd fd
     ln -s fd/2 stderr
     ln -s fd/0 stdin
@@ -467,14 +423,6 @@
 proc		/proc		proc	defaults			0	0
 EOF
 
-# The new vserver patch now automatically mounts /proc
-# Debian needs /dev/pts mounting "gid=5,mode=620" by vserver
-cat << EOF > "$VROOTDIR/$VHOST/etc/mtab"
-/dev/hdv1 / vfs none 0 0
-proc /proc proc rw 0 0
-devpts /dev/pts devpts rw,gid=5,mode=620 0 0
-EOF
-
 # Create a reduced inittab that doesn't start getty on the consoles
 cat << EOF > "$VROOTDIR/$VHOST/etc/inittab"
 # /etc/inittab: init(8) configuration.
@@ -549,22 +497,6 @@
 
 EOF
 
-# Create default /etc/vservers entry
-cat << EOF > /etc/vservers/$VHOST.conf
-S_HOSTNAME="$VHOST"
-IPROOT="$IP"
-IPROOTDEV="$INTERFACE"
-ONBOOT="yes"
-S_NICE=""
-S_FLAGS="lock nproc$FAKEINIT"
-ULIMIT="-H -n 1024"
-S_CAPS="CAP_NET_RAW"
-
-# *NOT* DNS domain name, for NIS only
-S_DOMAINNAME=""
-
-EOF
-
 if [ -n "$EXTRA_PACKAGES" ]; then
     EXTRA_PACKAGES_INSTALL="apt-get --assume-yes install ${EXTRA_PACKAGES//,/ }"
 fi
@@ -601,6 +533,9 @@
 
 EOF
 
+## start vserver before we can exec anything inside it
+vserver $VHOST start
+
 # Run the above commands from within the server
 chmod 755 $VROOTDIR/$VHOST/vserver-config.sh
 vserver $VHOST exec /vserver-config.sh
@@ -622,30 +557,12 @@
     chmod 600 "$VROOTDIR/$VHOST/root/.ssh/authorized_keys"
 fi
 
-# Install the vreboot/rebootmgr utility--hopefully this will disappear soon
-VREBOOT_LOCATION="/usr/lib/util-vserver/vreboot"
-if [ "$COPY_VREBOOT" == "true" -a -x "$VREBOOT_LOCATION" ]; then
-    cp -a "$VREBOOT_LOCATION" "$VROOTDIR/$VHOST/usr/local/sbin/"
-    chmod 750 "$VROOTDIR/$VHOST/usr/local/sbin/vreboot"
-    # ln -s "$VROOTDIR/$VHOST/usr/local/sbin/"{vshutdown,vreboot}
-    # ln -s "$VROOTDIR/$VHOST/usr/local/sbin/"{vhalt,vreboot}
-fi
-
-# Stop all the processes that were started inside the server
-export PREVLEVEL=2
-vserver $VHOST exec /etc/init.d/rc 0
+## stop the vserver
 vserver $VHOST stop
 
-# Populate the archive for future virtual servers
-if [ ! -d $VROOTDIR/ARCHIVES/$DIST ]; then
-    mkdir -p $VROOTDIR/ARCHIVES/$DIST
-fi
-cp $VROOTDIR/$VHOST/var/cache/apt/archives/*.deb $VROOTDIR/ARCHIVES/$DIST
-
-echo "Restarting rebootmgr."
-invoke-rc.d rebootmgr restart
 echo
-echo "You should now adjust /etc/vservers/$VHOST.conf to suit your needs,"
+echo "You should now adjust the configuration in /etc/vservers/$VHOST/"
+echo "to suit your needs,"
 echo "or else just go ahead and type \`vserver $VHOST start' to start"
 echo "your new virtual server.  debian/rules!"
 echo
