proxmox-backup-client-installer 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- proxmox_backup_client_installer-0.1.0/PKG-INFO +22 -0
- proxmox_backup_client_installer-0.1.0/README.md +11 -0
- proxmox_backup_client_installer-0.1.0/pyproject.toml +31 -0
- proxmox_backup_client_installer-0.1.0/pyproject.toml.orig +27 -0
- proxmox_backup_client_installer-0.1.0/src/proxmox_backup_client_installer/__init__.py +3 -0
- proxmox_backup_client_installer-0.1.0/src/proxmox_backup_client_installer/cli.py +32 -0
- proxmox_backup_client_installer-0.1.0/src/proxmox_backup_client_installer/defaults.py +11 -0
- proxmox_backup_client_installer-0.1.0/src/proxmox_backup_client_installer/installer.py +441 -0
- proxmox_backup_client_installer-0.1.0/src/proxmox_backup_client_installer/parser.py +58 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: proxmox-backup-client-installer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Install the statically-linked proxmox-backup-client on non-Debian platforms.
|
|
5
|
+
Author: Roger Smith
|
|
6
|
+
Author-email: Roger Smith <rogersmith@noreply.codeberg.org>
|
|
7
|
+
Requires-Dist: python-debian>=1.1.1
|
|
8
|
+
Requires-Dist: requests>=2.34.2
|
|
9
|
+
Requires-Python: >=3.14
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Proxmox backup client installer
|
|
13
|
+
|
|
14
|
+
Install the statically-linked proxmox-backup-client on non-Debian platforms.
|
|
15
|
+
|
|
16
|
+
## Provenance
|
|
17
|
+
|
|
18
|
+
Proudly written with 100% natural stupidity.
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
[GPL-3.0-only](LICENSE.md)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "proxmox-backup-client-installer"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Install the statically-linked proxmox-backup-client on non-Debian platforms."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"python-debian>=1.1.1",
|
|
9
|
+
"requests>=2.34.2",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[[project.authors]]
|
|
13
|
+
name = "Roger Smith"
|
|
14
|
+
email = "rogersmith@noreply.codeberg.org"
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
proxmox-backup-client-installer = "proxmox_backup_client_installer.cli:main"
|
|
18
|
+
|
|
19
|
+
[dependency-groups]
|
|
20
|
+
dev = ["pytest>=9.2.0"]
|
|
21
|
+
|
|
22
|
+
[build-system]
|
|
23
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
24
|
+
build-backend = "uv_build"
|
|
25
|
+
|
|
26
|
+
[tool.pytest.ini_options]
|
|
27
|
+
pythonpath = ["."]
|
|
28
|
+
testpaths = [
|
|
29
|
+
"tests/integration",
|
|
30
|
+
"tests/units",
|
|
31
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "proxmox-backup-client-installer"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Install the statically-linked proxmox-backup-client on non-Debian platforms."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.14"
|
|
7
|
+
authors = [{ name = "Roger Smith", email = "rogersmith@noreply.codeberg.org" }]
|
|
8
|
+
dependencies = [
|
|
9
|
+
"python-debian>=1.1.1",
|
|
10
|
+
"requests>=2.34.2",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
proxmox-backup-client-installer = "proxmox_backup_client_installer.cli:main"
|
|
15
|
+
|
|
16
|
+
[dependency-groups]
|
|
17
|
+
dev = [
|
|
18
|
+
"pytest>=9.2.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["uv_build>=0.13.7,<0.14.0"]
|
|
23
|
+
build-backend = "uv_build"
|
|
24
|
+
|
|
25
|
+
[tool.pytest.ini_options]
|
|
26
|
+
pythonpath = ["."]
|
|
27
|
+
testpaths = ["tests/integration", "tests/units"]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from importlib.metadata import version
|
|
2
|
+
from sys import exit
|
|
3
|
+
|
|
4
|
+
from proxmox_backup_client_installer.installer import Installer
|
|
5
|
+
from proxmox_backup_client_installer.parser import Parser
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main(*args) -> None:
|
|
9
|
+
"""The main CLI entrypoint."""
|
|
10
|
+
|
|
11
|
+
if len(args) > 0:
|
|
12
|
+
parsed = Parser().parse_args(*args)
|
|
13
|
+
else:
|
|
14
|
+
parsed = Parser().parse_args()
|
|
15
|
+
|
|
16
|
+
if parsed.check:
|
|
17
|
+
current_version = Installer.current_version()
|
|
18
|
+
latest_version = Installer(
|
|
19
|
+
parsed.arch, parsed.chan, parsed.dist, parsed.prefix
|
|
20
|
+
).latest_version()
|
|
21
|
+
|
|
22
|
+
print(f"The currently installed version is: {current_version}")
|
|
23
|
+
print(f"The latest version found is: {latest_version}")
|
|
24
|
+
|
|
25
|
+
if current_version != latest_version:
|
|
26
|
+
exit(1)
|
|
27
|
+
|
|
28
|
+
elif parsed.version:
|
|
29
|
+
print(version("proxmox-backup-client-installer"))
|
|
30
|
+
|
|
31
|
+
else:
|
|
32
|
+
Installer(parsed.arch, parsed.chan, parsed.dist, parsed.prefix).install()
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
import sys # Need to dynamically look up sys.stderr for testing...
|
|
2
|
+
from hashlib import sha256
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from re import match, sub
|
|
6
|
+
from subprocess import run
|
|
7
|
+
from tarfile import open as tarfile_open
|
|
8
|
+
from tempfile import TemporaryDirectory
|
|
9
|
+
from typing import BinaryIO, Final, NamedTuple, cast
|
|
10
|
+
|
|
11
|
+
from debian.deb822 import Packages, Release
|
|
12
|
+
from debian.debfile import DebFile
|
|
13
|
+
from requests import get
|
|
14
|
+
|
|
15
|
+
from proxmox_backup_client_installer.defaults import ARCH, CHAN, DIST, PREFIX
|
|
16
|
+
|
|
17
|
+
# It's possible the debian modules are being under-utilised. In particular:
|
|
18
|
+
#
|
|
19
|
+
# - The deb822 classes seem like they should be able to do their own gpg validation, but it was not
|
|
20
|
+
# clear how to get that to work. Instead, gpgv is called manually.
|
|
21
|
+
# - The Packges class seems like it should be able to parse an entire file, but only parsed the
|
|
22
|
+
# first paragraph. Instead, the file is split into separate paragraphs to be parsed.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class CertLink(NamedTuple):
|
|
26
|
+
"""Data structure for ssl symlinks"""
|
|
27
|
+
|
|
28
|
+
name: str | Path
|
|
29
|
+
"""Name/location of symlink"""
|
|
30
|
+
|
|
31
|
+
target: str | Path
|
|
32
|
+
"""Target of symlink"""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Installer:
|
|
36
|
+
"""Class to perform the installation process"""
|
|
37
|
+
|
|
38
|
+
_packages_content: None | bytes
|
|
39
|
+
"""Internal cache for Packages file contents"""
|
|
40
|
+
|
|
41
|
+
_inrelease_content: None | bytes
|
|
42
|
+
"""Internal cache for InRelease file contents"""
|
|
43
|
+
|
|
44
|
+
_deb_content: None | bytes
|
|
45
|
+
"""Internal cache for debian package contents"""
|
|
46
|
+
|
|
47
|
+
_key_content: None | bytes
|
|
48
|
+
"""Internal cache for GPG key contents"""
|
|
49
|
+
|
|
50
|
+
ARCHIVE_NAME: Final = "data.tar.xz"
|
|
51
|
+
"""File name of archive to look for in debian package"""
|
|
52
|
+
|
|
53
|
+
CERT_LINKS: Final = [
|
|
54
|
+
CertLink(
|
|
55
|
+
name="/usr/lib/ssl/cert.pem",
|
|
56
|
+
target="/etc/ssl/cert.pem",
|
|
57
|
+
),
|
|
58
|
+
CertLink(
|
|
59
|
+
name="/usr/lib/ssl/certs",
|
|
60
|
+
target="/etc/ssl/certs",
|
|
61
|
+
),
|
|
62
|
+
]
|
|
63
|
+
"""Symlinks to create to support expected debian filesystem locations"""
|
|
64
|
+
|
|
65
|
+
DOWNLOAD_HOST = "http://download.proxmox.com"
|
|
66
|
+
"""Host from which to download package and metadata"""
|
|
67
|
+
|
|
68
|
+
ENTERPRISE_HOST = "https://enterprise.proxmox.com"
|
|
69
|
+
"""Host from which to download the GPG key"""
|
|
70
|
+
|
|
71
|
+
INRELEASE_FILE = "InRelease"
|
|
72
|
+
"""File name of the InRelease file"""
|
|
73
|
+
|
|
74
|
+
PACKAGE_NAME = "proxmox-backup-client-static"
|
|
75
|
+
"""Name of the debian package"""
|
|
76
|
+
|
|
77
|
+
PACKAGES_FILE = "Packages"
|
|
78
|
+
"""File name of the Packages file"""
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
def current_version() -> str | None:
|
|
82
|
+
"""
|
|
83
|
+
Get the currently-installed version of proxmox-backup-client.
|
|
84
|
+
|
|
85
|
+
:return: The version of proxmox-backup-client if it is installed, otherwise None.
|
|
86
|
+
:rtype: str | None
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
process = run(
|
|
91
|
+
["proxmox-backup-client", "version"], check=True, capture_output=True, text=True
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
version_match = match("^client version: (.+)$", process.stdout)
|
|
95
|
+
if version_match:
|
|
96
|
+
return version_match.group(1)
|
|
97
|
+
else:
|
|
98
|
+
raise RuntimeError(f"Failed to parse version from stdout: {process.stdout}")
|
|
99
|
+
|
|
100
|
+
except FileNotFoundError:
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
def __init__(
|
|
104
|
+
self,
|
|
105
|
+
arch: str = ARCH,
|
|
106
|
+
chan: str = CHAN,
|
|
107
|
+
dist: str = DIST,
|
|
108
|
+
prefix: Path | str = PREFIX,
|
|
109
|
+
) -> None:
|
|
110
|
+
self.arch = arch
|
|
111
|
+
self.chan = chan
|
|
112
|
+
self.dist = dist
|
|
113
|
+
self.prefix = prefix
|
|
114
|
+
self._deb_content = None
|
|
115
|
+
self._inrelease_content = None
|
|
116
|
+
self._packages_content = None
|
|
117
|
+
self._key_content = None
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def deb_file(self) -> str:
|
|
121
|
+
"""
|
|
122
|
+
The file name of the debian package of the latest version of proxmox-backup-client found in
|
|
123
|
+
the Packages file.
|
|
124
|
+
|
|
125
|
+
:return: File name
|
|
126
|
+
:rtype: str
|
|
127
|
+
"""
|
|
128
|
+
|
|
129
|
+
return Path(self.deb_meta["Filename"]).name
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def deb_content(self) -> bytes:
|
|
133
|
+
"""
|
|
134
|
+
The contents of the debian package.
|
|
135
|
+
|
|
136
|
+
:return: Package file contents
|
|
137
|
+
:rtype: bytes
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
if not self._deb_content:
|
|
141
|
+
res = get(self.deb_url)
|
|
142
|
+
res.raise_for_status()
|
|
143
|
+
|
|
144
|
+
self.validate_deb(res.content)
|
|
145
|
+
|
|
146
|
+
self._deb_content = res.content
|
|
147
|
+
|
|
148
|
+
return self._deb_content
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def deb_meta(self) -> Packages:
|
|
152
|
+
"""
|
|
153
|
+
The metadata of the debian package of the latest version of proxmox-backup-client found in
|
|
154
|
+
the Packages file.
|
|
155
|
+
|
|
156
|
+
:return: Package metadata
|
|
157
|
+
:rtype: debian.deb822.Packages
|
|
158
|
+
"""
|
|
159
|
+
|
|
160
|
+
for paragraph in self.packages_content.decode("utf-8").split("\n\n"):
|
|
161
|
+
packages = Packages(paragraph)
|
|
162
|
+
|
|
163
|
+
# In case of extra blank lines
|
|
164
|
+
if len(packages) == 0:
|
|
165
|
+
continue
|
|
166
|
+
|
|
167
|
+
if packages["Package"] == self.PACKAGE_NAME:
|
|
168
|
+
package = packages
|
|
169
|
+
|
|
170
|
+
return package
|
|
171
|
+
|
|
172
|
+
@property
|
|
173
|
+
def deb_url(self) -> str:
|
|
174
|
+
"""
|
|
175
|
+
The URL from which the debian package will be downloaded.
|
|
176
|
+
|
|
177
|
+
:return: Package URL
|
|
178
|
+
:rtype: str
|
|
179
|
+
"""
|
|
180
|
+
|
|
181
|
+
return f"{self.DOWNLOAD_HOST}/debian/pbs-client/dists/{self.dist}/{self.chan}/binary-{self.arch}/{self.deb_file}"
|
|
182
|
+
|
|
183
|
+
def extract_deb(self) -> None:
|
|
184
|
+
"""Extract the debian package to the filesystem prefix."""
|
|
185
|
+
|
|
186
|
+
deb = DebFile(fileobj=BytesIO(self.deb_content))
|
|
187
|
+
for member in deb.members:
|
|
188
|
+
if member.name == self.ARCHIVE_NAME:
|
|
189
|
+
archive = member
|
|
190
|
+
break
|
|
191
|
+
|
|
192
|
+
archive = cast(BinaryIO, archive) # Make type checker happy
|
|
193
|
+
with tarfile_open(fileobj=archive, mode="r:xz") as tar:
|
|
194
|
+
for member in tar.getmembers():
|
|
195
|
+
if member.isfile():
|
|
196
|
+
member_file = tar.extractfile(member)
|
|
197
|
+
if member_file is None:
|
|
198
|
+
raise RuntimeError(
|
|
199
|
+
f"Failed to get file handle for tar member {member.name}"
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
name = sub(r"^\./usr", str(self.prefix), member.name)
|
|
203
|
+
path = Path(name)
|
|
204
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
205
|
+
with open(name, "wb") as f:
|
|
206
|
+
f.write(member_file.read())
|
|
207
|
+
path.chmod(member.mode)
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def inrelease_content(self) -> bytes:
|
|
211
|
+
"""
|
|
212
|
+
The content of the InRelease file.
|
|
213
|
+
|
|
214
|
+
:return: File contents
|
|
215
|
+
:rtype: bytes
|
|
216
|
+
"""
|
|
217
|
+
|
|
218
|
+
if self._inrelease_content is None:
|
|
219
|
+
res = get(self.inrelease_url)
|
|
220
|
+
res.raise_for_status()
|
|
221
|
+
|
|
222
|
+
self.validate_inrelease(res.content)
|
|
223
|
+
|
|
224
|
+
self._inrelease_content = res.content
|
|
225
|
+
|
|
226
|
+
return self._inrelease_content
|
|
227
|
+
|
|
228
|
+
@property
|
|
229
|
+
def inrelease_url(self) -> str:
|
|
230
|
+
"""
|
|
231
|
+
The URL from which the InRelease file should be downloaded.
|
|
232
|
+
|
|
233
|
+
:return: InRelease file URL
|
|
234
|
+
:rtype: str
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
return f"{self.DOWNLOAD_HOST}/debian/pbs-client/dists/{self.dist}/{self.INRELEASE_FILE}"
|
|
238
|
+
|
|
239
|
+
def install(self) -> None:
|
|
240
|
+
"""
|
|
241
|
+
Download and install the latest version of proxmox-backup-client.
|
|
242
|
+
"""
|
|
243
|
+
|
|
244
|
+
self.extract_deb()
|
|
245
|
+
self.link_certs()
|
|
246
|
+
|
|
247
|
+
@property
|
|
248
|
+
def key_content(self) -> bytes:
|
|
249
|
+
"""
|
|
250
|
+
The contents of the GPG key.
|
|
251
|
+
|
|
252
|
+
:return: Key contents
|
|
253
|
+
:rtype: bytes
|
|
254
|
+
"""
|
|
255
|
+
if self._key_content is None:
|
|
256
|
+
res = get(self.key_url)
|
|
257
|
+
res.raise_for_status()
|
|
258
|
+
|
|
259
|
+
self._key_content = res.content
|
|
260
|
+
|
|
261
|
+
return self._key_content
|
|
262
|
+
|
|
263
|
+
@property
|
|
264
|
+
def key_file(self) -> str:
|
|
265
|
+
"""
|
|
266
|
+
The file name of the GPG key.
|
|
267
|
+
|
|
268
|
+
:return: Key file name
|
|
269
|
+
:rtype: str
|
|
270
|
+
"""
|
|
271
|
+
|
|
272
|
+
return f"proxmox-release-{self.dist}.gpg"
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def key_url(self) -> str:
|
|
276
|
+
"""
|
|
277
|
+
The URL from which to download the GPG key.
|
|
278
|
+
|
|
279
|
+
:return: Key URL
|
|
280
|
+
:rtype: str
|
|
281
|
+
"""
|
|
282
|
+
|
|
283
|
+
return f"{self.ENTERPRISE_HOST}/debian/{self.key_file}"
|
|
284
|
+
|
|
285
|
+
def latest_version(self) -> str:
|
|
286
|
+
"""
|
|
287
|
+
Get the latest available version of proxmox-backup-client.
|
|
288
|
+
|
|
289
|
+
:return: Latest available version
|
|
290
|
+
:rtype: str
|
|
291
|
+
"""
|
|
292
|
+
|
|
293
|
+
version = self.deb_meta["Version"]
|
|
294
|
+
|
|
295
|
+
matches = match(r"^(.+)-.+$", version)
|
|
296
|
+
if matches:
|
|
297
|
+
version = matches.group(1)
|
|
298
|
+
|
|
299
|
+
return version
|
|
300
|
+
|
|
301
|
+
def link_certs(self) -> None:
|
|
302
|
+
"""Symlink system cert locations to debian cert locations."""
|
|
303
|
+
|
|
304
|
+
try:
|
|
305
|
+
for link in self.CERT_LINKS:
|
|
306
|
+
path = Path(link.name)
|
|
307
|
+
if path.exists():
|
|
308
|
+
continue
|
|
309
|
+
|
|
310
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
311
|
+
path.symlink_to(link.target)
|
|
312
|
+
|
|
313
|
+
except PermissionError:
|
|
314
|
+
print(
|
|
315
|
+
"A permission error occurred while attempting to create supporting symlinks.",
|
|
316
|
+
file=sys.stderr,
|
|
317
|
+
)
|
|
318
|
+
print(
|
|
319
|
+
"If you encounter issues with TLS certificates/fingerprints, consider creating the following symlinks:",
|
|
320
|
+
file=sys.stderr,
|
|
321
|
+
end="\n\n",
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
for link in self.CERT_LINKS:
|
|
325
|
+
print(f"{link.name} -> {link.target}", file=sys.stderr)
|
|
326
|
+
|
|
327
|
+
@property
|
|
328
|
+
def packages_content(self) -> bytes:
|
|
329
|
+
"""
|
|
330
|
+
The contents of the Packages file.
|
|
331
|
+
|
|
332
|
+
:return: File contents
|
|
333
|
+
:rtype: bytes
|
|
334
|
+
"""
|
|
335
|
+
|
|
336
|
+
if not self._packages_content:
|
|
337
|
+
res = get(self.packages_url)
|
|
338
|
+
res.raise_for_status()
|
|
339
|
+
|
|
340
|
+
self.validate_packages(res.content)
|
|
341
|
+
|
|
342
|
+
self._packages_content = res.content
|
|
343
|
+
|
|
344
|
+
return self._packages_content
|
|
345
|
+
|
|
346
|
+
@property
|
|
347
|
+
def packages_meta(self) -> dict:
|
|
348
|
+
"""
|
|
349
|
+
Metadata for the Packages file, from the InRelease file.
|
|
350
|
+
|
|
351
|
+
:return: Packages file metadata
|
|
352
|
+
:rtype: dict
|
|
353
|
+
|
|
354
|
+
:raises RuntimeError: if Packages metadata is not found
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
release = Release(sequence=self.inrelease_content)
|
|
358
|
+
|
|
359
|
+
for file in release["SHA256"]:
|
|
360
|
+
if file["name"] == f"{self.chan}/binary-{self.arch}/{self.PACKAGES_FILE}":
|
|
361
|
+
return file
|
|
362
|
+
|
|
363
|
+
raise RuntimeError("Failed to find Packages metadata")
|
|
364
|
+
|
|
365
|
+
@property
|
|
366
|
+
def packages_url(self) -> str:
|
|
367
|
+
"""
|
|
368
|
+
The URL from which to download the Packages file.
|
|
369
|
+
|
|
370
|
+
:return: Packages file URL
|
|
371
|
+
:rtype: str
|
|
372
|
+
"""
|
|
373
|
+
|
|
374
|
+
return f"{self.DOWNLOAD_HOST}/debian/pbs-client/dists/{self.dist}/{self.chan}/binary-{self.arch}/{self.PACKAGES_FILE}"
|
|
375
|
+
|
|
376
|
+
def validate_deb(self, content: bytes) -> None:
|
|
377
|
+
"""
|
|
378
|
+
Validate the debian package with metadata from the Packages file.
|
|
379
|
+
|
|
380
|
+
:param content: The content of the debian package
|
|
381
|
+
:type content: bytes
|
|
382
|
+
|
|
383
|
+
:raises RuntimeError: if file size or digest mismatch
|
|
384
|
+
"""
|
|
385
|
+
|
|
386
|
+
expected = int(self.deb_meta["size"])
|
|
387
|
+
actual = len(content)
|
|
388
|
+
if actual != expected:
|
|
389
|
+
raise RuntimeError(f"Expected deb file to be {expected} bytes, got {actual}")
|
|
390
|
+
|
|
391
|
+
expected = self.deb_meta["sha256"]
|
|
392
|
+
actual = sha256(content).hexdigest()
|
|
393
|
+
if actual != expected:
|
|
394
|
+
raise RuntimeError(f"Expected deb file to have sha256 digest {expected}, got {actual}")
|
|
395
|
+
|
|
396
|
+
def validate_inrelease(self, content: bytes) -> None:
|
|
397
|
+
"""
|
|
398
|
+
Validate the GPG signature of the InRelease file.
|
|
399
|
+
|
|
400
|
+
:param content: The content of the InRelease file
|
|
401
|
+
:type content: bytes
|
|
402
|
+
"""
|
|
403
|
+
|
|
404
|
+
with TemporaryDirectory() as tmp_dir:
|
|
405
|
+
tmp_path = Path(tmp_dir)
|
|
406
|
+
|
|
407
|
+
key_path = tmp_path / self.key_file
|
|
408
|
+
with open(key_path, "wb") as f:
|
|
409
|
+
f.write(self.key_content)
|
|
410
|
+
|
|
411
|
+
inrelease_path = tmp_path / self.INRELEASE_FILE
|
|
412
|
+
with open(inrelease_path, "wb") as f:
|
|
413
|
+
f.write(content)
|
|
414
|
+
|
|
415
|
+
run(
|
|
416
|
+
["gpgv", "--keyring", key_path, inrelease_path],
|
|
417
|
+
check=True,
|
|
418
|
+
capture_output=True,
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
def validate_packages(self, content: bytes) -> None:
|
|
422
|
+
"""
|
|
423
|
+
Validate Packages file with metadata from InRelease file.
|
|
424
|
+
|
|
425
|
+
:param content: The contents of the Packages file
|
|
426
|
+
:type content: bytes
|
|
427
|
+
|
|
428
|
+
:raises RuntimeError: if file size or digest mismatch
|
|
429
|
+
"""
|
|
430
|
+
|
|
431
|
+
expected = int(self.packages_meta["size"])
|
|
432
|
+
actual = len(content)
|
|
433
|
+
if actual != expected:
|
|
434
|
+
raise RuntimeError(f"Expected Packages file to be {expected} bytes, got {actual}")
|
|
435
|
+
|
|
436
|
+
expected = self.packages_meta["sha256"]
|
|
437
|
+
actual = sha256(content).hexdigest()
|
|
438
|
+
if actual != expected:
|
|
439
|
+
raise RuntimeError(
|
|
440
|
+
f"Expected Packages file to have sha256 digest {expected}, got {actual}"
|
|
441
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from argparse import ArgumentParser
|
|
2
|
+
|
|
3
|
+
from proxmox_backup_client_installer.defaults import ARCH, CHAN, DIST, PREFIX
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Parser(ArgumentParser):
|
|
7
|
+
"""Subclass of ArgumentParser with arguments pre-set"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, **args) -> None:
|
|
10
|
+
super().__init__(
|
|
11
|
+
prog="proxmox-backup-client-installer",
|
|
12
|
+
description="Install proxmox-backup-client on non-Debian platforms",
|
|
13
|
+
**args,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
self.add_argument(
|
|
17
|
+
"-a",
|
|
18
|
+
"--arch",
|
|
19
|
+
choices=["amd64", "arm64"],
|
|
20
|
+
default=ARCH,
|
|
21
|
+
help="The processor architecture of the package to download",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
self.add_argument(
|
|
25
|
+
"-c",
|
|
26
|
+
"--chan",
|
|
27
|
+
choices=["main", "test"],
|
|
28
|
+
default=CHAN,
|
|
29
|
+
help="The release channel from which to download the package",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
self.add_argument(
|
|
33
|
+
"-C",
|
|
34
|
+
"--check",
|
|
35
|
+
action="store_true",
|
|
36
|
+
help="Check for a newer version of proxmox-backup-client",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
self.add_argument(
|
|
40
|
+
"-d",
|
|
41
|
+
"--dist",
|
|
42
|
+
default=DIST,
|
|
43
|
+
help="The Debian distribution from which to download the package",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
self.add_argument(
|
|
47
|
+
"-p",
|
|
48
|
+
"--prefix",
|
|
49
|
+
default=PREFIX,
|
|
50
|
+
help="The filesystem directory under which files should be installed",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
self.add_argument(
|
|
54
|
+
"-v",
|
|
55
|
+
"--version",
|
|
56
|
+
action="store_true",
|
|
57
|
+
help="Print the version of proxmox-backup-client-installer",
|
|
58
|
+
)
|