Fix bug with installing pacman packags & systemd user units

This commit is contained in:
Kivi Kaitaniemi
2024-05-18 01:05:11 +03:00
parent 90f31ced35
commit 09c320cdad
2 changed files with 21 additions and 35 deletions
+9 -5
View File
@@ -45,7 +45,7 @@ class Commands:
""" """
Running this command installs the given packages from pacman repositories. Running this command installs the given packages from pacman repositories.
""" """
return ["pacman", "-S", "--asexplicit"] + pkgs return ["pacman", "-S", "--needed"] + pkgs
def install_files(self, pkg_files: list[str]) -> list[str]: def install_files(self, pkg_files: list[str]) -> list[str]:
""" """
@@ -97,17 +97,21 @@ class Commands:
""" """
return ["systemctl", "disable", "--quiet"] + units return ["systemctl", "disable", "--quiet"] + units
def enable_user_units(self, units: list[str]) -> list[str]: def enable_user_units(self, units: list[str], user: str) -> list[str]:
""" """
Running this command enables the given systemd units for the user it's run as. Running this command enables the given systemd units for the user it's run as.
""" """
return ["systemctl", "enable", "--now", "--quiet", "--user"] + units return [
"systemctl", "--quiet", "--user", "-M", f"{user}@", "enable",
"--now"
] + units
def disable_user_units(self, units: list[str]) -> list[str]: def disable_user_units(self, units: list[str], user: str) -> list[str]:
""" """
Running this command disables the given systemd units fol the user it's run as. Running this command disables the given systemd units fol the user it's run as.
""" """
return ["systemctl", "disable", "--quiet"] + units return ["systemctl", "--quiet", "--user", "-M", f"{user}@", "disable"
] + units
def compare_versions(self, installed_version: str, def compare_versions(self, installed_version: str,
new_version: str) -> list[str]: new_version: str) -> list[str]:
+12 -30
View File
@@ -738,6 +738,8 @@ class Pacman:
try: try:
subprocess.run(conf.commands.install_pkgs(packages), check=True) subprocess.run(conf.commands.install_pkgs(packages), check=True)
subprocess.run(conf.commands.set_as_explicitly_installed(packages),
check=True)
except subprocess.CalledProcessError as error: except subprocess.CalledProcessError as error:
raise err.UserFacingError( raise err.UserFacingError(
"Failed to install packages using pacman.") from error "Failed to install packages using pacman.") from error
@@ -849,20 +851,11 @@ class Systemd:
if not units: if not units:
return return
try: with subprocess.Popen(conf.commands.enable_user_units(
uid = pwd.getpwnam(user).pw_uid units, user)) as process:
gid = pwd.getpwnam(user).pw_gid if process.wait() != 0:
raise err.UserFacingError(
with subprocess.Popen(conf.commands.enable_user_units(units), f"Failed to enable systemd units: {units} for {user}.")
group=gid,
user=uid) as process:
if process.wait() != 0:
raise err.UserFacingError(
f"Failed to enable systemd units: {units} for {user}.")
except KeyError as error:
raise err.UserFacingError(
f"Failed to enable systemd units because user {user} doesn't exist."
) from error
for unit in units: for unit in units:
self.state.add_enabled_user_systemd_unit(user, unit) self.state.add_enabled_user_systemd_unit(user, unit)
@@ -873,21 +866,10 @@ class Systemd:
if not units: if not units:
return return
try: with subprocess.Popen(conf.commands.disable_user_units(
uid = pwd.getpwnam(user).pw_uid units, user)) as process:
gid = pwd.getpwnam(user).pw_gid if process.wait() != 0:
raise err.UserFacingError(
with subprocess.Popen(conf.commands.disable_user_units(units), f"Failed to disable systemd units: {units} for {user}.")
group=gid,
user=uid) as process:
if process.wait() != 0:
raise err.UserFacingError(
f"Failed to disable systemd units: {units} for {user}."
)
except KeyError as error:
raise err.UserFacingError(
f"Failed to disable systemd units because user {user} doesn't exist."
) from error
for unit in units: for unit in units:
self.state.remove_enabled_user_systemd_unit(user, unit) self.state.remove_enabled_user_systemd_unit(user, unit)