Bulk download for MikroTik packages

Just want to share a very useful command that helps with bulk downloading from

https://mikrotik.com/download

## Preview what *would* be downloaded (recommended first)

Replace `wget` with `echo` to see all URLs before downloading anything:

for i in $(curl -s "https://mikrotik.com/download" | grep 'download.mikrotik.com' | grep -oP '(?<=href=")[^"]*'); do echo "$i"; done

This prints all detected download URLs without downloading them.

Useful to verify that your filters are correct.

## Download all available MikroTik files

for i in $(curl -s "https://mikrotik.com/download" | grep 'download.mikrotik.com' | grep -oP '(?<=href=")[^"]*'); do wget "$i"; done

Useful for people like me who want to keep **all MikroTik packages locally**

(I do this 2–3 times per year as an offline repository).

## Download only a specific RouterOS version (example: 7.20.4)

for i in $(curl -s "https://mikrotik.com/download" | grep 'download.mikrotik.com' | grep -oP '(?<=href=")[^"]*' | grep '7.20.4'); do wget "$i"; done

Regards :slight_smile:

Maybe specifying on which OS those commands are intended to be run would be useful.

I presume Linux/bash, maybe MacOS :confused:, Windows will need curl and a port of grep (and batch syntax is slightly different).

So , Linux .. I don’t see a reason why not on MacOS.

As general this is simple bash/sh loop , the “magical“ part is == grep -oP '(?<=href=")[^"]*' == , so if any Windows ninja can contribute and translate it to powershell or whatever I guess a lot of people will appreciate it .

Use WSL.
No Powershell needed :rofl:

1 Like

MikroTik's download URLs follow a known scheme for downloading packages. So no need for grep'ing the HTML, since you can just replace the version and architecture in the URL.

Similar with a "stable" or any channel, you can use awk and the .../

curl -s https://download.mikrotik.com/routeros/NEWESTa7.testing | awk '{ print $1 }'

which gets "7.21beta8", and that can be used in the direct URL. And once you've downloaded the historic packages, you can just cron or similar to schedule checking the .../NEWESTa7. to update your archive.

So I'm not sure scraping the HTML is needed, outside finding older versions.

Not only well known but scripts to do that by simply type arch/version exsits from years.

However you need to know 2 thinks , arch and version .. In my case I just do that 2 -3 times per year regarldes of both can get all lates and grates (including change logs, winbox, swith os etc.. ) :slight_smile: IMO no one need to do this execept if want to have offiline copy when own multiple different arch. devices (think on it as similar to have linux distro offline/local mirror pkg repo)

Intresting is this NEWESTa7.testing file have aways same name ?

Yes, the URL only changes the .testing part, to .stable, etc., which is the "channel" name provided after the . extension.

It also returns the build number, separated by space, which is why the awk is needed to get the just the version number needed build the actual download URLs.

There is similar URL for WinBox, curl -s https://upgrade.mikrotik.com/routeros/winbox/LATEST.4 that return the current version.

Now the URL have changed in past, but since RouterOS (and WinBox) use these URL to do their update checks, there is always a URL to get version

1 Like
#!/bin/bash
ARCH=('-arm' '-arm64' '-mipsbe' '-mmips' '-smips' '-tile' '-ppc' '')
VERSION=('6' '7' 'a7')
RELEASE=('long-term' 'stable' 'testing' 'development')
echo Mikrotik Versions of RouterOS/Firmware.
for arch in "${ARCH[@]}"
do
	for ver in "${VERSION[@]}"
	do
		echo Ver ${ver}
		for rel in "${RELEASE[@]}"
		do
			version=$(curl -s http://upgrade.mikrotik.com/routeros/NEWEST${ver}.${rel} | cut -f1 -d' ')
			echo ${arch:1} ${rel} https://download.mikrotik.com/routeros/${version}/routeros-${version}${arch}.npk
		done
	done
done
echo
2 Likes

cool, only missing changelogs , dude, winbox , netinstall, allpkgs, swos :wink: