Auto upgrade script V3.x: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
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;
# TODO: auto detect platform
:local platform "mipsle";


: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" src-path="latestVer.txt" user="admin" password="" mode=ftp;
      :local lVer [/file get latestVer.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: should never happen ( /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=[:resolve "www.mikrotik.com"] host="www.mikrotik.com" mode=http src-path="download/$pckgName";
/system reboot;
/system reboot;
}
} else={
                :log info "Upgrade_script: already latest version";
        }
}
}


Line 67: Line 71:


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]]

Latest revision as of 08:02, 15 June 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" src-path="latestVer.txt" user="admin" password="" mode=ftp;
       :local lVer [/file get latestVer.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=[:resolve "www.mikrotik.com"] host="www.mikrotik.com" mode=http src-path="download/$pckgName";
		/system reboot;
	} else={
                :log info "Upgrade_script: already latest version";
        }
}


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