25 lines
699 B
Plaintext
25 lines
699 B
Plaintext
|
{%- from "apt/map.jinja" import apt with context -%}
|
||
|
#!/usr/bin/env python3
|
||
|
|
||
|
import subprocess
|
||
|
import re
|
||
|
|
||
|
SCHEME = "{{ apt.proxy.scheme }}"
|
||
|
HOSTNAME = "{{ apt.proxy.hostname }}"
|
||
|
PORT = "{{ apt.proxy.port }}"
|
||
|
|
||
|
def main():
|
||
|
regex = re.compile(f".*{HOSTNAME}.*")
|
||
|
cmd = subprocess.Popen(f"avahi-resolve-host-name {HOSTNAME}",
|
||
|
shell=True,
|
||
|
stdout=subprocess.PIPE,
|
||
|
stderr=subprocess.PIPE)
|
||
|
result = cmd.stdout.read().decode().splitlines()
|
||
|
if len(result) > 0:
|
||
|
if regex.match(result[0]):
|
||
|
return f"{SCHEME}://{HOSTNAME}:{PORT}"
|
||
|
return "DIRECT"
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
print(main())
|