diff --git a/src/decman/config.py b/src/decman/config.py index 9427e94..8cc4983 100644 --- a/src/decman/config.py +++ b/src/decman/config.py @@ -45,7 +45,7 @@ class Commands: """ 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]: """ @@ -97,17 +97,21 @@ class Commands: """ 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. """ - 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. """ - return ["systemctl", "disable", "--quiet"] + units + return ["systemctl", "--quiet", "--user", "-M", f"{user}@", "disable" + ] + units def compare_versions(self, installed_version: str, new_version: str) -> list[str]: diff --git a/src/decman/lib/__init__.py b/src/decman/lib/__init__.py index 37532ff..f42a313 100644 --- a/src/decman/lib/__init__.py +++ b/src/decman/lib/__init__.py @@ -738,6 +738,8 @@ class Pacman: try: 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: raise err.UserFacingError( "Failed to install packages using pacman.") from error @@ -849,20 +851,11 @@ class Systemd: if not units: return - try: - uid = pwd.getpwnam(user).pw_uid - gid = pwd.getpwnam(user).pw_gid - - with subprocess.Popen(conf.commands.enable_user_units(units), - 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 + with subprocess.Popen(conf.commands.enable_user_units( + units, user)) as process: + if process.wait() != 0: + raise err.UserFacingError( + f"Failed to enable systemd units: {units} for {user}.") for unit in units: self.state.add_enabled_user_systemd_unit(user, unit) @@ -873,21 +866,10 @@ class Systemd: if not units: return - try: - uid = pwd.getpwnam(user).pw_uid - gid = pwd.getpwnam(user).pw_gid - - with subprocess.Popen(conf.commands.disable_user_units(units), - 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 - + with subprocess.Popen(conf.commands.disable_user_units( + units, user)) as process: + if process.wait() != 0: + raise err.UserFacingError( + f"Failed to disable systemd units: {units} for {user}.") for unit in units: self.state.remove_enabled_user_systemd_unit(user, unit)