#!/bin/bash

nmcli connection delete dummy0 2>/dev/null || :
ip link delete dummy0 2>/dev/null || :

table=" table=50"

# Create connection with 2 IPv4 routes and activate
ip link add dummy0 type dummy
nmcli connection add type dummy ifname dummy0 con-name dummy0 \
	ipv4.method manual ipv4.addresses 192.0.2.251/24 \
	ipv4.routes "198.51.100.0/24 192.0.2.1$table,203.0.113.0/24 192.0.2.1$table" \
	ipv6.method disabled
nmcli connection up dummy0

echo

echo Values before reapply:
echo NM routes:
nmcli -g ipv4.routes connection show dummy0
echo System route:
ip route list table all | grep dummy0 | grep "203.0.113.0"

echo

# Remove one of the routes and reapply
nmcli connection modify dummy0 ipv4.routes "198.51.100.0/24 192.0.2.1$table"
nmcli device reapply dummy0

echo

echo Values after reapply:
echo NM routes:
nmcli -g ipv4.routes connection show dummy0
echo System route:
ip route list table all | grep dummy0 | grep "203.0.113.0"

echo

cnt=$(ip route list table all | grep dummy0 | grep -c "203.0.113.0")
[[ $cnt == 0 ]] && echo RESULT: OK || echo RESULT: FAIL
