ca522e4b329f7215b8c17f2727f0718674834800
[util-vserver.git] / scripts / vserver-build
1 #! /bin/bash
2 # $Id: vserver-build,v 1.20 2005/07/03 17:45:43 ensc Exp $
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     copy        ...  the copy-all-from-host method which uses the recent
55                      configuration scheme
56     apt-rpm ... -- -d <distribution>
57                 ...  installs the base-packages of the given distribution with
58                      help of 'vapt-get'
59     yum     ... -- -d <distribution>
60                 ...  installs the base-packages of the given distribution with
61                      help of 'vyum'
62     rpm     ... -- [-d <distribution>] --empty|([--force] [--nodeps] <manifest>)+
63                 ...  installs lists of rpm-packages
64     skeleton ... -- [<cmd> <args>*]
65                 ...  installs a minimal skeleton filesystem, creates the
66                      configuration file and calls an optional command then
67     debootstrap ... -- -d <distribution> [-m <mirror>] [-- <debootstrap-options>*]
68                      bootstraps the vserver with Debian's 'debootstrap' package
69
70 Please report bugs to $PACKAGE_BUGREPORT"
71     exit 0
72 }
73
74 function showVersion()
75 {
76     echo \
77 $"vserver-build $PACKAGE_VERSION -- initializes a vserver
78 This program is part of $PACKAGE_STRING
79
80 Copyright (C) 2003,2004,2005 Enrico Scholz
81 This program is free software; you may redistribute it under the terms of
82 the GNU General Public License.  This program has absolutely no warranty."
83     exit 0
84 }
85
86 ### main starts here
87
88 set -e
89
90 declare -a default_opts=()
91 test -n "$NO_DEFAULT_OPTS" || getFileArray default_opts "$__CONFDIR/.defaults/apps/build/options" || :
92
93 tmp=$(getopt -o +m:n: --long keep,force,debug,help,version,rootdir:,pkgbase:,$SETUP_OPTIONS -n "$(basename $0)" -- \
94         "${default_opts[@]}" "$@") || exit 1
95 eval set -- "$tmp"
96
97 VSERVER_NAME=
98 OPTION_FORCE=
99 OPTION_DEBUG=0
100 OPTION_KEEP=
101
102 while true; do
103     case "$1" in
104         (--help)    showHelp $0 ;;
105         (--version) showVersion ;;
106         (--force)   OPTION_FORCE=1;;
107         (--keep)    OPTION_KEEP=1;;
108         (--debug)   let ++OPTION_DEBUG;  set -x;;
109         (--rootdir) ROOTDIR=$2;      shift;;
110         (--pkgbase) PKGCFGBASE=$2;   shift;;
111         (-m)        method=$2;       shift;;
112         (-n)        VSERVER_NAME=$2; shift;;
113         (--)        shift; break;;
114         (*)
115             { setup_setOption2 "$1" "$2" && shift; } || \
116               panic $"vserver-build: internal error."
117             ;;
118     esac
119     shift
120 done
121
122 test -n "$VSERVER_NAME" ||
123     panic $"Name of vserver not specified"
124
125 setup_setDefaults "$VSERVER_NAME"
126
127 case x"$method" in
128     (xlegacy)   exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
129     (xapt-rpm|xcopy|xskeleton|xdebootstrap|xyum|xrpm)
130                 . $__PKGLIBDIR/vserver-build.$method
131                 ;;
132     (x)         panic $"No build-method specified";;
133     (*)         panic $"Unknown build-method '$method'";;
134 esac