Add support for vserver-build -m template, which extracts tarballs.
authorDaniel Hokka Zakrisson <daniel@hozac.com>
Tue, 12 Sep 2006 16:33:59 +0000 (16:33 +0000)
committerDaniel Hokka Zakrisson <daniel@hozac.com>
Tue, 12 Sep 2006 16:33:59 +0000 (16:33 +0000)
git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@2304 94cd875c-1c1d-0410-91d2-eb244daf1a30

configure.ac
contrib/manifest.dat.pathsubst
scripts/Makefile-files
scripts/magic.mime [new file with mode: 0644]
scripts/util-vserver-vars.pathsubst
scripts/vserver-build
scripts/vserver-build.template [new file with mode: 0644]

index 0e85a57..5642959 100644 (file)
@@ -56,6 +56,11 @@ ENSC_PATHPROG(NOHUP,     nohup)
 ENSC_PATHPROG(RMMOD,     rmmod)
 ENSC_PATHPROG(VCONFIG,   vconfig,, [See http://www.candelatech.com/~greear/vlan.html; usually this tool is shipped in the 'vconfig' or 'vlan' package of your distribution])
 ENSC_PATHPROG(WGET,      wget)
+ENSC_PATHPROG(FILE,      file,    [file])
+ENSC_PATHPROG(GZIP,      gzip,    [gzip])
+ENSC_PATHPROG(BZIP2,     bzip2,   [bzip2])
+ENSC_PATHPROG(CPIO,      cpio,    [cpio])
+ENSC_PATHPROG(RESTORE,   restore, [restore])
 
 ENSC_PATHPROG(DOXYGEN,   doxygen,  [:])
 ENSC_PATHPROG(XSLTP,     xsltp,    [:])
index d700696..8ae2eff 100644 (file)
@@ -7,6 +7,7 @@ build  @PKGLIBDIR@/vserver-build.skeleton
 build  @PKGLIBDIR@/vserver-build.debootstrap
 build  @PKGLIBDIR@/vserver-build.yum
 build  @PKGLIBDIR@/vserver-build.rpm
+build  @PKGLIBDIR@/vserver-build.template
 build  @PKGLIBDIR@/vserver-build.functions
 build  @PKGLIBDIR@/vserver-build.functions.apt
 build  @PKGLIBDIR@/vserver-build.functions.rpm
index 27aac8e..7c2e989 100644 (file)
@@ -38,11 +38,13 @@ AM_INSTALLCHECK_STD_OPTIONS_EXEMPT += \
 
 
 scripts_pkglib_src_DTA =       scripts/functions \
+                               scripts/magic.mime \
                                scripts/vserver-build.apt-rpm \
                                scripts/vserver-build.skeleton \
                                scripts/vserver-build.debootstrap \
                                scripts/vserver-build.rpm \
                                scripts/vserver-build.yum \
+                               scripts/vserver-build.template \
                                scripts/vserver-build.functions \
                                scripts/vserver-build.functions.apt \
                                scripts/vserver-build.functions.rpm \
diff --git a/scripts/magic.mime b/scripts/magic.mime
new file mode 100644 (file)
index 0000000..0e10d84
--- /dev/null
@@ -0,0 +1,19 @@
+# Borrowed from file(1)
+# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
+0      string          \037\213                application/x-gzip
+# tar posix
+257    string          ustar\0                 application/x-tar
+# tar gnu
+257    string          ustar\040\040\0         application/x-tar
+# cpio
+0      short           070707                  application/x-cpio
+# cpio swapped
+0      short           0143561                 application/x-cpio
+# bzip2
+0      string          BZh                     application/x-bzip2
+# dump/restore new-fs big and little endian
+24     belong          60012                   application/x-dump
+24     lelong          60012                   application/x-dump
+# dump/restore old-fs big and little endian
+24     belong          60011                   application/x-dump
+24     lelong          60011                   application/x-dump
index 4ea7698..ee7662f 100644 (file)
@@ -43,6 +43,7 @@ _IFSPEC="$__LEGACYDIR/ifspec"
 _INITSYNC_MINIT_START=:
 _KEEP_CTX_ALIVE="$__PKGLIBDIR/keep-ctx-alive"
 _LIB_FUNCTIONS="$__PKGLIBDIR/functions"
+_LIB_MAGIC="$__PKGLIBDIR/magic"
 _LIB_VSERVER_SETUP_FUNCTIONS="$__PKGLIBDIR/vserver-setup.functions"
 _LIB_VSERVER_BUILD_FUNCTIONS="$__PKGLIBDIR/vserver-build.functions"
 _LIB_VSERVER_BUILD_FUNCTIONS_APT="$__PKGLIBDIR/vserver-build.functions.apt"
@@ -96,14 +97,18 @@ _VYUM="$__SBINDIR/vyum"
 _VYUM_WORKER="$__PKGLIBDIR/vyum-worker"
 
 _AWK="@AWK@"
+_BZIP2="@BZIP2@"
 _CAT="@CAT@"
 _CHOWN="@CHOWN@"
 _CMP="@CMP@"
 _CP="@CP@"
+_CPIO="@CPIO@"
 _DIRNAME="@DIRNAME@"
 _EGREP="@EGREP@"
 _ENV="@ENV@"
+_FILE="@FILE@"
 _GREP="@GREP@"
+_GZIP="@GZIP@"
 _IP="@IP@"
 _IPTABLES="@IPTABLES@"
 _LN="@LN@"
@@ -118,6 +123,7 @@ _MV="@MV@"
 _NAMEIF="@NAMEIF@"
 _NICE="@NICE@"
 _NOHUP="@NOHUP@"
+_RESTORE="@RESTORE@"
 _RM="@RM@"
 _RMDIR="@RMDIR@"
 _RMMOD="@RMMOD@"
index 41fe0b7..e184deb 100755 (executable)
@@ -66,6 +66,8 @@ Possible methods are:
                     configuration file and calls an optional command then
     debootstrap ... -- -d <distribution> [-m <mirror>] [-s <script> ] [-- <debootstrap-options>*]
                      bootstraps the vserver with Debian's 'debootstrap' package
+    template ... -- (-t <tarball>)+
+                ...  installs a guest using tarball(s)
 
 Please report bugs to $PACKAGE_BUGREPORT"
     exit 0
@@ -126,7 +128,7 @@ setup_setDefaults "$VSERVER_NAME"
 
 case x"$method" in
     (xlegacy)  exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
-    (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm)
+    (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xtemplate)
                . $__PKGLIBDIR/vserver-build.$method
                ;;
     (x)                panic $"No build-method specified";;
diff --git a/scripts/vserver-build.template b/scripts/vserver-build.template
new file mode 100644 (file)
index 0000000..7274dcd
--- /dev/null
@@ -0,0 +1,92 @@
+# $Id:$        --*- sh -*--
+
+# Copyright (C) 2006 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:t:' --long debug,pkgmgmt,template: -n "vserver-build.template" -- "$@") || exit 1
+eval set -- "$tmp"
+
+. "$_LIB_VSERVER_BUILD_FUNCTIONS_PKGMGMT"
+
+DISTRIBUTION=:
+use_pkgmgmt=
+declare -a TEMPLATE=()
+while true; do
+    case "$1" in
+       -d)             DISTRIBUTION=$2; shift;;
+       --debug)        set -x;;
+       --pkgmgmt)      use_pkgmgmt=1;;
+       -t|--template)
+                       case "$2" in
+                            /*)        f="$2";;
+                            *)         f=`pwd`/"$2";;
+                       esac
+                       TEMPLATE=( "${TEMPLATE[@]}" "$f" )
+                       shift
+                       ;;
+       --)             shift; break ;;
+       *)              echo "vserver-build.template: internal error: unrecognized option '$1'" >&2
+                       exit 1
+                       ;;
+    esac
+    shift
+done
+
+getDistribution '' 1
+
+base.init
+test -z "$use_pkgmgmt" || pkgmgmt.initVariables
+
+base.initFilesystem "$OPTION_FORCE"
+test -z "$use_pkgmgmt" || pkgmgmt.initFilesystem "$OPTION_FORCE"
+
+
+setup_writeOption "$VSERVER_NAME"
+setup_writeInitialFstab
+
+test -z "$BUILD_INITPRE"  || "$BUILD_INITPRE" "$SETUP_CONFDIR"  "$UTIL_VSERVER_VARS"
+
+pushd "$SETUP_CONFDIR/vdir" &> /dev/null
+for t in "${TEMPLATE[@]}"; do
+    mime=$($_FILE -Nbiz -m "$_LIB_MAGIC" "$t")
+    compression=$(echo "$mime" | $_GREP '(' | $_SED 's!.*(\(.*\))$!\1!')
+
+    case "$compression" in
+       application/x-bzip2)    DECOMPRESS="$_BZIP2 -d -c";;
+       application/x-gzip)     DECOMPRESS="$_GZIP -d -c";;
+       "")                     DECOMPRESS=$_CAT;;
+       *)
+           echo "Unsupported compression method: $compression"
+           exit 1
+           ;;
+    esac
+
+    case "$mime" in
+       application/x-tar*)     EXTRACT="$_TAR -x";;
+       application/x-cpio*)    EXTRACT="$_CPIO -i";;
+       application/x-dump*)    EXTRACT="$_RESTORE -rf -";;
+       *)
+           echo "Unsupported packaging method: $mime"
+           exit 1
+           ;;
+    esac
+
+    $DECOMPRESS "$t" | $EXTRACT
+done
+popd &> /dev/null
+
+test -z "$BUILD_INITPOST" || "$BUILD_INITPOST" "$SETUP_CONFDIR" "$UTIL_VSERVER_VARS"
+
+base.setSuccess