#!/bin/bash

# Check if running as root
if [ "$EUID" -ne 0 ]; then
  echo -e "${RED}This script must be run as root${NC}"
  exit 1
fi

cmd=$1
SERVER="192.168.50.10"

function delete_route() {
  ip route del 10.0.255.1/32 via "$SERVER"
  ip route del 10.0.0.0/24 via "$SERVER"
  ip route del 10.0.15.0/24 via "$SERVER"
  ip route del 121.78.0.216/29 via "$SERVER"
  ip route del 121.78.0.212/30 via "$SERVER"
  ip route del 121.78.0.208/31 via "$SERVER"
  ip route del 121.78.0.211/32 via "$SERVER"
}

function add_route() {
  ip route add 10.0.255.1/32 via "$SERVER"
  ip route add 10.0.0.0/24 via "$SERVER"
  ip route add 10.0.15.0/24 via "$SERVER"
  ip route add 121.78.0.216/29 via "$SERVER"
  ip route add 121.78.0.212/30 via "$SERVER"
  ip route add 121.78.0.208/31 via "$SERVER"
  ip route add 121.78.0.211/32 via "$SERVER"
}

if [ -z "$cmd" ]; then
 echo "add or del"
 exit 1
fi

case $cmd in
add)
  echo add
  delete_route 2>/dev/null
  add_route
  ;;
del)
  echo del
  delete_route
  ;;
*)
  echo "add or del"
  exit 1
  ;;
esac

