#!/bin/bash

#used for cli command "show system rollback"
#input:
#$1:"show_list",used for list the configure files
#$1:"show_config" ,$2: the rollback number,range is [01, 02, 03, ...... 49],used for show a configure
#file
#$1:"show_diff",$2: the rollback number,range is [01, 02, 03, ...... 49],used for diff a rollback
#configure file and the current configure file
 
. /etc/functions

if [ $1 = "show_list" ]; then
	if [ -f ${CONFIG_DIR}pica.conf ]; then
	    ls -l ${CONFIG_DIR}pica.conf*
	else
	    echo "Rollback file doesn't exist!"
	fi

elif [ $1 = "show_config" ]; then
    if [ $2 -lt 1 -o $2 -gt 5 ]; then
        echo
        echo "Rollback number doesn't exist, please input correct rollback number!"
        echo
    elif [ -f ${CONFIG_DIR}pica.conf.$2 ]; then
        echo
        cat ${CONFIG_DIR}pica.conf.$2
        echo

    elif [ -f ${CONFIG_DIR}pica.conf.0$2 ]; then
        echo
        cat ${CONFIG_DIR}pica.conf.0$2
        echo
    
    else
        echo
        echo "Specified rollback file doesn't exist!"
    fi

elif [ $1 = "show_diff" ]; then
    if [ $2 -lt 1 -o $2 -gt 49 ]; then
        echo
        echo "Rollback number doesn't exist, please input correct rollback number!"
        echo
    elif [ -f ${CONFIG_DIR}pica.conf.$2 ]; then
        echo
        diff ${CONFIG_DIR}pica.conf ${CONFIG_DIR}pica.conf.$2
        echo
    elif [ -f ${CONFIG_DIR}pica.conf.0$2 ]; then
        echo
        diff ${CONFIG_DIR}pica.conf ${CONFIG_DIR}pica.conf.0$2
        echo
    else
        echo
        echo "Specified rollback file doesn't exist!"
    fi
fi

exit 0
