minor optimizations
[util-vserver.git] / util-vserver / scripts / vserver-setup.functions
index ba14777..3e2086f 100644 (file)
@@ -19,23 +19,28 @@ SETUP_HOSTNAME=
 SETUP_NETDEV=
 SETUP_NETMASK=
 SETUP_NETPREFIX=
-SETUP_BCAST=
+SETUP_NETBCAST=
 SETUP_LOCKFILE=
 SETUP_LOCKREVDIR=
 SETUP_CONFDIR=
+SETUP_CONTEXT=
+SETUP_INITSTYLE=
 
 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_OPTIONS="confdir:,lockfile:,lockrevdir:,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>]
     --lockrevdir <dirname>
-               ...  [default: $RUNDIR/rev/]
+               ...  [default: $CONFDIR/.defaults/run.rev]
     --hostname <hostname>
     --netdev   <device>
+    --netbcast <broadcast>
     --netmask <netmask>|--netprefix <prefix>
                 ...  sets the  default netmask  (a.b.c.d quadruple)  or prefix
                     (length of the interface)
@@ -52,27 +57,31 @@ declare -r SETUP_HELPMSG=$"
                            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
-       --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_BCAST=$2;;
-       --interface)    SETUP_INTERFACES=( "${SETUP_INTERFACES[@]}" "$2" );;
-       --flags)        old_IFS=$IFS
+       (--context)     SETUP_CONTEXT=$2;;
+       (--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" );;
+       (--initstyle)   SETUP_INITSTYLE=$2;;
+       (--flags)       old_IFS=$IFS
                        IFS=,
                        set -- $2
                        SETUP_FLAGS=( "${SETUP_FLAGS[@]}" "$@" )
                        IFS=$old_IFS
                        ;;
-       *)              return 1;;
+       (*)             return 1;;
     esac
 
     return 0
@@ -122,7 +131,8 @@ function setup_setDefaults
 {
     : ${SETUP_CONFDIR:=$CONFDIR/$1}
     : ${SETUP_LOCKFILE:=$RUNDIR/$1}
-    : ${SETUP_LOCKREVDIR:=$RUNDIR/rev}
+    : ${SETUP_LOCKREVDIR:=$CONFDIR/.defaults/run.rev}
+    findFile SETUP_FSTAB "$CONFDIR"/.defaults/fstab "$PKGLIBDEFAULTDIR"/fstab
 }
 
 function setup_writeOption
@@ -131,13 +141,16 @@ function setup_writeOption
     local cfgdir=$SETUP_CONFDIR
     local i
 
-    mkdir -p "$cfgdir/interfaces"
+    mkdir -p "$cfgdir"/interfaces "$cfgdir"/apps/init "$cfgdir"/uts
 
     _setup_writeSingleOption "$name"            "$cfgdir"/name
-    _setup_writeSingleOption "$SETUP_HOSTNAME"  "$cfgdir"/hostname
+    _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
@@ -149,17 +162,13 @@ function setup_writeOption
        echo "$i"
     done >"$cfgdir"/flags
 
-    ln -s "$SETUP_LOCKFILE"   "$cfgdir/run"
-    ln -s "$SETUP_LOCKREVDIR" "$cfgdir/run.rev"
+    ln -s "$SETUP_LOCKFILE"   "$cfgdir"/run
+    ln -s "$SETUP_LOCKREVDIR" "$cfgdir"/run.rev
 }
 
 function setup_writeInitialFstab
 {
-    cat <<EOF >$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
+    cat "$SETUP_FSTAB" >"$SETUP_CONFDIR"/fstab
 }
 
 function setup_test