-
Notifications
You must be signed in to change notification settings - Fork 1
/
storeid-wrapper
executable file
·40 lines (31 loc) · 1.33 KB
/
storeid-wrapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python3 -u
__author__ = "Lionel Nicolas <[email protected]>"
__copyright__ = "Copyright 2016 Lionel Nicolas"
__license__ = "Apache License, Version 2.0"
__version__ = "1.2"
import re
import sys
HTTPREDIR = re.compile('^http://httpredir\.debian\.org/.*')
APT_DOMAIN = 'http://apt.squid.internal'
APT_RE_MIRROR = re.compile('^.*/(debian|ubuntu)/(pool/.*)\.(deb|udeb|tar.gz|tar.xz|tar.bz2)$')
YUM_DOMAIN = 'http://yum.squid.internal'
YUM_RE_MIRROR = re.compile('^.*/(x86_64/.*)\.(gz|bz2|xml|srpm|drpm|rpm)$')
while True:
try:
line = sys.stdin.readline().replace('\r', '').replace('\n', '')
except KeyboardInterrupt:
break
if not line:
break
match_httpredir = HTTPREDIR.match(line)
match_apt_mirror = APT_RE_MIRROR.match(line)
match_yum_mirror = YUM_RE_MIRROR.match(line)
if match_httpredir:
# do not rewrite calls to httpredir.debian.org, because redirection store-id will collide with the "real" one
print ("ERR")
elif match_apt_mirror:
print ("OK store-id=%s/%s/%s.%s" % (APT_DOMAIN, match_apt_mirror.group(1), match_apt_mirror.group(2), match_apt_mirror.group(3)))
elif match_yum_mirror:
print ("OK store-id=%s/%s.%s" % (YUM_DOMAIN, match_yum_mirror.group(1), match_yum_mirror.group(2)))
else:
print ("ERR")