# $Id$ --*- sh -*-- # Copyright (C) 2003 Enrico Scholz # # 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_LOCKREVDIR= SETUP_CONFDIR= declare -a SETUP_INTERFACES=() declare -a SETUP_FLAGS=() declare -r SETUP_OPTIONS="confdir:,lockfile:,lockrevdir:,hostname:,netdev:,netmask:,netprefix:,netbcast:,interface:,flags:" declare -r SETUP_HELPMSG=$" --confdir ... [default: $CONFDIR/] --lockfile ... [default: $RUNDIR/] --lockrevdir ... [default: $PKGSTATEREVDIR/] --hostname --netdev --netbcast --netmask |--netprefix ... sets the default netmask (a.b.c.d quadruple) or prefix (length of the interface) --interface [=][:][/] ... declares an network-interface; this option can be specified multiple times --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. 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 " function setup_setOption2 { case "$1" in --confdir) SETUP_CONFDIR=$2;; --lockfile) SETUP_LOCKFILE=$2;; --lockrevdir) SEUTP_LOCKREVDIR=$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" );; --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 } function setup_setDefaults { : ${SETUP_CONFDIR:=$CONFDIR/$1} : ${SETUP_LOCKFILE:=$RUNDIR/$1} : ${SETUP_LOCKREVDIR:=$PKGSTATEREVDIR} } function setup_writeOption { local name=$1 local cfgdir=$SETUP_CONFDIR local i mkdir -p "$cfgdir/interfaces" _setup_writeSingleOption "$name" "$cfgdir"/name _setup_writeSingleOption "$SETUP_HOSTNAME" "$cfgdir"/hostname _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 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" ln -s "$SETUP_LOCKREVDIR" "$cfgdir/run.rev" } function setup_writeInitialFstab { cat <$SETUP_CONFDIR/fstab none /proc proc defaults 0 0 none /tmp tmpfs size=16m,mode=1777 0 0 none /dev/pts devpts gid=5,mode=620 0 0 EOF } 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 }