1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
# $Id: vserver-setup.functions,v 1.16 2005/01/31 17:43:31 ensc Exp $ --*- sh -*--
# Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
SETUP_HOSTNAME=
SETUP_NETDEV=
SETUP_NETMASK=
SETUP_NETPREFIX=
SETUP_NETBCAST=
SETUP_LOCKFILE=
SETUP_CONFDIR=
SETUP_CONTEXT=
SETUP_INITSTYLE=
declare -a SETUP_INTERFACES=()
declare -a SETUP_FLAGS=()
declare -r SETUP_OPTIONS="confdir:,lockfile:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:,context:,initstyle:"
declare -r SETUP_HELPMSG=$"
--context ... the static context of the vserver [default: none; a dynamic
context will be assumed]
--confdir ... [default: $CONFDIR/<name>]
--lockfile <filename>
... [default: $RUNDIR/<name>]
--hostname <hostname>
--netdev <device>
--netbcast <broadcast>
--netmask <netmask>|--netprefix <prefixlen>
... sets the default netmask (a.b.c.d quadruple) or prefixlen
(length of the interface)
--interface [<name-suffix>=][<device>:]<ip>[/<mask|prefixlen>]
... declares an network-interface; this option can be specified
multiple times
--flags <flags>+
... sets comma-separated list of flags; possible flags are
lock: Prevent the vserver from setting new security context
sched: Merge scheduler priority of all processes in the
vserver so that it acts a like a single
one (kernel 2.4 only).
nproc: Limit the number of processes in the vserver
according to ulimit (instead of a per user limit,
this becomes a per vserver limit)
private: No other process can join this security context.
Even root
--initstyle <style>
... configures the initstyle (e.g. minit,sysv,plain)
"
function setup_setOption2
{
case "$1" in
(--context) SETUP_CONTEXT=$2;;
(--confdir) SETUP_CONFDIR=$2;;
(--lockfile) SETUP_LOCKFILE=$2;;
(--hostname) SETUP_HOSTNAME=$2;;
(--netdev) SETUP_NETDEV=$2;;
(--netmask) SETUP_NETMASK=$2;;
(--netprefix) SETUP_NETPREFIX=$2;;
(--netbcast) SETUP_NETBCAST=$2;;
(--interface) SETUP_INTERFACES=( "${SETUP_INTERFACES[@]}" "$2" );;
(--initstyle) SETUP_INITSTYLE=$2;;
(--flags) old_IFS=$IFS
IFS=,
set -- $2
SETUP_FLAGS=( "${SETUP_FLAGS[@]}" "$@" )
IFS=$old_IFS
;;
(*) return 1;;
esac
return 0
}
function _setup_writeSingleOption
{
test -z "$1" || echo "$1" >"$2"
}
function _setup_writeInterface
{
local vdir=$1
local idx=$2
local tmp=$3
local name=${tmp%%=*}
test "$name" != "$tmp" || name=
tmp=${tmp##${name}=}
local dev=${tmp%%:*}
test "$dev" != "$tmp" || dev=
tmp=${tmp##${dev}:}
local mask=${tmp##*/}
test "$mask" != "$tmp" || mask=
local ip=${tmp%%/${mask}}
local prefix=
test "${mask%%.*}" != "$mask" || {
prefix=$mask
mask=
}
d=$vdir/interfaces/$idx
mkdir "$d"
_setup_writeSingleOption "$name" $d/name
_setup_writeSingleOption "$dev" $d/dev
_setup_writeSingleOption "$ip" $d/ip
_setup_writeSingleOption "$mask" $d/mask
_setup_writeSingleOption "$prefix" $d/prefix
test -n "$dev" -o -n "$SETUP_NETDEV" || \
echo $"No device specified for interface '$idx'; do not forget to set the 'nodev' option" >&2
}
function setup_setDefaults
{
: ${SETUP_CONFDIR:=$CONFDIR/$1}
: ${SETUP_LOCKFILE:=$RUNDIR/$1}
findFile SETUP_FSTAB "$CONFDIR"/.defaults/fstab "$PKGLIBDEFAULTDIR"/fstab
}
function setup_writeOption
{
local name=$1
local cfgdir=$SETUP_CONFDIR
local i
mkdir -p "$cfgdir"/interfaces "$cfgdir"/apps/init "$cfgdir"/uts
_setup_writeSingleOption "$name" "$cfgdir"/name
_setup_writeSingleOption "$SETUP_CONTEXT" "$cfgdir"/context
_setup_writeSingleOption "$SETUP_HOSTNAME" "$cfgdir"/uts/nodename
_setup_writeSingleOption "$SETUP_NETDEV" "$cfgdir"/interfaces/dev
_setup_writeSingleOption "$SETUP_NETMASK" "$cfgdir"/interfaces/mask
_setup_writeSingleOption "$SETUP_NETPREFIX" "$cfgdir"/interfaces/prefix
_setup_writeSingleOption "$SETUP_NETBCAST" "$cfgdir"/interfaces/bcast
_setup_writeSingleOption "$SETUP_INITSTYLE" "$cfgdir"/apps/init/style
local idx=0
for i in "${SETUP_INTERFACES[@]}"; do
_setup_writeInterface "$cfgdir" $idx "$i"
let ++idx
done
test -z "$SETUP_FLAGS" || for i in "${SETUP_FLAGS[@]}"; do
echo "$i"
done >"$cfgdir"/flags
ln -s "$SETUP_LOCKFILE" "$cfgdir"/run
}
function setup_writeInitialFstab
{
cat "$SETUP_FSTAB" >"$SETUP_CONFDIR"/fstab
}
function setup_test
{
SETUP_INTERFACES=()
setup_setOption2 --interface foo0=eth0:1.2.3.4/1
setup_setOption2 --interface foo1=eth0:1.2.3.4/255.255.248.0
setup_setOption2 --interface foo2=eth0:1.2.3.4
setup_setOption2 --interface foo3=1.2.3.4
setup_setOption2 --interface foo4=1.2.3.4/1
setup_setOption2 --interface eth0:1.2.3.4
setup_setOption2 --interface eth0:1.2.3.4/1
setup_setOption2 --interface 1.2.3.4
setup_setOption2 --interface 1.2.3.4/1
setup_writeOption xx
}
|