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 [--bcast <broadcast>] [--] <commands> <args>*
35 Do not print the addresses assigned.
37 Network context id to use.
38 --ip <ip_num>[/<mask>]
39 IP address to bind to.
41 Broadcast address for the network context.
43 Report bugs to <$PACKAGE_BUGREPORT>."
47 function showVersion()
50 $"chbind $PACKAGE_VERSION -- bind to IP addresses and execute a program
51 This program is part of $PACKAGE_STRING
53 Copyright (C) 2004 Enrico Scholz
54 Copyright (C) 2006 Daniel Hokka Zakrisson
55 This program is free software; you may redistribute it under the terms of
56 the GNU General Public License. This program has absolutely no warranty."
60 tmp=$(getopt -o + --long ncap:,nid:,ip:,bcast:,disconnect,flag:,secure,silent,help,version -n "$0" -- "$@") || exit 1
74 --help) showHelp $0 0;;
75 --version) showVersion 0;;
76 --ncap) OPT_CAPS=( "${OPT_CAPS[@]}" "$2" ); shift;;
77 --nid) OPT_NID=$2; shift;;
78 --disconnect) OPT_DISCONNECT=1;;
79 --flag) OPT_FLAGS=( "${OPT_FLAGS[@]}" "$2" ); shift;;
80 --secure) OPT_SECURE=1;;
81 --silent) OPT_SILENT=1;;
82 --ip) OPT_IPS=( "${OPT_IPS[@]}" --ip "$2" ); shift;;
83 --bcast) OPT_BCAST=$2; shift;;
85 *) echo $"chbind: internal error; arg=='$1'" >&2; exit 1;;
90 $_VSERVER_INFO - FEATURE vnet || exec $_CHBIND_COMPAT \
91 ${OPT_NID:+--nid "$OPT_NID"} \
92 ${OPT_SILENT:+--silent} \
93 ${OPT_BCAST:+--bcast "$OPT_BCAST"} \
97 create_cmd=( $_NCONTEXT --create --silentexist
98 ${OPT_SILENT:+--silent}
99 ${OPT_NID:+--nid "$OPT_NID"} )
106 chain_cmd=( "${chain_cmd[@]}"
109 ${OPT_SECURE:+--secure}
110 ${OPT_CAPS:+--ncap "${OPT_CAPS[*]}"}
111 ${OPT_FLAGS:+--flag "${OPT_FLAGS[*]}"}
114 ${OPT_SILENT:+--silent}
115 ${OPT_BCAST:+--bcast "$OPT_BCAST"}
118 migrate_cmd=( $_NCONTEXT
119 ${OPT_SILENT:+--silent}
120 ${OPT_DISCONNECT:+--disconnect} )
124 if test -z "$OPT_NID" || $_VSERVER_INFO -q "$OPT_NID" XIDTYPE static; then
125 "${create_cmd[@]}" "${chain_cmd[@]}" -- "$@"
131 test "$rc" -ne 254 || exec "${migrate_cmd[@]}" --nid "$OPT_NID" --migrate -- "$@"