Auto upgrade script V3.x: Difference between revisions

From MikroTik Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 59: Line 59:
: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
 


</pre>
</pre>

Revision as of 10:21, 12 February 2008

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;


# TODO: auto detect platform
:local platform "mipsle";

: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: should never happen ( /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).

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.