#!/bin/sh -e
#
# ufwroute - ufw route allow proto from to port comment

usage() {
  printf %s "\
$(basename "$0")
  a simple script to define ufw routings

usage:
  [tcp/udp] [from: any/cidr/interface] [to: any/cidr/interface] [port] [name]

example:
  $(basename "$0") tcp any 10.88.0.0/16 9443 portainer
"
  exit 0
}

proto="$1"
from="$2"
to="$3"
port="$4"
comment="$5"

if [ -z "$1" ]; then
  usage
else
  sudo ufw route allow proto "${proto}" from "${from}" to "${to}" port "${port}" \
    comment "${comment}"
fi
