Sunday, May 22, 2016

Use squid redirect_program to correct bandersnatch directory structure for easy_install -- update to python3 and >=squid 3.3.8


follow the previous howto
http://www.atechnote.com/search?q=easy_install

change only stop 1,2,3 the rest will be the same

1- install squid and python3
$ sudo apt-get install squid python3

2- update squid configuration /etc/squid3/squid.conf
acl Safe_ports port 80        # http
acl Safe_ports port 21        # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 70        # gopher
acl Safe_ports port 210        # wais
acl Safe_ports port 1025-65535    # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl CONNECT method CONNECT
acl localnet src 10.0.3.0/24
http_access allow localnet
http_access allow localhost manager
http_access deny manager
http_access deny all
http_port 3128
dns_nameservers 10.0.3.1
visible_hostname u-trusty-lxc
acl pypi dstdomain .pypi.repo
url_rewrite_access allow pypi
redirect_program /usr/bin/python3 /etc/squid3/helper.py
redirect_children 5
coredump_dir /var/spool/squid3
refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|\?) 0    0%    0
refresh_pattern (Release|Packages(.gz)*)$      0       20%     2880
refresh_pattern .        0    20%    4320


3- helper file /etc/squid3/helper.py
import sys
import re
def modify_url(line):
    if line == "":
        return line
    ulist = line.split()
    old_url = ulist[0]
    old_url1 = ulist[0]
    new_url = "\n"
    old_url = re.sub(r"/$","",old_url)
    n = old_url.split("/")
    if len(n) < 4:
        return old_url1

    if re.search(r"pypi.repo/./.*", old_url):
        return old_url1

    else:
        old_url = re.sub(r"/$","",old_url)
        n = old_url.split("/")
        startLetter = n[3][0]
        new_urls = "/".join(n[0:3]) + "/" + startLetter + "/" + "/".join(n[3:])

    return new_urls


while True:
  
    line = sys.stdin.readline().strip()
    new_url = modify_url(line)
    print(new_url)
    sys.stdout.flush()



4- start squid
$ sudo squid -f /etc/squid3/squid.conf
- if you have problem you can run squid in debug mode to see what wrong.
$ sudo squid -d 5 -f /etc/squid3/squid.conf

No comments:

Post a Comment