3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 declare -a SETUP_INTERFACES=()
29 declare -a SETUP_FLAGS=()
31 declare -r SETUP_OPTIONS="confdir:,lockfile:,lockrevdir:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:,context:"
32 declare -r SETUP_HELPMSG=$"
33 --context ... the static context of the vserver [default: none; a dynamic
34 context will be assumed]
35 --confdir ... [default: $CONFDIR/<name>]
37 ... [default: $RUNDIR/<name>]
38 --lockrevdir <dirname>
39 ... [default: $CONFDIR/.defaults/run.rev]
42 --netbcast <broadcast>
43 --netmask <netmask>|--netprefix <prefix>
44 ... sets the default netmask (a.b.c.d quadruple) or prefix
45 (length of the interface)
46 --interface [<name-suffix>=][<device>:]<ip>[/<mask|prefix>]
47 ... declares an network-interface; this option can be specified
50 ... sets comma-separated list of flags; possible flags are
51 lock: Prevent the vserver from setting new security context
52 sched: Merge scheduler priority of all processes in the
53 vserver so that it acts a like a single one.
54 nproc: Limit the number of processes in the vserver
55 according to ulimit (instead of a per user limit,
56 this becomes a per vserver limit)
57 private: No other process can join this security context.
61 function setup_setOption2
64 (--context) SETUP_CONTEXT=$2;;
65 (--confdir) SETUP_CONFDIR=$2;;
66 (--lockfile) SETUP_LOCKFILE=$2;;
67 (--lockrevdir) SEUTP_LOCKREVDIR=$2;;
68 (--hostname) SETUP_HOSTNAME=$2;;
69 (--netdev) SETUP_NETDEV=$2;;
70 (--netmask) SETUP_NETMASK=$2;;
71 (--netprefix) SETUP_NETPREFIX=$2;;
72 (--netbcast) SETUP_NETBCAST=$2;;
73 (--interface) SETUP_INTERFACES=( "${SETUP_INTERFACES[@]}" "$2" );;
74 (--flags) old_IFS=$IFS
77 SETUP_FLAGS=( "${SETUP_FLAGS[@]}" "$@" )
86 function _setup_writeSingleOption
88 test -z "$1" || echo "$1" >"$2"
91 function _setup_writeInterface
98 test "$name" != "$tmp" || name=
102 test "$dev" != "$tmp" || dev=
105 local mask=${tmp##*/}
106 test "$mask" != "$tmp" || mask=
108 local ip=${tmp%%/${mask}}
111 test "${mask%%.*}" != "$mask" || {
116 d=$vdir/interfaces/$idx
119 _setup_writeSingleOption "$name" $d/name
120 _setup_writeSingleOption "$dev" $d/dev
121 _setup_writeSingleOption "$ip" $d/ip
122 _setup_writeSingleOption "$mask" $d/mask
123 _setup_writeSingleOption "$prefix" $d/prefix
126 function setup_setDefaults
128 : ${SETUP_CONFDIR:=$CONFDIR/$1}
129 : ${SETUP_LOCKFILE:=$RUNDIR/$1}
130 : ${SETUP_LOCKREVDIR:=$CONFDIR/.defaults/run.rev}
131 findFile SETUP_FSTAB "$CONFDIR"/.defaults/fstab "$PKGLIBDEFAULTDIR"/fstab
134 function setup_writeOption
137 local cfgdir=$SETUP_CONFDIR
140 mkdir -p "$cfgdir/interfaces"
142 _setup_writeSingleOption "$name" "$cfgdir"/name
143 _setup_writeSingleOption "$SETUP_CONTEXT" "$cfgdir"/context
144 _setup_writeSingleOption "$SETUP_HOSTNAME" "$cfgdir"/hostname
145 _setup_writeSingleOption "$SETUP_NETDEV" "$cfgdir"/interfaces/dev
146 _setup_writeSingleOption "$SETUP_NETMASK" "$cfgdir"/interfaces/mask
147 _setup_writeSingleOption "$SETUP_NETPREFIX" "$cfgdir"/interfaces/prefix
148 _setup_writeSingleOption "$SETUP_NETBCAST" "$cfgdir"/interfaces/bcast
151 for i in "${SETUP_INTERFACES[@]}"; do
152 _setup_writeInterface "$cfgdir" $idx "$i"
156 test -z "$SETUP_FLAGS" || for i in "${SETUP_FLAGS[@]}"; do
158 done >"$cfgdir"/flags
160 ln -s "$SETUP_LOCKFILE" "$cfgdir/run"
161 ln -s "$SETUP_LOCKREVDIR" "$cfgdir/run.rev"
164 function setup_writeInitialFstab
166 cat "$SETUP_FSTAB" >"$SETUP_CONFDIR"/fstab
173 setup_setOption2 --interface foo0=eth0:1.2.3.4/1
174 setup_setOption2 --interface foo1=eth0:1.2.3.4/255.255.248.0
175 setup_setOption2 --interface foo2=eth0:1.2.3.4
176 setup_setOption2 --interface foo3=1.2.3.4
177 setup_setOption2 --interface foo4=1.2.3.4/1
178 setup_setOption2 --interface eth0:1.2.3.4
179 setup_setOption2 --interface eth0:1.2.3.4/1
180 setup_setOption2 --interface 1.2.3.4
181 setup_setOption2 --interface 1.2.3.4/1