From c479f58e75c839686f6597d2ac86192d7ef23c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Stucke?= Date: Fri, 3 Feb 2023 12:38:45 +0100 Subject: [PATCH] requested review changes --- fact_extractor/helperFunctions/install.py | 17 +++++++++-------- fact_extractor/install.py | 19 +++++++------------ fact_extractor/install/unpacker.py | 4 ++-- .../plugins/unpacking/sevenz/install.sh | 4 +++- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/fact_extractor/helperFunctions/install.py b/fact_extractor/helperFunctions/install.py index 12a12365..819eb98f 100644 --- a/fact_extractor/helperFunctions/install.py +++ b/fact_extractor/helperFunctions/install.py @@ -38,7 +38,7 @@ def _remove_folder(folder_name): logging.debug(f'Falling back on root permission for deleting {folder_name}') execute_shell_command_get_return_code(f'sudo rm -rf {folder_name}') except Exception as exception: - raise InstallationError(exception) + raise InstallationError(exception) from exception def log_current_packages(packages, install=True): @@ -46,9 +46,9 @@ def log_current_packages(packages, install=True): logging.info(f'{action} {" ".join(packages)}') -def run_shell_command_raise_on_return_code( +def run_shell_command_raise_on_return_code( # pylint: disable=invalid-name command: str, error: str, add_output_on_error=False -) -> str: # pylint: disable=invalid-name +) -> str: output, return_code = execute_shell_command_get_return_code(command) if return_code != 0: if add_output_on_error: @@ -79,7 +79,7 @@ def apt_clean_system(): def apt_install_packages(*args): if not args: - return + return None log_current_packages(args) return run_shell_command_raise_on_return_code( @@ -89,7 +89,7 @@ def apt_install_packages(*args): def apt_remove_packages(*args): if not args: - return + return None log_current_packages(args, install=False) return run_shell_command_raise_on_return_code( @@ -162,9 +162,10 @@ def is_virtualenv() -> bool: return sys.prefix != getattr(sys, 'base_prefix', getattr(sys, 'real_prefix', None)) -def gcc_is_new() -> bool: +def check_gcc_major_version_at_least(version: int) -> bool: try: - output = run(split('gcc --version'), text=True, capture_output=True).stdout - return int(output.splitlines()[0].split(' ')[-1].split('.')[0]) >= 10 + output = run(split('gcc -dumpversion'), text=True, capture_output=True, check=False).stdout + major_version = int(output.strip().split('.')[0]) + return major_version >= version except ValueError: return False diff --git a/fact_extractor/install.py b/fact_extractor/install.py index 01eb6434..a19df4d6 100755 --- a/fact_extractor/install.py +++ b/fact_extractor/install.py @@ -39,13 +39,12 @@ # Compatible Ubuntu releases BIONIC_CODE_NAMES = ['bionic', 'tara', 'tessa', 'tina', 'disco'] -XENIAL_CODE_NAMES = ['xenial', 'yakkety', 'sarah', 'serena', 'sonya', 'sylvia'] FOCAL_CODE_NAMES = ['focal', 'ulyana', 'uma', 'una'] JAMMY_CODE_NAMES = ['jammy', 'vanessa'] # Compatible Debian/Kali releases -BUSTER_CODE_NAMES = ['buster', 'stretch', 'kali-rolling'] -BULLSEYE_CODE_NAMES = ['bullseye'] +BUSTER_CODE_NAMES = ['buster', 'stretch'] +BULLSEYE_CODE_NAMES = ['bullseye', 'kali-rolling'] def _setup_argparser(): @@ -68,16 +67,12 @@ def _setup_logging(debug_flag=False): def check_python_version(): - if sys.version_info.major != 3 or sys.version_info.minor < 6: - sys.exit(f'Error: Incompatible Python version! You need at least version 3.6! Your Version: {sys.version}') + if sys.version_info.major != 3 or sys.version_info.minor < 7: + sys.exit(f'Error: Incompatible Python version! You need at least version 3.7! Your Version: {sys.version}') def check_distribution(): codename = distro.codename().lower() - if codename in XENIAL_CODE_NAMES: - logging.debug('Ubuntu 16.04 detected') - logging.warning('Ubuntu 16.04 is no longer supported') - return 'xenial' if codename in BIONIC_CODE_NAMES: logging.debug('Ubuntu 18.04 detected') return 'bionic' @@ -88,14 +83,14 @@ def check_distribution(): logging.debug('Ubuntu 22.04 detected') return 'jammy' if codename in BUSTER_CODE_NAMES: - logging.debug('Debian 10/Kali detected') + logging.debug('Debian 10 detected') return 'buster' if codename in BULLSEYE_CODE_NAMES: - logging.debug('Debian 11 detected') + logging.debug('Debian 11/Kali detected') return 'bullseye' sys.exit( f'Your Distribution ({distro.id()} {distro.version()}) is not supported. ' - f'FACT Extractor Installer requires Ubuntu 18.04, 20.04, 22.04 or compatible!' + f'FACT Extractor Installer requires Ubuntu 18.04/20.04/22.04, Debian 9/10, Kali or compatible!' ) diff --git a/fact_extractor/install/unpacker.py b/fact_extractor/install/unpacker.py index 8397dfca..f740089e 100644 --- a/fact_extractor/install/unpacker.py +++ b/fact_extractor/install/unpacker.py @@ -8,7 +8,7 @@ from helperFunctions.install import ( apt_install_packages, - gcc_is_new, + check_gcc_major_version_at_least, install_github_project, InstallationError, OperateInDirectory, @@ -17,7 +17,7 @@ BIN_DIR = Path(__file__).parent.parent / 'bin' -CFLAGS = '-fcommon' if gcc_is_new() else '' +CFLAGS = '-fcommon' if check_gcc_major_version_at_least(10) else '' DEPENDENCIES = { # Ubuntu 'bionic': { diff --git a/fact_extractor/plugins/unpacking/sevenz/install.sh b/fact_extractor/plugins/unpacking/sevenz/install.sh index c43c161a..736e3ed2 100755 --- a/fact_extractor/plugins/unpacking/sevenz/install.sh +++ b/fact_extractor/plugins/unpacking/sevenz/install.sh @@ -11,10 +11,12 @@ echo "------------------------------------" # install newest version of p7zip sudo apt-get remove -y p7zip-full -mkdir /tmp/fact_build || : +mkdir -p /tmp/fact_build cd /tmp/fact_build wget -O 7zip.tar.bz2 https://sourceforge.net/projects/p7zip/files/latest/download +# remove possible artifacts from previous installation (: == NOP) +rm -rf ./p7zip* || : tar xvjf 7zip.tar.bz2 cd p7zip* # gcc >= 11 has -Wnarrowing as default flag which leads to an error during compilation