vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

vserver-build (5674B)


      1 #! /bin/bash
      2 # $Id$
      3 
      4 # Copyright (C) 2003,2004,2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
      5 #  
      6 # This program is free software; you can redistribute it and/or modify
      7 # it under the terms of the GNU General Public License as published by
      8 # the Free Software Foundation; version 2 of the License.
      9 #  
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #  
     15 # You should have received a copy of the GNU General Public License
     16 # along with this program; if not, write to the Free Software
     17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     18 
     19 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
     20 test -e "$UTIL_VSERVER_VARS" || {
     21     echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
     22     exit 1
     23 }
     24 . "$UTIL_VSERVER_VARS"
     25 . "$_LIB_FUNCTIONS"
     26 . "$_LIB_VSERVER_SETUP_FUNCTIONS"
     27 . "$_LIB_VSERVER_BUILD_FUNCTIONS"
     28 
     29 ### Some local functions
     30 
     31 function showHelp()
     32 {
     33     echo \
     34 $"Usage: $(basename $0) -m <method> -n <name> --force <cfg-options>*
     35     --rootdir <dir> --pkgbase <dir> [--] <method-args>*
     36 
     37 Options:
     38     --force     ...  remove/rename already existing vservers with the same
     39                      name
     40     --i-know-its-there
     41                 ...  allow to finish build even if it exists
     42     --keep      ...  do not delete generated files and directories when
     43                      build of vserver failed.
     44     -m <method> ...  use method <method>; see below for possible values
     45     --rootdir <dir>
     46                 ...  [default: $__DEFAULT_VSERVERDIR]
     47     --pkgbase <dir>
     48                 ...  [default: $__DEFAULT_VSERVERPKGDIR]
     49       
     50 cfg-options are: $SETUP_HELPMSG
     51 
     52 Possible methods are:
     53     legacy      ...  the \"old\" copy-all-from-host method, which requires the
     54                      old legacy  vserver-legacy script;  with  this method the
     55 		     cfg-options will be ignored
     56     apt-rpm     ... -- -d <distribution>
     57                 ...  installs the base-packages of the given distribution with
     58 		     help of 'vapt-get'
     59     yum         ... -- -d <distribution> [-- <packages>*]
     60                 ...  installs the base-packages of the given distribution with
     61 		     help of 'vyum'
     62     urpmi       ... -- -d <distribution> -m <mirror>
     63     rpm         ... -- [-d <distribution>] --empty|([--force] [--nodeps] <manifest>)+
     64                 ...  installs lists of rpm-packages
     65     skeleton    ... -- [<cmd> <args>*]
     66                 ...  installs a minimal skeleton filesystem, creates the
     67 		     configuration file and calls an optional command then
     68     debootstrap ... -- -d <distribution> [-m <mirror>] [-s <script> ] [-- <debootstrap-options>*]
     69                 ...  bootstraps the vserver with Debian's 'debootstrap' package
     70     template    ... -- (-t <tarball>)+ [-d <distribution>]
     71                 ...  installs a guest using tarball(s)
     72     fai         ... -- [ -f <fai_vserver> ] [-n <nfsroot>] [-d <fai_dir> ] [ -a ]
     73                      bootstraps the vserver with Debian Fully Automatic Installation
     74                      -f means use the nfsroot and profile in the vserver <fai_vserver>
     75                      -n <nfsroot> specifies the 'NFS' root explicitly
     76                      -d <fai_dir> specifies the location of the FAI profile
     77                      the -f option implies -n and -d are relative to the <fai_vserver>
     78     rsync       ... -- [-d <distribution>] --source <source> [-- <rsync options>*]
     79                 ...  installs a guest by rsyncing from <source> to the guest root
     80     clone       ... -- [-d <distribution>] --source <source> [--exclude-from <exclude-list>]
     81                 ...  clones a guest by linking unified files and copying the rest
     82 
     83 Please report bugs to $PACKAGE_BUGREPORT"
     84     exit 0
     85 }
     86 
     87 function showVersion()
     88 {
     89     echo \
     90 $"vserver-build $PACKAGE_VERSION -- initializes a vserver
     91 This program is part of $PACKAGE_STRING
     92 
     93 Copyright (C) 2003,2004,2005 Enrico Scholz
     94 This program is free software; you may redistribute it under the terms of
     95 the GNU General Public License.  This program has absolutely no warranty."
     96     exit 0
     97 }
     98 
     99 ### main starts here
    100 
    101 set -e
    102 
    103 declare -a default_opts=()
    104 test -n "$NO_DEFAULT_OPTS" || getFileArray default_opts "$__CONFDIR/.defaults/apps/build/options" || :
    105 
    106 tmp=$(getopt -o +m:n: --long keep,force,i-know-its-there,debug,help,version,rootdir:,pkgbase:,$SETUP_OPTIONS -n "$(basename $0)" -- \
    107 	"${default_opts[@]}" "$@") || exit 1
    108 eval set -- "$tmp"
    109 
    110 VSERVER_NAME=
    111 OPTION_FORCE=
    112 OPTION_DEBUG=0
    113 OPTION_KEEP=
    114 OPTION_SEMIFORCE=
    115 
    116 while true; do
    117     case "$1" in
    118 	(--help)    showHelp $0 ;;
    119 	(--version) showVersion ;;
    120 	(--force)   OPTION_FORCE=1;;
    121 	(--keep)    OPTION_KEEP=1;;
    122 	(--debug)   let ++OPTION_DEBUG;  set -x;;
    123 	(--rootdir) ROOTDIR=$2;      shift;;
    124 	(--pkgbase) PKGCFGBASE=$2;   shift;;
    125 	(--i-know-its-there)
    126 		    OPTION_SEMIFORCE=1;;
    127 	(-m)	    method=$2;       shift;;
    128 	(-n)	    VSERVER_NAME=$2; shift;;
    129 	(--)	    shift; break;;
    130 	(*)
    131 	    { setup_setOption2 "$1" "$2" && shift; } || \
    132 	      panic $"vserver-build: internal error."
    133 	    ;;
    134     esac
    135     shift
    136 done
    137 
    138 test -n "$VSERVER_NAME" ||
    139     panic $"Name of vserver not specified"
    140 
    141 setup_setDefaults "$VSERVER_NAME"
    142 
    143 case x"$method" in
    144     (xlegacy)	exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
    145     (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xtemplate|xfai|xrsync|xclone|xurpmi)
    146 		. $__PKGDATADIR/vserver-build.$method
    147 		;;
    148     (x)		panic $"No build-method specified";;
    149     (*)		panic $"Unknown build-method '$method'";;
    150 esac