Skip to content

Instantly share code, notes, and snippets.

@kmcfate
Created January 9, 2016 02:16
Show Gist options
  • Save kmcfate/4fd006fa9ec3798b7ba4 to your computer and use it in GitHub Desktop.
Save kmcfate/4fd006fa9ec3798b7ba4 to your computer and use it in GitHub Desktop.
How to change the cache ID of squid for repositories
http://pastebin.ca/2422099
http://stackoverflow.com/questions/28240297/squid-storeid-rewrite
Must be tabs:
^http:\/\/.*/([^\/]*\.(?:deb|rpm)) $1
store_id_program /usr/local/squid/store-id.pl /usr/local/squid/store_id_db
store_id_children 5 startup=1
Test:
echo "http://yum.theforeman.org/releases/latest/el6/x86_64/foreman-debug-1.10.0-1.el6.noarch.rpm" | /usr/local/bin/squid-store-id.pl /etc/squid/store-id.conf
OK store-id=foreman-debug-1.10.0-1.el6.noarch.rpm
#!/usr/bin/perl
use strict;
use warnings;
$|=1;
my %url;
# read config file
open CONF, $ARGV[0] or die "Error opening $ARGV[0]: $!";
while (<CONF>) {
chomp;
next if /^\s*#?$/;
my @l = split("\t");
$url{qr/$l[0]/} = $l[$#l];
}
close CONF;
# read urls from squid and do the replacement
URL: while (<STDIN>) {
chomp;
last if /^(exit|quit|x|q)$/;
foreach my $re (keys %url) {
if (my @match = /$re/) {
$_ = $url{$re};
for (my $i=1; $i<=scalar(@match); $i++) {
s/\$$i/$match[$i-1]/g;
}
print "OK store-id=$_\n";
next URL;
}
}
print "ERR\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment