#!/bin/bash
# config-scripts/src/share/networkif_vlan_helper.sh
# 
#  Copyright: ©2011, Güralp Systems Ltd.
#  Author: Bob Dunlop <rdunlop@guralp.com>
#  License: GPLv3
#

# Load support functions
script_dir=$(dirname $0)
. $script_dir/functions.sh


exit_code=0

# Create a new script and initialise the VLAN support if needed.
# Parent will then start the service.
add_vlan_svc() {

    cd "$INITDIR2"

    # Load and configure the VLAN support module if required
    if [ ! -e /proc/net/vlan/config ]
    then
        modprobe 8021q
        vconfig set_name_type vlan_plus_vid
    fi

    # If the file already exists we do nothing more
    [ -x net_$intrf ] && return 0

    # Create the new service script for the interface
    sed -e "s/^INTRF=.*/INTRF=${intrf}/" \
        < /usr/share/svc_net/net.generic > "net_$intrf"
    chmod 0755 "net_$intrf"
}

# Delete the script.
# The parent should already have stopped any associated service.
del_vlan_svc() {

    rm -f "$INITDIR2/net_$intrf"
}


# Get the action to take and interface to apply it to
act=$1
intrf=$2

# Sanity check the interface
case "X$intrf" in
Xvlan????)
    :
    ;;
*)
    echo "Bad interface $intrf"
    exit 1
    ;;
esac

shift
case "X$act" in
Xadd)
    add_vlan_svc
    ;;
Xdelete)
    del_vlan_svc
    ;;
*)
    echo "Bad action $act"
    exit 1
    ;;
esac

exit $exit_code

# vim: ts=4:sw=4:expandtab
