File cloud-multiroute.sh of Package cloud-multiroute
#!/bin/bash
# cloud-multiroute.sh
# Configuration via user_data
# (c) Kurt Garloff <t-systems@garloff.de>, 3/2017
# License: CC-BY-SA 2.0
#
# Syntax: YAML
# otc:
# multiroute: true
# OR
# otc:
# multiroute: guessgw
#
# The first example sets up routing for secondary network devices that are in the same network
# as the one that has the default route by setting specific routig tables for them using the
# same default gateway and rules to use these tables when the network device is addressed by IP.
#
# The second example does in addition move network devices from other subnets to their own
# routing tables and guesses a default gateway for them (.1 of the net) and configures a
# default route via it in the device-specific routing table.
if test "$1" == "debug"; then DEBUG=1; shift; else unset DEBUG; fi
if test "$1" == "verbose"; then VERBOSE=1; shift; else unset VERBOSE; fi
verbprint()
{
if test "$VERBOSE" = "1"; then
echo $@ 1>&2
fi
}
if test -n "$DEBUG"; then
get_user_data()
{
cat -
}
else
get_user_data()
{
otc mds user_data 2>/dev/null
}
fi
is_multiroute()
{
echo "$1" | shyaml get-value otc.multiroute >/dev/null 2>&1
}
multiroute()
{
echo "$1" | shyaml get-value otc.multiroute
}
## MAIN
export USERDATA=$(get_user_data)
if ! is_multiroute "$USERDATA"; then exit 0; fi
MROUTE=$(multiroute "$USERDATA")
if test "$MROUTE" = "True"; then verbprint rttbl2.sh; rttbl2.sh
elif test "$MROUTE" = "guessgw"; then verbprint rttbl2 -g; rttbl2.sh -g
else echo "Unknown multiroute setting $MROUTE"; exit 1;
fi