Annotation of badi/public_scripts/switchgate/dhclient-exit-hooks.d/switchgate-helper, revision 1.3

1.1       adi         1: 
                      2: # dhclient-exit-hook: switchgate-helper
                      3: 
                      4: RUN="yes"
1.3     ! adi         5: SWITCHGATE="/usr/local/sbin/switchgate"
1.1       adi         6: 
1.3     ! adi         7: if [ "$RUN" = "yes" ]; then 
        !             8: 
        !             9:        # ipv4 or ipv6?
        !            10:        if [ -z "$(echo "$reason" | sed -e "s/^.*6$//")" ]; then
        !            11:                IF_FILENAME="dhcp6.${interface}"
        !            12:                IPV="IPv6"
        !            13:        else
        !            14:                IF_FILENAME="dhcp.${interface}"
        !            15:                IPV="IPv4"
        !            16:        fi
1.1       adi        17: 
1.3     ! adi        18:        # get writeable tmp dir from switchgate
        !            19:        SWITCHGATE_TMPDIR="$("$SWITCHGATE" -C)"
        !            20:        if [ $? -ne 0 ]; then
        !            21:                echo -e "Error: Failed to query switchgate:\n\n$SWITCHGATE_TMPDIR"
        !            22:                exit 1
        !            23:        elif [ -z "$SWITCHGATE_TMPDIR" ]; then
        !            24:                echo "Error: No writeable dir from switchgate received. Please check."
        !            25:                exit 1
        !            26:        fi
1.1       adi        27: 
                     28:        
1.3     ! adi        29:        case "$reason" in 
        !            30: 
        !            31:            BOUND|RENEW|REBIND|REBOOT|BOUND6|RENEW6|REBIND6|REBOOT6)
        !            32: 
        !            33:                # check there is a gateway given
        !            34:                if [ -z "$new_routers" ]; then
        !            35:                        echo "No $IPV gateway supplied from DHCP server."
        !            36:                        # remove the gw file
        !            37:                        if [ -f "$SWITCHGATE_TMPDIR/$IF_FILENAME" ]; then
        !            38:                                rm "$SWITCHGATE_TMPDIR/$IF_FILENAME"
        !            39:                        fi
        !            40:                        exit 0
        !            41:                fi
        !            42:                
        !            43:                # create writeable dir if not already existing
        !            44:                if [ ! -d "$SWITCHGATE_TMPDIR" ]; then
        !            45:                        mkdir "$SWITCHGATE_TMPDIR"
        !            46:                fi
        !            47: 
        !            48:                echo "Adding DHCP supplied gateways to the list of gateways for switchgate: $new_routers"
        !            49: 
        !            50:                # Register switchgate routers
        !            51:                echo "$new_routers" | sed -e "s/ /\n/g" > "$SWITCHGATE_TMPDIR/$IF_FILENAME"
        !            52:                ;;
1.1       adi        53: 
1.3     ! adi        54:            *)
        !            55:                # remove the gw file
        !            56:                if [ -f "$SWITCHGATE_TMPDIR/$IF_FILENAME" ]; then
        !            57:                        rm "$SWITCHGATE_TMPDIR/$IF_FILENAME"
        !            58:                fi
        !            59:                exit 0
        !            60:                ;;
1.2       adi        61: 
1.3     ! adi        62:        esac
1.1       adi        63: fi

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>