#!/bin/bash

# check if polycubed is alive
polycubed_alive=$(ps -el | grep polycubed)
if [ -z "$polycubed_alive" ]; then
    echo "pcn-iptables is not able to find any daemon running."
    echo "please try to run:"
    echo ""
    echo "sudo polycubed"
    exit 1
fi

ret=$(polycubectl iptables pcn-iptables show)
ret=$(echo $?)

if [ $ret -ne 0 ]
    then
        echo "starting pcn-iptables ..."
        polycubectl iptables add pcn-iptables type=XDP_DRV
        exit 0
else
    echo "pcn-iptables already running ..."
fi
