Add the fai build method based on Sam Vilain's patch.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Sun, 1 Oct 2006 17:27:50 +0000 (17:27 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Sun, 1 Oct 2006 17:27:50 +0000 (17:27 +0000)
(https://savannah.nongnu.org/patch/?5058)

git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2341 94cd875c-1c1d-0410-91d2-eb244daf1a30

scripts/Makefile-files
scripts/vserver-build
scripts/vserver-build.fai [new file with mode: 0644]

index 7c2e989..d369285 100644 (file)
@@ -42,6 +42,7 @@ scripts_pkglib_src_DTA =      scripts/functions \
                                scripts/vserver-build.apt-rpm \
                                scripts/vserver-build.skeleton \
                                scripts/vserver-build.debootstrap \
+                               scripts/vserver-build.fai \
                                scripts/vserver-build.rpm \
                                scripts/vserver-build.yum \
                                scripts/vserver-build.template \
index 866b7e5..f2180fd 100755 (executable)
@@ -66,6 +66,12 @@ Possible methods are:
                 ...  bootstraps the vserver with Debian's 'debootstrap' package
     template    ... -- (-t <tarball>)+ [-d <distribution>]
                 ...  installs a guest using tarball(s)
+    fai         ... -- [ -f <fai_vserver> ] [-n <nfsroot>] [-d <fai_dir> ] [ -a ]
+                     bootstraps the vserver with Debian Fully Automatic Installation
+                     -f means use the nfsroot and profile in the vserver <fai_vserver>
+                     -n <nfsroot> specifies the 'NFS' root explicitly
+                     -d <fai_dir> specifies the location of the FAI profile
+                     the -f option implies -n and -d are relative to the <fai_vserver>
 
 Please report bugs to $PACKAGE_BUGREPORT"
     exit 0
@@ -126,7 +132,7 @@ setup_setDefaults "$VSERVER_NAME"
 
 case x"$method" in
     (xlegacy)  exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
-    (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xtemplate)
+    (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xtemplate|xfai)
                . $__PKGLIBDIR/vserver-build.$method
                ;;
     (x)                panic $"No build-method specified";;
diff --git a/scripts/vserver-build.fai b/scripts/vserver-build.fai
new file mode 100644 (file)
index 0000000..9c6506d
--- /dev/null
@@ -0,0 +1,156 @@
+#
+# Copyright (C) 2006 Sam Vilain <sam.vilain@catalyst.net.nz>
+#  
+# 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:f:n:a' --long debug,pkgmgmt -n "$0" -- "$@") || exit 1
+eval set -- "$tmp"
+
+. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
+. "$__PKGLIBDIR/vserver.functions"
+
+DISTRIBUTION=:
+
+FAI_VSERVER=
+FAI_NFSROOT=/usr/lib/fai/nfsroot
+FAI_DIR=/usr/local/share/fai
+
+use_pkgmgmt=
+while true; do
+    case "$1" in
+       -f)             FAI_VSERVER=$2; shift; ;;
+       -n)             FAI_NFSROOT=$2; shift; ;;
+       -d)             FAI_DIR=$2; shift; ;;
+       -a)             AUTO=1; ;;
+       --debug)        DEBUG=1; SH_DEBUG=-x; set -x;;
+       --)             shift; break ;;
+       *)              echo "vserver-build.fai: internal error: unrecognized option '$1'" >&2
+                       exit 1
+                       ;;
+    esac
+    shift
+done
+
+getDistribution '' 1
+
+base.init
+base.initFilesystem "$OPTION_FORCE"
+
+setup_writeOption "$VSERVER_NAME"
+setup_writeInitialFstab
+
+test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE" "$SETUP_CONFDIR"  "$UTIL_VSERVER_VARS"
+
+# if they specified a vserver where FAI is installed, then prefix its
+# root to the FAI_NFSROOT etc (unless they have already specified a
+# $ROOTDIR-relative path)
+REAL_ROOTDIR=`getPhysicalDir "$ROOTDIR"`
+REAL_VDIR=`getPhysicalDir "$VDIR"`
+echo "ROOTDIR is $REAL_ROOTDIR"
+echo "VDIR    is $REAL_VDIR"
+if [ -n "$FAI_VSERVER" ]
+then
+    echo "FAI_VSERVER is $FAI_VSERVER"
+    if [ `expr "$FAI_NFSROOT" : "$REAL_ROOTDIR"` -eq 0 ]
+    then
+        FAI_NFSROOT="$REAL_ROOTDIR/$FAI_VSERVER$FAI_NFSROOT"
+    fi
+    if [ `expr "$FAI_DIR" : "$REAL_ROOTDIR"` -eq 0 ]
+    then
+        FAI_DIR="$REAL_ROOTDIR/$FAI_VSERVER$FAI_DIR"
+    fi
+fi
+echo "FAI_NFSROOT is $FAI_NFSROOT"
+echo "FAI_DIR     is $FAI_DIR"
+FAI_ROOT=/tmp/target
+
+if [ ! -e "$FAI_NFSROOT/usr/sbin/fai" ]
+then
+    colpanic "NFSROOT not found - did you run fai-setup?"
+    exit 1
+fi
+
+if ! grep -qw VIRTUAL "$FAI_NFSROOT/usr/sbin/fai"
+then
+    echo "*** Looks like you don't have the patched FAI."
+    echo "*** get it from svn://svn.debian.org/svn/fai/people/mugwump/vserver"
+    exit 1
+fi
+
+# setup a new filesystem namespace
+set -e
+#[ -d $FAI_NFSROOT/var/log/fai ] || mkdir $FAI_NFSROOT/var/log/fai
+
+# suppresses color logo, as it does not leave the terminal in a nice
+# state.
+console=dummy
+
+# set up interfaces, so that the vserver can be built with restricted
+# network access.
+generateOptions "$SETUP_CONFDIR"
+enableInterfaces "$SETUP_CONFDIR"
+
+# last chance to abort!
+if [ -z "$AUTO" ]
+then
+    echo -n "Press ENTER to begin, or Ctrl+C to cancel: "
+    read junk
+fi
+
+killprocs() {
+       base.__cleanup
+       if [ -e "/proc/virtual/$SETUP_CONTEXT" ]
+       then
+               $_VKILL -c "$SETUP_CONTEXT" -s 15
+               sleep 2
+               $_VKILL -c "$SETUP_CONTEXT" -s 9
+       fi
+       set -x
+       disableInterfaces "$SETUP_CONFDIR"
+}
+
+trap killprocs INT EXIT
+
+rwpaths="/var/lock /var/log /dev /var/run /etc/sysconfig"
+[ -d "$FAI_NFSROOT/etc/network/run" ] && rwpaths="$rwpaths /etc/network/run"
+
+export VDIR ROOTDIR FAI_VSERVER FAI_DIR FAI_NFSROOT FAI_ROOT console
+
+[ -z "$AUTO" ] && FINAL_SHELL="exec /bin/sh -i"
+
+mount -n -o ro --bind "$FAI_NFSROOT" /mnt
+mount -n -t tmpfs -o size=64m,mode=1777 vm /mnt/tmp
+mkdir -p /mnt/tmp/target
+mount -n --bind "$VDIR" /mnt/tmp/target
+mkdir -p /mnt/tmp/target/proc
+mount -n -t proc proc /mnt/tmp/target/proc
+for x in $rwpaths
+do
+    /mnt/usr/lib/fai/mkrw -n "/mnt$x"
+done
+mount -n -o ro --bind "$FAI_DIR" /mnt/fai
+mount -n -t proc proc /mnt/proc
+
+cd /mnt
+$_CHBIND "${CHBIND_OPTS[@]}" \
+    $_VCONTEXT --create "${OPTS_VCONTEXT_CREATE[@]}" -- \
+    $_VUNAME --xid self --set -t nodename="$SETUP_HOSTNAME" -- \
+    $_VATTRIBUTE --set --xid self "${OPTS_VATTRIBUTE[@]}" --ccap secure_mount \
+    $_VCONTEXT --migrate-self --endsetup --chroot $SILENT_OPT \
+       "${OPTS_VCONTEXT_MIGRATE[@]}" "${OPTS_VCONTEXT_ENTER[@]}" -- \
+    /bin/sh -c "/bin/sh $SH_DEBUG /etc/init.d/rcS -N vschild_build; $FINAL_SHELL"
+
+test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+
+base.setSuccess