updated apt state

This commit is contained in:
Paul 2022-07-27 23:49:54 +02:00
parent 25e7ca4917
commit 769dfd0917
3 changed files with 50 additions and 2 deletions

24
states/apt/apt.py.j2 Executable file
View File

@ -0,0 +1,24 @@
{%- 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())

View File

@ -1,6 +1,17 @@
--- ---
apt: apt:
config: {} proxy:
scheme: http
hostname: apt.local
port: 8000
config:
10proxy:
content:
- Acquire::http::ProxyAutoDetect "/usr/local/bin/apt-proxy-detect.py";
- Acquire::https::Proxy "DIRECT";
99unauth:
content:
- APT::Get::AllowUnauthenticated "true";
# apt: # apt:
# config: # config:

View File

@ -1,9 +1,22 @@
--- ---
{%- from "apt/map.jinja" import apt with context %} {%- from "apt/map.jinja" import apt with context %}
apt-deps:
pkg.installed:
- pkgs:
- avahi-daemon
- avahi-utils
apt-proxy-detect:
file.managed:
- name: /usr/local/bin/apt-proxy-detect.py
- source: salt://apt/apt.py.j2
- template: jinja
- mode: "0755"
{% for itemkey, itemvalue in apt.config.items() -%} {% for itemkey, itemvalue in apt.config.items() -%}
apt-proxy-{{ itemkey }}: apt-proxy-{{ itemkey }}:
file.managed: file.managed:
- name: /etc/apt/apt.conf.d/{{ k }} - name: /etc/apt/apt.conf.d/{{ itemkey }}
- user: root - user: root
- group: root - group: root
- mode: "0644" - mode: "0644"