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