这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions src/helperFunctions/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def log_current_packages(packages: tuple[str], install: bool = True):
:param install: Identifier to distinguish installation from removal.
"""
action = 'Installing' if install else 'Removing'
logging.info(f"{action} {' '.join(packages)}")
logging.info(f'{action} {" ".join(packages)}')


def _run_shell_command_raise_on_return_code(command: str, error: str, add_output_on_error=False) -> str:
Expand All @@ -93,7 +93,7 @@ def dnf_install_packages(*packages: str):
"""
log_current_packages(packages)
return _run_shell_command_raise_on_return_code(
f"sudo dnf install -y {' '.join(packages)}", f"Error in installation of package(s) {' '.join(packages)}", True
f'sudo dnf install -y {" ".join(packages)}', f'Error in installation of package(s) {" ".join(packages)}', True
)


Expand All @@ -105,7 +105,7 @@ def dnf_remove_packages(*packages: str):
"""
log_current_packages(packages, install=False)
return _run_shell_command_raise_on_return_code(
f"sudo dnf remove -y {' '.join(packages)}", f"Error in removal of package(s) {' '.join(packages)}", True
f'sudo dnf remove -y {" ".join(packages)}', f'Error in removal of package(s) {" ".join(packages)}', True
)


Expand All @@ -126,8 +126,8 @@ def apt_install_packages(*packages: str):
"""
log_current_packages(packages)
return _run_shell_command_raise_on_return_code(
f"sudo apt-get install -y {' '.join(packages)}",
f"Error in installation of package(s) {' '.join(packages)}",
f'sudo apt-get install -y {" ".join(packages)}',
f'Error in installation of package(s) {" ".join(packages)}',
True,
)

Expand All @@ -140,7 +140,7 @@ def apt_remove_packages(*packages: str):
"""
log_current_packages(packages, install=False)
return _run_shell_command_raise_on_return_code(
f"sudo apt-get remove -y {' '.join(packages)}", f"Error in removal of package(s) {' '.join(packages)}", True
f'sudo apt-get remove -y {" ".join(packages)}', f'Error in removal of package(s) {" ".join(packages)}', True
)


Expand Down Expand Up @@ -227,35 +227,25 @@ def check_distribution(allow_unsupported=False):

:return: The codename of the distribution
"""
debian_code_names = ['buster', 'stretch', 'bullseye', 'bookworm', 'trixie', 'kali-rolling']
focal_code_names = ['focal', 'ulyana', 'ulyssa', 'uma', 'una']
jammy_code_names = ['jammy', 'vanessa', 'vera', 'victoria', 'virginia']
noble_code_names = ['noble', 'wilma', 'xia', 'zara']

codename = distro.codename().lower()
if codename in focal_code_names:
logging.debug('Ubuntu 20.04 detected')
logging.warning('Ubuntu 20.04 has reached its end of life and is no longer supported.')
return 'focal'
if codename in jammy_code_names:
logging.debug('Ubuntu 22.04 detected')
return 'jammy'
if codename in noble_code_names:
logging.debug('Ubuntu 24.04 detected')
return 'noble'
if codename in debian_code_names:
logging.debug('Debian/Kali detected')
distro_data = distro.os_release_info()
codename = distro_data.get(
'ubuntu_codename',
distro_data.get('debian_codename', distro_data.get('codename', distro_data.get('version_codename', ''))),
).lower()
logging.debug(f'found distribution: {distro_data["pretty_name"]} (codename: {codename})')
supported_codenames = {'jammy', 'noble', 'bookworm', 'trixie', 'kali-rolling'}
if codename in supported_codenames:
if codename == 'kali-rolling':
return 'bookworm'
return codename
if distro.id() == 'fedora':
logging.debug('Fedora detected')
return 'fedora'

msg = (
f'Your Distribution ({distro.id()} {distro.version()}) is not supported. '
f'Your Distribution ({distro_data["pretty_name"]} is either deprecated or not supported. '
'FACT Installer requires Ubuntu 22.04/24.04, Debian 12 or compatible!'
)
if allow_unsupported:
logging.info(msg)
return None
return codename
logging.critical(msg)
sys.exit(1)

Expand Down
8 changes: 4 additions & 4 deletions src/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ def install():

def install_fact_components(args, distribution, none_chosen, skip_docker):
if (args.common or args.frontend or args.backend or none_chosen) and not args.no_common:
common(distribution)
common()
if args.db or none_chosen:
db()
db(distribution)
if args.frontend or none_chosen:
frontend(skip_docker, not args.no_radare, args.nginx, distribution, args.no_hasura)
frontend(skip_docker, not args.no_radare, args.nginx, args.no_hasura)
if args.backend or none_chosen:
backend(skip_docker, distribution)
backend(skip_docker)


def install_docker_images(args):
Expand Down
13 changes: 7 additions & 6 deletions src/install/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from shlex import split
from subprocess import PIPE, STDOUT

