Auto upgrade script V3.x: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
Eep (talk | contribs)
m Protected "Auto upgrade script V3.x": w [edit=sysop:move=sysop]
No edit summary
Line 30: Line 30:




# TODO: auto detect platform
# detect platform
:local platform "mipsle";
:local platform [/system resource get architecture-name];


:local myVer [/system resource get version];
:local myVer [/system resource get version];
Line 54: Line 54:


:if ($vMajor < 3) do={
:if ($vMajor < 3) do={
:log warning "oOops: should never happen ( /tool fetch supported only on 3.x )";
:log warning "oOops:( /tool fetch supported only on 3.x )";
} else={  
} else={  
:if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={
:if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={
Line 67: Line 67:


Add scheduler to run this script, for example once in 24h (or whatever interval you like).
Add scheduler to run this script, for example once in 24h (or whatever interval you like).
This script will download packages for mipsle platform, set
':local platform' variable to correct platform that will run this script:
*) "x86" - all x86 machines ( RB200, intel, amd );
*) "mipsbe" - rb4xx and other atheros based boards
*) "mipsle" - rb1xx, rb5xx
*) "powerpc" - rb333, rb600, rb1000
TODO: add code to detect platform automatically.


[[Category:Scripting]]
[[Category:Scripting]]

Revision as of 11:22, 15 April 2009

One little script to upgrade RrouterBoards automatically.

  • ) fetch file from main router containing latest ROS version number;
  • ) get currently running version number;
  • ) extract minor and major version numbers and compare them;
  • ) if version fetched from main router is newer then download combined package directly from mikrotik.com
  • ) reboot.

At first you should create file containing newest version number on main router.

/file print file="latestVer";
/file set latestVer.txt content="3.3";

Now we are ready to run scripts on other routers:

#########################################################################
# download and upgrade
#########################################################################

# newest version
:local lMajor;
:local lMinor;

# current version
:local vMajor;
:local vMinor;


# detect platform
:local platform [/system resource get architecture-name];

:local myVer [/system resource get version];

# fetch latest version
/tool fetch address="172.16.0.1" path="currentVer.txt" user="admin" password="" mode=ftp;
:local lVer [/file get currentVer.txt content];

:for i from=0 to=([:len $myVer] - 1) do={  
	:if ( [:pick $myVer $i] = ".") do={ 
		:set vMajor [:tonum [:pick $myVer 0 $i]]; 
		:set vMinor [:tonum [:pick $myVer ($i + 1) [:len $myVer]]] ;
	}
}

:for i from=0 to=([:len $lVer] - 1) do={  
	:if ( [:pick $lVer $i] = ".") do={ 
		:set lMajor [:tonum [:pick $lVer 0 $i]]; 
		:set lMinor [:tonum [:pick $lVer ($i + 1) [:len $lVer]]] ;
	}
}

:if ($vMajor < 3) do={
	:log warning "oOops:( /tool fetch supported only on 3.x )";
} else={ 
	:if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={
		:local pckgName ("routeros-" . $platform . "-" . $lMajor . "." . $lMinor . ".npk");
		/tool fetch address="www.mikrotik.com" host="www.mikrotik.com" mode=http path="download/$pckgName";
		/system reboot;
	}
}


Add scheduler to run this script, for example once in 24h (or whatever interval you like).