#!/bin/sh

LEDCNT=$(cat /proc/sysinfo/pd/led  | wc -l)
MAX_LED_IDX=$(expr $LEDCNT - 1)

ledstartred()
{
    for i in $(seq 0 $MAX_LED_IDX); do
        echo "FAST RED" > /tmp/status/led-manager/led$i
    done
    sleep 1
}

ledstartgreen()                             
{                                     
    for i in $(seq 0 $MAX_LED_IDX); do
        echo "FAST GREEN" > /tmp/status/led-manager/led$i
    done                              
    sleep 1                             
} 

ledstop()
{
    for i in $(seq 0 $MAX_LED_IDX); do
        rm -f /tmp/status/led-manager/led$i
    done
    sleep 1
}


cut -f 1 -d: /etc/passwd | grep -q frr

currentver="$(bgpd --version | head -n1 | cut -d" " -f3)"
requiredver="7.5"


if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]; then 
        echo "Correct Version Installed"
 else
        echo "Upgrading BGP"
	ledstop;  
	ledstartgreen;
	/bin/tar -C / -xzvf  /mnt/media/autorun/ffr.tar.gz
	ledstop;
	reboot;

fi
