#!/bin/sh

# Stop existing services
sudo systemctl stop strongswan frr vpp clixon-restconf

# Time to make the backups
mkdir -p ~/tnsr-config-backup
sudo cp -p /var/tnsr/running_db ~/tnsr-config-backup/running_db-`date +%Y%m%d%H%M%S`.xml
sudo cp -p /var/tnsr/startup_db ~/tnsr-config-backup/startup_db-`date +%Y%m%d%H%M%S`.xml

# Update all RPMs
sudo yum clean all
sudo yum clean expire-cache
sudo yum -y upgrade

# Ensure services are stopped, in case some automatically started after update.
sudo systemctl stop strongswan frr vpp clixon-restconf

# Run config database upgrade script
sudo /usr/bin/tnsr-db-update

# Start services
sudo systemctl start clixon-backend clixon-restconf