#!/bin/sh

#  Description:
#
# This is an if-up.d script to create natfree nework interface when bringing up network
# The script by itself, creates interface (if needed) without configuration.
# This script also checks for the availability of "natfree-server" configuration tool.
# If this configuration tool is available (like in a wired natfree lliurex server)
# "natfree-server update" is executed to configure the interface.
#


#####################
#  vars & functions #
#####################

# load common functions
. /usr/share/natfree-common/natfree-common

# get default route iface
GW_IFACE="$(get_gw_iface)"

########
# main #
########

[ "$GW_IFACE" ] || die "Unable to find network gateway iface"
[ "$DEVICE_IFACE" ] || die "Undefined 'IFACE' environment var. May be not running under networkd-dispatcher?"

# correct interface up?
[ "$GW_IFACE" = "$DEVICE_IFACE" ] || exit 0

# create interface
natfree-iface -i "$GW_IFACE" create

exit 0