import distro
from compile_yara_signatures import main as compile_signatures

import config
Expand All @@ -28,8 +29,8 @@
PIP_DEPENDENCIES = INSTALL_DIR / 'requirements_backend.txt'


def main(skip_docker, distribution):
if distribution != 'fedora':
def main(skip_docker):
if distro.id() != 'fedora':
pkgs = read_package_list_from_file(INSTALL_DIR / 'apt-pkgs-backend.txt')
apt_install_packages(*pkgs)
else:
Expand All @@ -47,7 +48,7 @@ def main(skip_docker, distribution):
_install_docker_images()

# install plug-in dependencies
_install_plugins(distribution, skip_docker)
_install_plugins(skip_docker)

# create directories
_create_firmware_directory()
Expand Down Expand Up @@ -86,7 +87,7 @@ def _install_docker_images():
def install_plugin_docker_images():
# Distribution can be None here since it will not be used for installing
# docker images
_install_plugins(None, skip_docker=False, only_docker=True)
_install_plugins(skip_docker=False, only_docker=True)


def _create_firmware_directory():
Expand All @@ -110,7 +111,7 @@ def _create_firmware_directory():
)


def _install_plugins(distribution, skip_docker, only_docker=False):
def _install_plugins(skip_docker, only_docker=False):
installer_paths = Path(get_src_dir() + '/plugins/').glob('*/*/install.py')

for install_script in installer_paths:
Expand All @@ -119,7 +120,7 @@ def _install_plugins(distribution, skip_docker, only_docker=False):

plugin = importlib.import_module(f'plugins.{plugin_type}.{plugin_name}.install')

plugin_installer = plugin.Installer(distribution, skip_docker=skip_docker)
plugin_installer = plugin.Installer(skip_docker=skip_docker)
logging.info(f'Installing {plugin_name} plugin.')
if not only_docker:
plugin_installer.install()
Expand Down
13 changes: 7 additions & 6 deletions src/install/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from platform import python_version_tuple
from subprocess import PIPE, STDOUT

import distro
from pkg_resources import parse_version

from helperFunctions.install import (
Expand Down Expand Up @@ -40,16 +41,16 @@ def install_pip():
raise InstallationError(f'Error in pip installation for python3:\n{cmd_process.stdout}')


def main(distribution):
_update_package_sources(distribution)
def main():
_update_package_sources()
_update_submodules()

BIN_DIR.mkdir(exist_ok=True)

apt_packages_path = INSTALL_DIR / 'apt-pkgs-common.txt'
dnf_packages_path = INSTALL_DIR / 'dnf-pkgs-common.txt'

if distribution != 'fedora':
if distro.id() != 'fedora':
pkgs = read_package_list_from_file(apt_packages_path)
apt_install_packages(*pkgs)
else:
Expand All @@ -60,7 +61,7 @@ def main(distribution):

if not is_virtualenv():
install_pip()
elif distribution != 'fedora':
elif distro.id() != 'fedora':
run_cmd_with_logging('pip install -U pip setuptools wheel')
else:
# on fedora, extra setuptools will break some system tools like selinux ones
Expand Down Expand Up @@ -104,9 +105,9 @@ def _update_submodules():
logging.warning("FACT is not set up using git. Note that *adding submodules* won't work!!")


def _update_package_sources(distribution):
def _update_package_sources():
logging.info('Updating system')
if distribution == 'fedora':
if distro.id() == 'fedora':
dnf_update_sources()
else:
apt_update_sources()
8 changes: 4 additions & 4 deletions src/install/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
)


def install_postgres(version: int = POSTGRES_VERSION):
def install_postgres(version: int = POSTGRES_VERSION, codename: str | None = None):
# based on https://www.postgresql.org/download/linux/ubuntu/
codename = check_distribution()
codename = codename or check_distribution()
command_list = [
'sudo apt-get install -y postgresql-common',
f'sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y {codename}',
Expand Down Expand Up @@ -53,7 +53,7 @@ def get_postgres_version() -> int:
)


def main():
def main(distribution):
postgres_version: int | None = None
try:
postgres_version = get_postgres_version()
Expand All @@ -62,7 +62,7 @@ def main():
logging.info('Skipping PostgreSQL installation. Reason: Already installed.')
except (CalledProcessError, FileNotFoundError): # psql binary was not found
logging.info('Setting up PostgreSQL database')
install_postgres()
install_postgres(codename=distribution)
configure_postgres(postgres_version)

# initializing DB
Expand Down
13 changes: 7 additions & 6 deletions src/install/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from shlex import split
from subprocess import PIPE, STDOUT

import distro
from packaging.version import parse as parse_version

import config
Expand Down Expand Up @@ -67,14 +68,14 @@ def _create_directory_for_authentication():
)


