aboutsummaryrefslogtreecommitdiff
path: root/docker/arch-code-server/china-magic-for-pkgbuild.py
blob: 43a4d89b2369651743797c5c2378d3ed5163e057 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python3

# In China? Good for you!

import sys
import re

# read STDIN until EOF
content = sys.stdin.read()

url = re.search(r"url=(.+)", content).group(1)
if url.startswith('"') and url.endswith('"'):
    url = url[1:-1]

if url.startswith("https://github.com"): # yah, it's github!
    content = re.sub(r"\$\{\s*url\s*\}|\$url", url, content)
    content = content.replace("https://raw.githubusercontent.com", "https://gh.api.99988866.xyz/https://raw.githubusercontent.com")
    content = re.sub(r'https://github\.com/(.+)/(.+)/releases/download', lambda match: f'https://gh.api.99988866.xyz/{match.group(0)}', content)

# now print the result
print(content)