#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=95
boot() {
	mount_root done
	rm -f /sysupgrade.tgz && sync

	# process user commands
	[ -f /etc/rc.local ] && {
		sh /etc/rc.local
	}

	VERSION=`cat /etc/os-release  | grep VERSION= | awk -F'"' '{print $2}'`
	CURRENT_VERSION=`cat /etc/opkg/distfeeds.conf | grep "update.lantronix.com" | awk -F'ipks|main' '{print $2}' | tr -d '/'`
	has_correct_version=`cat /etc/opkg/distfeeds.conf | grep "update.lantronix.com" | grep "ipks/$VERSION/main" | wc -l`;
	if [[ "$has_correct_version" == "0" ]]; then
            if [[ "$CURRENT_VERSION" == "" ]]; then
                sed -i "/update.lantronix.com/ s/ipks\/main/ipks\/$VERSION\/main/g"  /etc/opkg/distfeeds.conf
            else
                sed -i "/update.lantronix.com/ s/ipks\/$CURRENT_VERSION\/main/ipks\/$VERSION\/main/g"  /etc/opkg/distfeeds.conf
            fi
        fi

	# set leds to normal state
	. /etc/diag.sh
	set_state done
}