def _install_nginx(distribution):
if distribution != 'fedora':
def _install_nginx():
if distro.id() != 'fedora':
apt_install_packages('nginx')
else:
dnf_install_packages('nginx')
_generate_and_install_certificate()
_configure_nginx()
if distribution == 'fedora':
if distro.id() == 'fedora':
execute_commands_and_raise_on_return_code(
[
'sudo restorecon -v /etc/nginx/fact.*',
Expand Down Expand Up @@ -191,8 +192,8 @@ def _init_hasura():
run_cmd_with_logging('python3 init_hasura.py')


def main(skip_docker, radare, nginx, distribution, skip_hasura):
if distribution != 'fedora':
def main(skip_docker, radare, nginx, skip_hasura):
if distro.id() != 'fedora':
pkgs = read_package_list_from_file(INSTALL_DIR / 'apt-pkgs-frontend.txt')
apt_install_packages(*pkgs)
else:
Expand All @@ -212,7 +213,7 @@ def main(skip_docker, radare, nginx, distribution, skip_hasura):
_create_directory_for_authentication()

if nginx:
_install_nginx(distribution)
_install_nginx()

if not skip_docker:
_install_docker_images(radare)
Expand Down
42 changes: 25 additions & 17 deletions src/install/pre_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,39 @@ sudo apt-get update
sudo apt-get -y install python3-pip git libffi-dev lsb-release

# distro and codename detection
DISTRO=$(lsb_release -is)
if [ "${DISTRO}" = "Linuxmint" ] || [ "${DISTRO}" = "Ubuntu" ]; then
DISTRO=ubuntu
elif [ "${DISTRO}" = "Kali" ] || [ "${DISTRO}" = "Debian" ]; then
DISTRO=debian
. /etc/os-release
if [ -n "${ID_LIKE}" ]; then
if [ "${ID}" = "ubuntu" ]; then
DISTRO="${ID}"
else
# ID_LIKE can contain multiple elements separated by spaces but we only want the first one
DISTRO="${ID_LIKE%% *}"
fi
else
DISTRO="${ID}"
fi

CODENAME=$(lsb_release -cs)
if [ "${CODENAME}" = "wilma" ] || [ "${CODENAME}" = "xia" ] || [ "${CODENAME}" = "zara" ]; then
CODENAME=noble
elif [ "${CODENAME}" = "vanessa" ] || [ "${CODENAME}" = "vera" ] || [ "${CODENAME}" = "victoria" ] || [ "${CODENAME}" = "virginia" ]; then
CODENAME=jammy
elif [ "${CODENAME}" = "ulyana" ] || [ "${CODENAME}" = "ulyssa" ] || [ "${CODENAME}" = "uma" ] || [ "${CODENAME}" = "una" ]; then
CODENAME=focal
if [ -z "${CODENAME}" ] && [ -n "${VERSION_CODENAME}" ]; then
CODENAME="${VERSION_CODENAME}"
fi

if [ -n "${UBUNTU_CODENAME}" ]; then
# this and DEBIAN_CODENAME are set for linux mint
CODENAME="${UBUNTU_CODENAME}"
elif [ -n "${DEBIAN_CODENAME}" ]; then
CODENAME="${DEBIAN_CODENAME}"
elif [ "${CODENAME}" = "kali-rolling" ]; then
CODENAME=bookworm
CODENAME=bookworm
elif [ -z "${CODENAME}" ]; then
echo "Could not get distribution codename. Please make sure that your distribution is compatible to ubuntu/debian."
exit 1
echo "Could not get distribution codename. Please make sure that your distribution is compatible to ubuntu/debian."
exit 1
fi

echo "detected distro ${DISTRO} and codename ${CODENAME}"

if [ "${CODENAME}" = "bionic" ] || [ "${CODENAME}" = "focal" ] || [ "${CODENAME}" = "buster" ] || [ "${CODENAME}" = "bullseye" ]; then
echo "Warning: your distribution is outdated and the installation may not work as expected. Please upgrade your OS."
supported_codenames=("jammy" "noble" "bookworm" "trixie" "kali-rolling")
if [[ ! " ${supported_codenames[*]} " =~ ${CODENAME} ]]; then
echo "Warning: your distribution is outdated or unsupported and the installation may not work as expected."
fi

# docker installation (source: https://docs.docker.com/engine/install/{ubuntu|debian})
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/analysis/architecture_detection/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from pathlib import Path

try:
from helperFunctions.install import check_distribution, run_cmd_with_logging
from helperFunctions.install import run_cmd_with_logging
from plugins.installer import AbstractPluginInstaller
except ImportError:
import sys

SRC_PATH = Path(__file__).absolute().parent.parent.parent.parent
sys.path.append(str(SRC_PATH))

from helperFunctions.install import check_distribution, run_cmd_with_logging
from helperFunctions.install import run_cmd_with_logging
from plugins.installer import AbstractPluginInstaller


Expand All @@ -28,6 +28,4 @@ def install_docker_images(self):

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
distribution = check_distribution()
installer = Installer(distribution)
installer.install()
Installer().install()
Loading