Skip to content

Commit

Permalink
requested review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Feb 3, 2023

Unverified

This user has not yet uploaded their public signing key.
1 parent 522c155 commit c479f58
Showing 4 changed files with 21 additions and 23 deletions.
17 changes: 9 additions & 8 deletions fact_extractor/helperFunctions/install.py
Original file line number Diff line number Diff line change
@@ -38,17 +38,17 @@ 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):
action = 'Installing' if install else 'Removing'
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
19 changes: 7 additions & 12 deletions fact_extractor/install.py
Original file line number Diff line number Diff line change
@@ -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!'
)


4 changes: 2 additions & 2 deletions fact_extractor/install/unpacker.py
Original file line number Diff line number Diff line change
@@ -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': {
4 changes: 3 additions & 1 deletion fact_extractor/plugins/unpacking/sevenz/install.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c479f58

Please sign in to comment.