diff --git a/CHANGELOG.md b/CHANGELOG.md index 914194b3..09bcd948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,10 +43,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - uninstall and downgrade logs are not available [#255](https://github.com/vinifmor/bauh/issues/255) - Debian + - install/upgrade: hanging when packages require manual configuration - info: crashing when the package size has unexpected symbols [#251](https://github.com/vinifmor/bauh/issues/251) - displaying wrong symbols among numbers in install/uninstall/upgrade outputs for systems without english encoding installed - removing unused packages on any type of transaction (this is the default behaviour for aptitude) - + - Flatpak - some updates not being displayed when there are new required runtimes for installed Flatpaks - not displaying new required runtimes as updates (requires Flatpak >= 1.12) diff --git a/bauh/commons/system.py b/bauh/commons/system.py index 980c898e..a3f0c3d5 100644 --- a/bauh/commons/system.py +++ b/bauh/commons/system.py @@ -71,7 +71,7 @@ class SimpleProcess: global_interpreter: bool = USE_GLOBAL_INTERPRETER, lang: Optional[str] = DEFAULT_LANG, root_password: Optional[str] = None, extra_paths: Set[str] = None, error_phrases: Set[str] = None, wrong_error_phrases: Set[str] = None, shell: bool = False, success_phrases: Set[str] = None, extra_env: Optional[Dict[str, str]] = None, - custom_user: Optional[str] = None): + custom_user: Optional[str] = None, preserve_env: Optional[Set] = None): pwdin, final_cmd = None, [] self.shell = shell @@ -80,6 +80,11 @@ class SimpleProcess: final_cmd.extend(['runuser', '-u', custom_user, '--']) elif isinstance(root_password, str): final_cmd.extend(['sudo', '-S']) + + if preserve_env: + for var in preserve_env: + final_cmd.append(f'--preserve-env={var}') + pwdin = self._new(['echo', root_password], cwd, global_interpreter, lang).stdout final_cmd.extend(cmd) diff --git a/bauh/gems/debian/aptitude.py b/bauh/gems/debian/aptitude.py index 3de2d277..e94490cf 100644 --- a/bauh/gems/debian/aptitude.py +++ b/bauh/gems/debian/aptitude.py @@ -46,7 +46,8 @@ class Aptitude: self._default_lang = '' self._ignored_fields: Optional[Set[str]] = None self._re_none: Optional[Pattern] = None - self._vars_encoding_fix: Optional[Dict[str, str]] = None + self._vars_fixes: Optional[Dict[str, str]] = None + self._preserve_env = {'DEBIAN_FRONTEND'} def show(self, pkgs: Iterable[str], attrs: Optional[Collection[str]] = None, verbose: bool = False) \ -> Optional[Dict[str, Dict[str, object]]]: @@ -129,7 +130,8 @@ class Aptitude: def upgrade(self, packages: Iterable[str], root_password: Optional[str]) -> SimpleProcess: cmd = self.gen_transaction_cmd('upgrade', packages).split(' ') - return SimpleProcess(cmd=cmd, shell=True, root_password=root_password, extra_env=self.vars_encoding_fix) + return SimpleProcess(cmd=cmd, shell=True, root_password=root_password, extra_env=self.vars_fixes, + preserve_env=self._preserve_env) def update(self, root_password: Optional[str]) -> SimpleProcess: return SimpleProcess(('aptitude', 'update'), root_password=root_password, shell=True) @@ -143,7 +145,8 @@ class Aptitude: def install(self, packages: Iterable[str], root_password: Optional[str]) -> SimpleProcess: cmd = self.gen_transaction_cmd('install', packages).split(' ') - return SimpleProcess(cmd=cmd, shell=True, root_password=root_password, extra_env=self.vars_encoding_fix) + return SimpleProcess(cmd=cmd, root_password=root_password, extra_env=self.vars_fixes, + preserve_env=self._preserve_env) def read_installed(self) -> Generator[DebianPackage, None, None]: yield from self.search(query='~i') @@ -200,7 +203,7 @@ class Aptitude: def remove(self, packages: Iterable[str], root_password: Optional[str], purge: bool = False) -> SimpleProcess: return SimpleProcess(cmd=self.gen_remove_cmd(packages, purge).split(' '), shell=True, - root_password=root_password, extra_env=self.vars_encoding_fix) + root_password=root_password, extra_env=self.vars_fixes, preserve_env=self._preserve_env) def read_installed_names(self) -> Generator[str, None, None]: code, output = system.execute("aptitude search ~i -q -F '%p' --disable-columns", @@ -279,11 +282,11 @@ class Aptitude: return self._re_none @property - def vars_encoding_fix(self) -> Dict[str, str]: - if self._vars_encoding_fix is None: - self._vars_encoding_fix = {'LC_NUMERIC': ''} + def vars_fixes(self) -> Dict[str, str]: + if self._vars_fixes is None: + self._vars_fixes = {'LC_NUMERIC': '', 'DEBIAN_FRONTEND': 'noninteractive'} - return self._vars_encoding_fix + return self._vars_fixes class AptitudeOutputHandler(Thread):