| 1 | #!/bin/sh |
| 2 | |
| 3 | set -eu |
| 4 | python3 - <<'PY' |
| 5 | from pathlib import Path |
| 6 | from urllib.parse import urlsplit |
| 7 | |
| 8 | source = Path('/etc/apt/sources.list.d/debian.sources') |
| 9 | rows = source.read_text().splitlines() |
| 10 | seen = set() |
| 11 | for index, row in enumerate(rows): |
| 12 | if not row.startswith('URIs:'): |
| 13 | continue |
| 14 | entries = row.split()[1:] |
| 15 | if len(entries) != 1: |
| 16 | raise SystemExit('Unexpected Debian source layout; source file was not changed.') |
| 17 | uri = urlsplit(entries[0]) |
| 18 | path = uri.path.rstrip('/') |
| 19 | if uri.scheme not in ('http', 'https') or path not in ('/debian', '/debian-security') or uri.query or uri.fragment: |
| 20 | raise SystemExit('Unexpected Debian source origin; source file was not changed.') |
| 21 | if path in seen: |
| 22 | raise SystemExit('Duplicate Debian source; source file was not changed.') |
| 23 | seen.add(path) |
| 24 | rows[index] = 'URIs: http://deb.debian.org' + path |
| 25 | if seen != {'/debian', '/debian-security'}: |
| 26 | raise SystemExit('Both Debian archive and security sources are required; source file was not changed.') |
| 27 | source.write_text('\n'.join(rows) + '\n') |
| 28 | PY |