diff --git a/weave b/weave index 4436bce1..e26da4bb 100755 --- a/weave +++ b/weave @@ -24,12 +24,6 @@ usage() { exit 1 } -# utility function to check whether a command can be executed by the shell -# see http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script -command_exists () { - command -v $1 >/dev/null 2>&1 -} - [ `id -u` = 0 ] || { echo "weave must be run as 'root'" >&2 exit 1 @@ -53,18 +47,17 @@ COMMAND=$1 shift 1 -check_command_and_run_anything() { - if command_exists $1 - then - shift 1 - "$@" - else - echo "Cannot find $1; please install it. Continuing without it." >&2 - fi +# utility function to check whether a command can be executed by the shell +# see http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script +command_exists () { + command -v $1 >/dev/null 2>&1 } -check_command_and_run() { - check_command_and_run_anything $1 "$@" +command_exists_or_warn () { + if ! command_exists $1 ; then + echo "Cannot find $1; please install it. Continuing without it." >&2 + return 1 + fi } is_cidr() { @@ -124,7 +117,7 @@ create_bridge() { ip link set dev v${CONTAINER_IFNAME}du master $BRIDGE ip link del dev v${CONTAINER_IFNAME}du # disable offloading - check_command_and_run ethtool -K $BRIDGE tx off >/dev/null + if command_exists_or_warn ethtool; then ethtool -K $BRIDGE tx off >/dev/null; fi # Work around the situation where there are no rules allowing traffic # across our bridge. E.g. ufw add_iptables_rule filter FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT @@ -205,7 +198,7 @@ connect_container_to_bridge() { return 1 fi - if check_command_and_run ethtool -K $GUEST_IFNAME tx off >/dev/null && + if { if command_exists_or_warn ethtool; then ethtool -K $GUEST_IFNAME tx off >/dev/null; fi } && ip link set $LOCAL_IFNAME master $BRIDGE && ip link set $LOCAL_IFNAME up && ip link set $GUEST_IFNAME netns $NETNS ; then @@ -224,7 +217,7 @@ launch() { return 1 fi connect_container_to_bridge && - check_command_and_run_anything ethtool ip netns exec $NETNS ethtool -K eth0 tx off >/dev/null && + { if command_exists_or_warn ethtool ; then ip netns exec $NETNS ethtool -K eth0 tx off >/dev/null; fi } && ip netns exec $NETNS ip link set $CONTAINER_IFNAME up } @@ -552,7 +545,9 @@ case "$COMMAND" in echo "Weave is not running." >&2 fi docker rm -f $CONTAINER_NAME >/dev/null 2>&1 || true - check_command_and_run conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true + if command_exists_or_warn conntrack; then + conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true + fi ;; stop-dns) [ $# -eq 0 ] || usage @@ -567,7 +562,9 @@ case "$COMMAND" in docker kill $DNS_CONTAINER_NAME >/dev/null 2>&1 || true docker rm -f $CONTAINER_NAME >/dev/null 2>&1 || true docker rm -f $DNS_CONTAINER_NAME >/dev/null 2>&1 || true - check_command_and_run conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true + if command_exists_or_warn conntrack; then + conntrack -D -p udp --dport $PORT >/dev/null 2>&1 || true + fi destroy_bridge for LOCAL_IFNAME in $(ip link show | grep v${CONTAINER_IFNAME}pl | cut -d ' ' -f 2 | tr -d ':') ; do ip link del $LOCAL_IFNAME