Auto upgrade script V3.x: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 11: Line 11:
<pre>
<pre>
/file print file="latestVer";
/file print file="latestVer";
/file set latestVer.txt content="3.3";
/file set latestVer.txt content="3.24";
</pre>
</pre>


Line 28: Line 28:
:local vMajor;
:local vMajor;
:local vMinor;
:local vMinor;
# detect platform
:local platform [/system resource get architecture-name];


:local myVer [/system resource get version];
: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={   
:for i from=0 to=([:len $myVer] - 1) do={   
Line 46: Line 38:
}
}


:for i from=0 to=([:len $lVer] - 1) do={   
:if ($vMajor < 3) do={
:if ( [:pick $lVer $i] = ".") do={  
:log warning "RouterOS version too old ($vMajor.$vMinor),  update script not compatible";
:set lMajor [:tonum [:pick $lVer 0 $i]];  
} else={
:set lMinor [:tonum [:pick $lVer ($i + 1) [:len $lVer]]] ;
 
      # detect platform (architecture-name is not available in older 3.x versions)
      :local platform [/system resource get architecture-name];
 
 
      # 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 $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={
:if (($vMajor = $lMajor) && ($vMinor < $lMinor)) do={
:local pckgName ("routeros-" . $platform . "-" . $lMajor . "." . $lMinor . ".npk");
:local pckgName "routeros-$platform-$lMajor.$lMinor.npk";
/tool fetch address="www.mikrotik.com" host="www.mikrotik.com" mode=http path="download/$pckgName";
/tool fetch address="www.mikrotik.com" host="www.mikrotik.com" mode=http path="download/$pckgName";
/system reboot;
/system reboot;

Revision as of 08:06, 20 May 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.24";

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;

:local myVer [/system resource get version];

: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]]] ;
	}
}

:if ($vMajor < 3) do={
	:log warning "RouterOS version too old ($vMajor.$vMinor),  update script not compatible";
} else={ 

       # detect platform (architecture-name is not available in older 3.x versions)
       :local platform [/system resource get architecture-name];


       # 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 $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 = $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).