fixed getopt long-option string
[util-vserver.git] / util-vserver / scripts / vserver-build
1 #! /bin/bash
2 # $Id$
3
4 # Copyright (C) 2003 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:=$(dirname $0)/util-vserver-vars}
20 test -e "$UTIL_VSERVER_VARS" || {
21     echo "Can not find util-vserver installation; aborting..."
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> --pkgcfgbase <dir> [--] <method-args>*
36
37 Options:
38     --force     ...  remove/rename already existing vservers with the same name
39     -m <method> ...  use method <method>; see below for possible values
40     --rootdir <dir>
41                 ...  [default: /vservers]
42     --pkgcfgbase <dir>
43                 ...  [default: <rootdir>/.pkg]
44       
45 cfg-options are: $SETUP_HELPMSG
46
47 Possible methods are:
48     legacy      ...  the \"old\" copy-all-from-host method, which requires the
49                      old legacy  vserver-legacy script;  with  this method the
50                      cfg-options will be ignored
51     copy        ...  the copy-all-from-host method which uses the recent
52                      configuration scheme
53     apt-rpm -d <distribution>
54                 ...  installs the base-packages of the given distribution with
55                      help of 'vapt-get'
56
57 Please report bugs to $PACKAGE_BUGREPORT"
58     exit 0
59 }
60
61 function showVersion()
62 {
63     echo \
64 $"vserver-build $PACKAGE_VERSION -- initializes a vserver
65 This program is part of $PACKAGE_STRING
66
67 Copyright (C) 2003 Enrico Scholz
68 This program is free software; you may redistribute it under the terms of
69 the GNU General Public License.  This program has absolutely no warranty."
70     exit 0
71 }
72
73 ### main starts here
74
75 set -e
76
77 declare -a default_opts=()
78 test "$NO_DEFAULT_OPTS" || getFileArray default_opts "$CONFDIR/.defaults/apps/build/options"
79
80 tmp=$(getopt -o +m:n: --long force,debug,help,version,rootdir:,pkgbase:,$SETUP_OPTIONS -n "$(basename $0)" -- \
81         "${default_opts[@]}" "$@") || exit 1
82 eval set -- "$tmp"
83
84 VSERVER_NAME=
85 OPTION_FORCE=
86
87 while true; do
88     case "$1" in
89         --help)    showHelp $0 ;;
90         --version) showVersion ;;
91         --force)   OPTION_FORCE=1;;
92         --debug)   set -x;;
93         --rootdir) ROOTDIR=$2;      shift;;
94         --pkgbase) PKGCFGBASE=$2;   shift;;
95         -m)        method=$2;       shift;;
96         -n)        VSERVER_NAME=$2; shift;;
97         --)        shift; break;;
98         *)
99             { setup_setOption2 "$1" "$2" && shift; } || \
100             { echo $"vserver-build: internal error."; exit 1; }
101             ;;
102     esac
103     shift
104 done
105
106 test "$VSERVER_NAME" || {
107     echo $"Name of vserver not specified"
108     exit 1
109 }
110
111 setup_setDefaults "$VSERVER_NAME"
112
113 case x"$method" in
114     xlegacy)    exec $_VSERVER_LEGACY "$VSERVER_NAME" build "$@" ;;
115     xapt-rpm|xcopy)
116                 . $PKGLIBDIR/vserver-build.$method
117                 ;;
118     x)          echo $"No build-method specified" >&2
119                 exit 1
120                 ;;
121     *)          echo $"Unknown build-method '$method'" >&2
122                 exit 1
123                 ;;
124 esac