#!/bin/bash

SYSTEM_TYPE="$1"

function die() {
    echo "!! $1"
    exit 1
}

OS="`/usr/share/dosis2/bin/whichos`"

if [ -z "${SYSTEM_TYPE}" ]; then
    echo "Usage: disable-prt-broadcast system-type"
    echo "  system-types: L60, U60, SITE_SERVER"
    echo ""
    echo "  Example: disable-prt-broadcast L60"
fi

if [ "${SYSTEM_TYPE}" = "L60" ] || [ "${SYSTEM_TYPE}" = "U60" ]; then
	
    iptables -D FORWARD -m pkttype --pkt-type broadcast -i eth2 -j DROP
    iptables -D INPUT -m pkttype --pkt-type broadcast -i eth2 -j DROP
    iptables -A FORWARD -m pkttype --pkt-type broadcast -i eth2 -j DROP
    iptables -A INPUT -m pkttype --pkt-type broadcast -i eth2 -j DROP
    if [ "${OS}" = "Ubuntu" ]; then
        netfilter-persistent save
    elif [ "${OS}" = "CentOS" ]; then
        service iptables save
    fi

elif [ "${SYSTEM_TYPE}" = "SITE_SERVER" ]; then
    die "Site server has ETH2 disabled. No need to run"
else
    die "Unknown System Type: ${SYSTEM_TYPE}"
fi