Skip to content

Instantly share code, notes, and snippets.

@freyes
Created March 22, 2017 19:56
Show Gist options
  • Select an option

  • Save freyes/b72a39b71b6d92239550895d78cd7e30 to your computer and use it in GitHub Desktop.

Select an option

Save freyes/b72a39b71b6d92239550895d78cd7e30 to your computer and use it in GitHub Desktop.
Redirect ubuntu archive requests to another mirror when using squid as an apt proxy (or transparent proxy)
#!/usr/bin/perl
#
# url_rewrite_program /etc/squid/rewrite.pl
# add ^^^ to your squid.conf
#
$mirror = "example.com";
$| = 1;
while (<>) {
@line = split;
$_ = $line[0];
if (m/^http:\/\/((?:[a-z0-9]+\.)?archive\.ubuntu\.com)\/(.*)/ &&
$1 ne $mirror) {
print "http://" . $mirror . "/" . $2 . "\n";
} else {
print $_ . "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment