Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ def _verify_service_stop(self, offline: bool, skip_ntp: bool, skip_wkd: bool) ->
while self._service_state('archlinux-keyring-wkd-sync.service') not in ('dead', 'failed', 'exited'):
time.sleep(1)

if self._service_state('archlinux-keyring-wkd-sync.service') == 'failed':
warn('archlinux-keyring-wkd-sync failed, keyring may need reinit during pacman sync')

def _verify_boot_part(self) -> None:
"""
Check that mounted /boot device has at minimum size for installation
Expand Down
48 changes: 39 additions & 9 deletions archinstall/lib/pacman/pacman.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pathlib import Path

from archinstall.lib.command import SysCommand
from archinstall.lib.exceptions import RequirementError
from archinstall.lib.log import error, info, warn
from archinstall.lib.exceptions import RequirementError, SysCallError
from archinstall.lib.log import debug, error, info, warn
from archinstall.lib.pathnames import PACMAN_CONF
from archinstall.lib.plugins import plugins
from archinstall.lib.translationhandler import tr
Expand Down Expand Up @@ -53,15 +53,45 @@ def ask(self, error_message: str, bail_message: str, func: Callable, *args, **kw
def sync(self) -> None:
if self.synced:
return
self.ask(
'Could not sync a new package database',
'Could not sync mirrors',
self.run,
'-Syy',
default_cmd='pacman',
)

try:
self.run('-Syy')
except SysCallError as err:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be simplified to

def sync(self) -> None:
		if self.synced:
			return

		try:
			self.run('-Syy')
		except SysCallError as err:
			if b'GPGME' in err.worker_log or b'keyring' in err.worker_log.lower():
				warn('Pacman sync failed with keyring error, attempting keyring reinit')
				self._reinit_keyring()
				msg = 'Could not sync a new package database after keyring reinit'
			else:
				msg = 'Could not sync a new package database'

			self.ask(msg, 'Could not sync mirrors', self.run, '-Syy', default_cmd='pacman')

		self.synced = True

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if b'GPGME' in err.worker_log or b'keyring' in err.worker_log.lower():
warn('Pacman sync failed with keyring error, attempting keyring reinit')
self._reinit_keyring()
msg = 'Could not sync a new package database after keyring reinit'
else:
msg = 'Could not sync a new package database'

self.ask(msg, 'Could not sync mirrors', self.run, '-Syy')

self.synced = True

@staticmethod
def _is_running(process: str) -> bool:
try:
SysCommand(f'pgrep -x {process}')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that gpg-agent is a systemd service we can use systemctl rather

	def _is_running() -> bool:
	return os.system('systemctl is-active --quiet gpg-agent.service') == 0 

Maybe even put that into the utils https://github.com/archlinux/archinstall/blob/af2120c0e94ada1bb7e9eea44283d19323ce2f27/archinstall/lib/utils/util.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on systemctl, that's cleaner and I see we already do exactly this for espeakup.

One thing I'm unsure about though: in the live ISO, gpg-agent is usually spawned on-demand by gpg/pacman-key rather than started as a systemd service, so systemctl is-active --quiet gpg-agent.service might report it inactive even while the process is actually running. In that case we'd skip the killall, and that's the one spot where killing it matters (a stale agent holding the old /etc/pacman.d/gnupg open before --init). pgrep catches the process directly regardless of how it was started, which is why I reached for it.

That said, I might be overthinking the ISO behavior here. Have you actually seen gpg-agent show up as an active unit in that context? If so I'm happy to switch to systemctl, otherwise maybe pgrep is the safer bet. What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, it seeems to run as a process not as a service
image

return True
except SysCallError:
debug(f'{process} is not running')
return False

@staticmethod
def _reinit_keyring() -> None:
if Pacman._is_running('gpg-agent'):
try:
SysCommand('killall gpg-agent')
except SysCallError as err:
debug(f'Failed to kill gpg-agent: {err}')

try:
SysCommand('pacman-key --init')
SysCommand('pacman-key --populate archlinux')
debug('Keyring reinitialized successfully')
except SysCallError as err:
debug(f'Keyring reinit failed: {err}')

def strap(self, packages: str | list[str]) -> None:
self.sync()
if isinstance(packages, str):
Expand Down