|
9 | 9 | # |
10 | 10 | # The above copyright notice and this permission notice shall be included in |
11 | 11 | # all copies or substantial portions of the Software. |
| 12 | +import glob |
12 | 13 | import logging |
13 | 14 | import os |
14 | 15 | import re |
15 | 16 | import shlex |
16 | 17 | import subprocess |
17 | 18 | import sys |
18 | 19 | from pathlib import Path |
| 20 | +from tempfile import TemporaryDirectory |
19 | 21 |
|
20 | 22 | from appimagebuilder.common import shell |
21 | 23 |
|
22 | | -DEPENDS_ON = ["bsdtar", "pacman", "pacman-key", "fakeroot"] |
| 24 | +DEPENDS_ON = ["bsdtar", "pacman", "pacman-key", "fakeroot", "gpg-agent"] |
23 | 25 |
|
24 | 26 |
|
25 | 27 | class PacmanVenvError(RuntimeError): |
@@ -160,11 +162,33 @@ def _generate_config(self): |
160 | 162 | f.write("Server = %s\n" % server) |
161 | 163 |
|
162 | 164 | def _configure_keyring(self): |
163 | | - self._run_command("{fakeroot} {pacman-key} --config {config} --init") |
164 | | - self._run_command( |
165 | | - "{fakeroot} {pacman-key} --config {config} --populate archlinux" |
| 165 | + keyrings = list( |
| 166 | + map( |
| 167 | + lambda x: x.split('.gpg')[0], |
| 168 | + [os.path.basename(x) for x in glob.glob('/usr/share/pacman/keyrings/*.gpg')] |
| 169 | + ) |
166 | 170 | ) |
167 | 171 |
|
| 172 | + with TemporaryDirectory(prefix="appimage-builder.") as temp_dir: |
| 173 | + temp_gnupg_dir = str(Path(temp_dir) / 'gnupg') |
| 174 | + |
| 175 | + os.symlink(self._gpg_dir.absolute(), temp_gnupg_dir, target_is_directory=True) |
| 176 | + |
| 177 | + proc_gpgagent = self._run_command( |
| 178 | + "{fakeroot} {gpg-agent} --homedir" |
| 179 | + f" {temp_gnupg_dir}" |
| 180 | + " --daemon", |
| 181 | + assert_success=False, |
| 182 | + wait_for_completion=False |
| 183 | + ) |
| 184 | + self._run_command("{fakeroot} {pacman-key} --config {config} --init") |
| 185 | + self._run_command( |
| 186 | + "{fakeroot} {pacman-key} --config {config} --populate " |
| 187 | + f"{' '.join(keyrings)}" |
| 188 | + ) |
| 189 | + |
| 190 | + proc_gpgagent.terminate() |
| 191 | + |
168 | 192 | def _run_command( |
169 | 193 | self, |
170 | 194 | command, |
|
0 commit comments