mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 00:31:56 -06:00
Add install/remove package helpers to advise
The smart card advise scripts assume that yum is installed. However Fedora has dnf and the yum wrapper is not installed by default. Installation and removal of packages is now provided by two helper methods that detect the package manager. Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
parent
f0e11dac2d
commit
f330c59dd8
@ -227,6 +227,7 @@ class _AdviceOutput:
|
||||
self.content = []
|
||||
self.prefix = '# '
|
||||
self.options = None
|
||||
self.pkgmgr_detected = False
|
||||
self._indentation_tracker = _IndentationTracker(
|
||||
spaces_per_indent=DEFAULT_INDENTATION_INCREMENT)
|
||||
|
||||
@ -312,6 +313,41 @@ class _AdviceOutput:
|
||||
|
||||
self.command('exit 1')
|
||||
|
||||
def detect_pkgmgr(self):
|
||||
self.commands_on_predicate(
|
||||
'which yum >/dev/null',
|
||||
commands_to_run_when_true=['PKGMGR=yum'],
|
||||
commands_to_run_when_false=['PKGMGR=dnf']
|
||||
)
|
||||
self.pkgmgr_detected = True
|
||||
|
||||
def install_packages(self, names, error_message_lines):
|
||||
assert isinstance(names, list)
|
||||
self.detect_pkgmgr()
|
||||
self.command('rpm -qi {} > /dev/null'.format(' '.join(names)))
|
||||
self.commands_on_predicate(
|
||||
'[ "$?" -ne "0" ]',
|
||||
['$PKGMGR install -y {}'.format(' '.join(names))]
|
||||
)
|
||||
self.exit_on_predicate(
|
||||
'[ "$?" -ne "0" ]',
|
||||
error_message_lines
|
||||
)
|
||||
|
||||
def remove_package(self, name, error_message_lines):
|
||||
# remove only supports one package name
|
||||
assert ' ' not in name
|
||||
self.detect_pkgmgr()
|
||||
self.command('rpm -qi {} > /dev/null'.format(name))
|
||||
self.commands_on_predicate(
|
||||
'[ "$?" -eq "0" ]',
|
||||
['$PKGMGR remove -y {} || exit 1'.format(name)]
|
||||
)
|
||||
self.exit_on_predicate(
|
||||
'[ "$?" -ne "0" ]',
|
||||
error_message_lines
|
||||
)
|
||||
|
||||
@contextmanager
|
||||
def unbranched_if(self, predicate):
|
||||
with self._compound_statement(UnbranchedIfStatement, predicate):
|
||||
|
@ -135,9 +135,10 @@ class config_server_for_smart_card_auth(common_smart_card_auth_config):
|
||||
|
||||
self.log.comment('make sure bind-utils are installed so that we can '
|
||||
'dig for ipa-ca records')
|
||||
self.log.exit_on_failed_command(
|
||||
'yum install -y bind-utils',
|
||||
['Failed to install bind-utils'])
|
||||
self.log.install_packages(
|
||||
['bind-utils'],
|
||||
['Failed to install bind-utils']
|
||||
)
|
||||
|
||||
self.log.comment('make sure ipa-ca records are resolvable, '
|
||||
'otherwise error out and instruct')
|
||||
@ -272,26 +273,23 @@ class config_client_for_smart_card_auth(common_smart_card_auth_config):
|
||||
self.restart_sssd()
|
||||
|
||||
def check_and_remove_pam_pkcs11(self):
|
||||
self.log.command('rpm -qi pam_pkcs11 > /dev/null')
|
||||
self.log.commands_on_predicate(
|
||||
'[ "$?" -eq "0" ]',
|
||||
[
|
||||
'yum remove -y pam_pkcs11'
|
||||
]
|
||||
self.log.remove_package(
|
||||
'pam_pkcs11',
|
||||
['Could not remove pam_pkcs11 package']
|
||||
)
|
||||
|
||||
def install_opensc_and_dconf_packages(self):
|
||||
self.log.comment(
|
||||
'authconfig often complains about missing dconf, '
|
||||
'install it explicitly')
|
||||
self.log.exit_on_failed_command(
|
||||
'yum install -y {} dconf'.format(self.opensc_module_name.lower()),
|
||||
self.log.install_packages(
|
||||
[self.opensc_module_name.lower(), 'dconf'],
|
||||
['Could not install OpenSC package']
|
||||
)
|
||||
|
||||
def install_krb5_client_dependencies(self):
|
||||
self.log.exit_on_failed_command(
|
||||
'yum install -y krb5-pkinit-openssl',
|
||||
self.log.install_packages(
|
||||
['krb5-pkinit-openssl'],
|
||||
['Failed to install Kerberos client PKINIT extensions.']
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user