merge with 0.30.213
[util-vserver.git] / scripts / vserver-build
1 #! /bin/bash
2 # $Id: vserver-build 2468 2007-01-21 20:05:19Z dhozac $
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     --keep      ...  do not delete generated files and directories when
41                      build of vserver failed.
42     -m <method> ...  use method <method>; see below for possible values
43     --rootdir <dir>
44                 ...  [default: $__DEFAULT_VSERVERDIR]
45     --pkgbase <dir>
46                 ...  [default: $__DEFAULT_VSERVERPKGDIR]
47       
48 cfg-options are: $SETUP_HELPMSG
49
50 Possible methods are:
51     legacy      ...  the \"old\" copy-all-from-host method, which requires the
52                      old legacy  vserver-legacy script;  with  this method the
53                      cfg-options will be ignored
54     apt-rpm     ... -- -d <distribution>
55                 ...  installs the base-packages of the given distribution with
56                      help of 'vapt-get'
57     yum         ... -- -d <distribution>
58                 ...  installs the base-packages of the given distribution with
59                      help of 'vyum'
60     rpm         ... -- [-d <distribution>] --empty|([--force] [--nodeps] <manifest>)+
61                 ...  installs lists of rpm-packages
62     skeleton    ... -- [<cmd> <args>*]
63                 ...  installs a minimal skeleton filesystem, creates the
64                      configuration file and calls an optional command then
65     debootstrap ... -- -d <distribution> [-m <mirror>] [-s <script> ] [-- <debootstrap-options>*]
66                 ...  bootstraps the vserver with Debian's 'debootstrap' package
67     template    ... -- (-t <tarball>)+ [-d <distribution>]
68                 ...  installs a guest using tarball(s)
69     fai         ... -- [ -f <fai_vserver> ] [-n <nfsroot>] [-d <fai_dir> ] [ -a ]
70                      bootstraps the vserver with Debian Fully Automatic Installation
71                      -f means use the nfsroot and profile in the vserver <fai_vserver>
72                      -n <nfsroot> specifies the 'NFS' root explicitly
73                      -d <fai_dir> specifies the location of the FAI profile
74                      the -f option implies -n and -d are relative to the <fai_vserver>
75     rsync       ... -- [-d <distribution>] --source <source> [-o <rsync option>]*
76                 ...  installs a guest by rsyncing from <source> to the guest root
77     clone       ... -- [-d <distribution>] --source <source>
78                 ...  clones a guest by linking unified files and copying the rest
79
80 Please report bugs to $PACKAGE_BUGREPORT"
81     exit 0
82 }
83
84 function showVersion()
85 {
86     echo \
87 $"vserver-build $PACKAGE_VERSION -- initializes a vserver
88 This program is part of $PACKAGE_STRING
89
90 Copyright (C) 2003,2004,2005 Enrico Scholz
91 This program is free software; you may redistribute it under the terms of
92 the GNU General Public License.  This program has absolutely no warranty."
93     exit 0
94 }
95
96 ### main starts here
97
98 set -e
99
100 declare -a default_opts=()
101 test -n "$NO_DEFAULT_OPTS" || getFileArray default_opts "$__CONFDIR/.defaults/apps/build/options" || :
102
103 tmp=$(getopt -o +m:n: --long keep,force,debug,help,version,rootdir:,pkgbase:,$SETUP_OPTIONS -n "$(basename $0)" -- \
104         "${default_opts[@]}" "$@") || exit 1
105 eval set -- "$tmp"
106
107 VSERVER_NAME=
108 OPTION_FORCE=
109 OPTION_DEBUG=0
110 OPTION_KEEP=
111
112 while true; do
113     case "$1" in
114         (--help)    showHelp $0 ;;
115         (--version) showVersion ;;
116         (--force)   OPTION_FORCE=1;;
117         (--keep)    OPTION_KEEP=1;;
118         (--debug)   let ++OPTION_DEBUG;  set -x;;
119         (--rootdir) ROOTDIR=$2;      shift;;
120         (--pkgbase) PKGCFGBASE=$2;   shift;;
121         (-m)        method=$2;       shift;;
122         (-n)        VSERVER_NAME=$2; shift;;
123         (--)        shift; break;;
124         (*)
125             { setup_setOption2 "$1" "$2" && shift; } || \
126               panic $"vserver-build: internal error."
127             ;;
128     esac
129     shift
130 done
131
132 test -n "$VSERVER_NAME" ||
133     panic $"Name of vserver not specified"
134
135 setup_setDefaults "$VSERVER_NAME"
136
137 case x"$method" in
138     (xlegacy)   exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
139     (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm|xtemplate|xfai|xrsync|xclone)
140                 . $__PKGLIBDIR/vserver-build.$method
141                 ;;
142     (x)         panic $"No build-method specified";;
143     (*)         panic $"Unknown build-method '$method'";;
144 esac