view profiles/xSMALL_/files/etc/bin/update @ 209:b7812d60bbcd

More small than SMALL_ profile :)
author ray@terran.dlink.ua
date Sat, 15 Oct 2011 02:31:07 +0300
parents
children 67a155d37199
line wrap: on
line source
#!/bin/sh

. /etc/rc.conf
. /default/version.sh


get_int_version()
{

	VERMJ=`echo "$1" | sed -E 's/([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/\1/'`
	VERMN=`echo "$1" | sed -E 's/([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/\2/'`
	VERBL=`echo "$1" | sed -E 's/([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/\3/'`
	VERINT=$(( ${VERMJ} * 256 ))
	VERINT=$(( ${VERINT} + ${VERMN} ))
	VERINT=$(( ${VERINT} * 65536 ))
	VERINT=$(( ${VERINT} + ${VERBL} ))

}


get_int_version "${IMAGE_VERSION}"
IMAGE_VERSIONINT=${VERINT}

UPDATE_PROFILE=${2-${IMAGE_PROFILE-'ipsec-router'}}
UPDATE_TYPE=${1-FreeBSD}
UPDATE_URL=${update_freebsd_url}

case ${UPDATE_TYPE} in

[Ff][Rr][Ee][Ee][Bb][Ss][Dd])
	UPDATE_TYPE="FreeBSD"
	UPDATE_URL=${update_freebsd_url}
	;;
[Ll][Ii][Nn][Uu][Xx])
	UPDATE_TYPE="Linux"
	UPDATE_URL=${update_linux_url}
	;;
*)
	echo "Unsupported update type"
	echo "Usage: $0 [FreeBSD|Linux] [profile_name]"
	echo "       profile_name - default ipsec-router"
	exit 1
	;;
esac

echo "UPDATE_TYPE=\"${UPDATE_TYPE}\""
echo "UPDATE_PROFILE=\"${UPDATE_PROFILE}\""
echo "UPDATE_URL=\"${UPDATE_URL}\""
cd /tmp
fetch -o /tmp/fwinfo "${UPDATE_URL}?profile=${UPDATE_PROFILE}"
. /tmp/fwinfo

get_int_version "${fwExternal}.${fwInternal}"
NEWEST_VERSION=${VERINT}

if [ ${UPDATE_TYPE} = "FreeBSD" ]; then
	if [ ${NEWEST_VERSION} -gt ${IMAGE_VERSIONINT} ]; then
		echo "Site ${fwExternal}.${fwInternal} version newest than my ${IMAGE_VERSION},"
	else
		fwURL=
		echo "System have newest version, no updating."
	fi

fi

if [ "x${fwURL}" != "x" ];  then
	echo "Updating system image to type ${UPDATE_TYPE}, version ${fwExternal}.${fwInternal}"
	fetch -o /tmp/fw.img "${fwURL}" || exit 1
	upgrade -f /tmp/fw.img 
fi