4 # Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 # Copyright (C) 2006 Daniel Hokka Zakrisson
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 : ${UTIL_VSERVER_VARS:=/usr/lib/util-vserver/util-vserver-vars}
21 test -e "$UTIL_VSERVER_VARS" || {
22 echo $"Can not find util-vserver installation (the file '$UTIL_VSERVER_VARS' would be expected); aborting..." >&2
25 . "$UTIL_VSERVER_VARS"
31 $"Usage: $1 [--silent] [--nid <nid>] [--ip <ip_num>[/<mask>]]
32 [--lback <loopback>] [--bcast <broadcast>]
33 [--] <commands> <args>*
36 Do not print the addresses assigned.
38 Network context id to use.
39 --ip <ip_num>[/<mask>]
40 IP address to bind to.
42 Loopback address for the network context.
44 Broadcast address for the network context.
46 Report bugs to <$PACKAGE_BUGREPORT>."
50 function showVersion()
53 $"chbind $PACKAGE_VERSION -- bind to IP addresses and execute a program
54 This program is part of $PACKAGE_STRING
56 Copyright (C) 2004 Enrico Scholz
57 Copyright (C) 2006 Daniel Hokka Zakrisson
58 This program is free software; you may redistribute it under the terms of
59 the GNU General Public License. This program has absolutely no warranty."
63 tmp=$(getopt -o + --long ncap:,nid:,ip:,bcast:,lback:,disconnect,flag:,secure,silent,help,version -n "$0" -- "$@") || exit 1
78 --help) showHelp $0 0;;
79 --version) showVersion 0;;
80 --ncap) OPT_CAPS=( "${OPT_CAPS[@]}" "$2" ); shift;;
81 --nid) OPT_NID=$2; shift;;
82 --disconnect) OPT_DISCONNECT=1;;
83 --flag) OPT_FLAGS=( "${OPT_FLAGS[@]}" "$2" ); shift;;
84 --secure) OPT_SECURE=1;;
85 --silent) OPT_SILENT=1;;
86 --ip) OPT_IPS=( "${OPT_IPS[@]}" --ip "$2" ); shift;;
87 --bcast) OPT_BCAST=$2; shift;;
88 --lback) OPT_LBACK=$2; shift;;
90 *) echo $"chbind: internal error; arg=='$1'" >&2; exit 1;;
95 $_VSERVER_INFO - FEATURE vnet || exec $_CHBIND_COMPAT \
96 ${OPT_NID:+--nid "$OPT_NID"} \
97 ${OPT_SILENT:+--silent} \
98 ${OPT_BCAST:+--bcast "$OPT_BCAST"} \
102 create_cmd=( $_NCONTEXT --create --silentexist
103 ${OPT_SILENT:+--silent}
104 ${OPT_NID:+--nid "$OPT_NID"} )
111 chain_cmd=( "${chain_cmd[@]}"
114 ${OPT_SECURE:+--secure}
115 ${OPT_CAPS:+--ncap "${OPT_CAPS[*]}"}
116 ${OPT_FLAGS:+--flag "${OPT_FLAGS[*]}"}
119 ${OPT_SILENT:+--silent}
120 ${OPT_BCAST:+--bcast "$OPT_BCAST"}
121 ${OPT_LBACK:+--lback "$OPT_LBACK"}
124 migrate_cmd=( $_NCONTEXT
125 ${OPT_SILENT:+--silent}
126 ${OPT_DISCONNECT:+--disconnect} )
130 if test -z "$OPT_NID" || $_VSERVER_INFO -q "$OPT_NID" XIDTYPE static; then
131 "${create_cmd[@]}" "${chain_cmd[@]}" -- "$@"
137 test "$rc" -ne 254 || exec "${migrate_cmd[@]}" --nid "$OPT_NID" --migrate -- "$@"