#!/bin/bash function check_installed() { c=0 e=0 config=$(vtysh -c "show run") for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p'); do echo "$config" | egrep -q "^route-map $route_map_name permit 20$" c=$((c+$?)) e=$((e+1)) echo "$config" | egrep -q "^route-map $route_map_name deny 30$" c=$((c+$?)) e=$((e+1)) done return $((e-c)) } check_installed installed=$? if [[ $installed -ne 0 ]]; then TSB_FILE=$(mktemp) for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p'); do case "$route_map_name" in *V4*) ;; *V6*) ;; *) continue ;; esac sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\"}" -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE" vtysh -f "$TSB_FILE" rm -f "$TSB_FILE" done echo "System Mode: Maintenance -> Normal" else echo "System is already in Normal mode" fi