Mercurial > code > home > repos > infra
annotate apt.py @ 288:3af02e24eaf9
minor
author | drewp@bigasterisk.com |
---|---|
date | Sun, 21 Apr 2024 17:01:13 -0700 |
parents | 73ec5064da44 |
children | 65e28d2e0cd8 |
rev | line source |
---|---|
282 | 1 import io |
195 | 2 from pathlib import Path |
280 | 3 import shlex |
288 | 4 from typing import cast |
155 | 5 from pyinfra import host |
6 from pyinfra.facts.files import FindFiles | |
7 from pyinfra.facts.server import Arch, LinuxDistribution | |
8 from pyinfra.operations import apt, files, server | |
9 | |
10 TZ = 'America/Los_Angeles' | |
11 | |
278 | 12 is_pi = host.get_fact(LinuxDistribution)['name'] in ['Debian', 'Raspbian GNU/Linux'] |
178
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
13 |
282 | 14 |
155 | 15 def pkg_keys(): |
178
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
16 files.directory(path='/etc/apt/keyrings/') # for raspi |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
17 for url, name in [ |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
18 ('https://repo.steampowered.com/steam/archive/stable/steam.gpg', 'steam.gpg'), |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
19 ]: |
247 | 20 files.download(src=url, dest=f'/usr/share/keyrings/{name}') |
203 | 21 |
22 # vscode keeps making this, but I fetch my own | |
235
19a7f714273c
pkg updates, take out nvidia drv for now
drewp@bigasterisk.com
parents:
230
diff
changeset
|
23 files.file(path='/etc/apt/trusted.gpg.d/microsoft.gpg', present=False) |
203 | 24 |
230 | 25 # and it makes this, which is redundant with my sources.list template line |
26 files.file(path='/etc/apt/sources.list.d/vscode.list', present=False) | |
27 | |
240 | 28 apt.packages(packages=['curl']) |
187
466108f0a509
redo pkg keys and future podman 4.3.1 version
drewp@bigasterisk.com
parents:
178
diff
changeset
|
29 server.shell(commands=[ |
280 | 30 f"curl -fsSL {shlex.quote(url)} | gpg --dearmor > /etc/apt/keyrings/{name}" for (url, name) in [ |
187
466108f0a509
redo pkg keys and future podman 4.3.1 version
drewp@bigasterisk.com
parents:
178
diff
changeset
|
31 ('https://packages.microsoft.com/keys/microsoft.asc', 'ms.gpg'), |
249 | 32 ('https://deb.nodesource.com/gpgkey/nodesource.gpg.key', 'nodesource-older.gpg'), # rm after everything's on 23.10 |
240 | 33 ('https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key', 'nodesource.gpg'), |
187
466108f0a509
redo pkg keys and future podman 4.3.1 version
drewp@bigasterisk.com
parents:
178
diff
changeset
|
34 ('https://dl.google.com/linux/linux_signing_key.pub', 'chrome.gpg'), |
195 | 35 ('https://ftp-master.debian.org/keys/archive-key-11.asc', 'bullseye.gpg'), |
36 ('https://ftp-master.debian.org/keys/archive-key-11-security.asc', 'bullseye-security.gpg'), | |
209 | 37 ('https://packages.cloud.google.com/apt/doc/apt-key.gpg', 'coral.gpg'), |
249 | 38 ('https://hub.unity3d.com/linux/keys/public', 'unityhub.gpg'), |
254 | 39 ('https://nvidia.github.io/libnvidia-container/gpgkey', 'nvidia.gpg'), |
187
466108f0a509
redo pkg keys and future podman 4.3.1 version
drewp@bigasterisk.com
parents:
178
diff
changeset
|
40 ] |
466108f0a509
redo pkg keys and future podman 4.3.1 version
drewp@bigasterisk.com
parents:
178
diff
changeset
|
41 ]) |
280 | 42 if is_pi or host.name == 'bang': |
195 | 43 # this contaminates the apt-update |
44 files.file(path="/etc/apt/trusted.gpg.d/podman.asc", present=False) | |
45 | |
211 | 46 # also these |
47 #-rw-r--r-- 1 root root 2794 Mar 26 2021 /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg | |
48 #-rw-r--r-- 1 root root 1733 Mar 26 2021 /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg | |
282 | 49 |
280 | 50 # raspi needs wget http://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add - |
195 | 51 |
249 | 52 |
195 | 53 dir = Path('/etc/apt/sources.list.d') |
54 | |
55 | |
240 | 56 def clear_known_sources_files(known=[ |
249 | 57 dir / 'vscode.list', |
58 dir / 'google-chrome.list', | |
59 dir / 'steam-beta.list', | |
60 dir / 'google-chrome-unstable.list', | |
61 dir / 'steam-stable.list', | |
280 | 62 dir / 'raspi.list', |
240 | 63 ]): |
288 | 64 found = map(Path, cast(str, host.get_fact(FindFiles, dir, quote_path=True))) |
195 | 65 if set(found) - set(known): |
66 raise SystemExit(f"new files in {host.name} /etc/apt/sources.list.d/ - please remove") | |
67 for f in known: | |
68 files.file(path=f, present=False) | |
155 | 69 |
70 | |
71 def apt_sources(): | |
72 if host.get_fact(Arch) == 'x86_64': | |
73 server.shell(commands=['dpkg --add-architecture i386']) | |
74 | |
75 files.template(src='templates/sources.list.j2', dest='/etc/apt/sources.list') | |
195 | 76 |
77 clear_known_sources_files() | |
155 | 78 apt.packages(update=True, |
187
466108f0a509
redo pkg keys and future podman 4.3.1 version
drewp@bigasterisk.com
parents:
178
diff
changeset
|
79 cache_time=86400, |
178
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
80 packages=['tzdata'], |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
81 force=True, |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
82 _env={ |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
83 'TZ': TZ, |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
84 'LANG': 'en_US.UTF-8', |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
85 'DEBIAN_FRONTEND': 'noninteractive' |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
86 }) |
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
87 |
188 | 88 # squib 1st setup seemed to need more updates for node(nodesource) |
89 # and steam-launcher | |
178
6ec7cd3615f0
another try at apt.key, but it doesn't completely work because prime
drewp@bigasterisk.com
parents:
155
diff
changeset
|
90 |
283 | 91 |
271 | 92 def flatpak_sources(): |
286 | 93 apt.packages(update=True, cache_time=86400, packages=['flatpak']) |
288 | 94 server.shell(commands='flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo') |
195 | 95 |
282 | 96 |
97 def correct_dns(): | |
98 files.put(src=io.StringIO("nameserver 10.2.0.3\n"), dest='/etc/resolv.conf') | |
99 | |
100 | |
101 if is_pi: | |
102 correct_dns() | |
155 | 103 pkg_keys() |
187
466108f0a509
redo pkg keys and future podman 4.3.1 version
drewp@bigasterisk.com
parents:
178
diff
changeset
|
104 apt_sources() |
282 | 105 flatpak_sources() |