updated apt state

This commit is contained in:
Paul 2023-07-02 21:32:49 +02:00
parent e257d76caa
commit 2d5ad8d45c
5 changed files with 99 additions and 8 deletions

View File

@ -10,7 +10,9 @@ apt:
- APT::Periodic::Download-Upgradeable-Packages "1";
- APT::Periodic::AutocleanInterval "0";
10proxy:
- Acquire::http::Proxy-Auto-Detect "/usr/local/bin/apt-proxy-detect.py";
- Acquire::http::Proxy-Auto-Detect "/usr/local/bin/apt-proxy-detect";
- Acquire::https::Proxy "DIRECT";
99unauth:
- APT::Get::AllowUnauthenticated "true";
fetch_url: https://paulbsd-pub.s3.fr-par.scw.cloud/apt
arch: amd64

View File

@ -6,19 +6,27 @@ apt-deps:
- avahi-daemon
- avahi-utils
apt-proxy-detect:
apt-proxy-detect-py:
file.managed:
- name: /usr/local/bin/apt-proxy-detect.py
- source: salt://apt/templates/apt.py.j2
- template: jinja
- mode: "0755"
{% for itemkey, itemvalue in apt.config.items() -%}
apt-proxy-{{ itemkey }}:
apt-proxy-detect-go:
file.managed:
- name: /etc/apt/apt.conf.d/{{ itemkey }}
- name: /usr/local/bin/apt-proxy-detect
- source: {{ apt.fetch_url }}/apt_{{ apt.arch }}
- template: jinja
- skip_verify: true
- mode: "0755"
{% for key, value in apt.config.items() -%}
apt-proxy-{{ key }}:
file.managed:
- name: /etc/apt/apt.conf.d/{{ key }}
- user: root
- group: root
- mode: "0644"
- contents: {{ itemvalue }}
- contents: {{ value }}
{% endfor -%}

View File

@ -1,5 +1,11 @@
{%- import_yaml "apt/defaults.yaml" as default_settings %}
{%- set defaults = salt['grains.filter_by'](default_settings, default='apt') %}
{%- import_yaml "apt/osarchmap.yaml" as osarchmap -%}
{%- set apt = salt['pillar.get']('apt', default=defaults, merge=True) %}
{%- set defaults = salt['grains.filter_by'](default_settings,
default='apt',
merge=salt['grains.filter_by'](osarchmap, grain='osarch')
)
-%}
{%- set apt = salt['pillar.get']('apt', default=defaults, merge=True) -%}

21
states/apt/osarchmap.yaml Normal file
View File

@ -0,0 +1,21 @@
---
amd64:
arch: "amd64"
x86_64:
arch: "amd64"
386:
arch: "386"
arm64:
arch: "arm64"
armv6l:
arch: "arm"
armv7l:
arch: "arm"
armhf:
arch: "arm"

View File

@ -0,0 +1,54 @@
package main
import (
"context"
"fmt"
"net"
"time"
"github.com/pion/mdns"
"golang.org/x/net/ipv4"
)
type Proxy struct {
SCHEME string
HOSTNAME string
PORT int
}
func (p *Proxy) Format() string {
return fmt.Sprintf(TMPL, p.SCHEME, p.HOSTNAME, p.PORT)
}
var DEFAULT_PORT = 8000
var DEFAULT_PROXY = Proxy{SCHEME: "http", HOSTNAME: "apt.paulbsd.com", PORT: 8001}
const TMPL = "%s://%s:%d"
func main() {
addr, err := net.ResolveUDPAddr("udp", mdns.DefaultAddress)
if err != nil {
panic(err)
}
l, err := net.ListenUDP("udp4", addr)
if err != nil {
panic(err)
}
server, err := mdns.Server(ipv4.NewPacketConn(l), &mdns.Config{})
if err != nil {
panic(err)
}
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
_, src, err := server.Query(ctx, "apt.local")
if err != nil {
var res = DEFAULT_PROXY
fmt.Println(res.Format())
return
}
var res = Proxy{SCHEME: "http", HOSTNAME: src.String(), PORT: DEFAULT_PORT}
fmt.Println(res.Format())
}