#!/usr/bin/php
<?php

$distros = array(
	"16.04" => "xenial",
	"18.04" => "bionic",
);
$mirror = "http://ftp.ubuntu.com/ubuntu/dists/%dist%/main/installer-%arch%/current/images/netboot/ubuntu-installer/%arch%/%file%";

foreach ( $distros as $version => $name ) {
	mkdir($version);
	chdir($version);
	foreach ( array("amd64","i386") as $arch ) {
		mkdir($arch);
		chdir($arch);

		foreach ( array("linux","initrd.gz") as $file ) {
			echo "{$version} ({$name}) {$arch}/{$file}\n";
			$command = "curl --remote-time --silent --time-cond {$file} -o {$file} " . str_replace(array("%dist%","%arch%","%file%"),array($name,$arch,$file),$mirror);
			exec($command);
		}
		chdir("..");
	}
	chdir("..");
}


$mirror = "http://ftp.ubuntu.com/ubuntu/dists/%dist%-updates/main/installer-%arch%/current/images/netboot/ubuntu-installer/%arch%/%file%";

foreach ( $distros as $version => $name ) {
	mkdir($version);
	chdir($version);
	foreach ( array("amd64","i386") as $arch ) {
		mkdir($arch);
		chdir($arch);

		foreach ( array("linux","initrd.gz") as $file ) {
			echo "{$version} updates ({$name}) {$arch}/{$file}\n";
			$command = "curl --remote-time --silent --time-cond {$file} -o {$file} " . str_replace(array("%dist%","%arch%","%file%"),array($name,$arch,$file),$mirror);
			exec($command);
		}
		chdir("..");
	}
	chdir("..");
}
