Skip to content

Commit

Permalink
Merge pull request #865 from HoxhaEndri/master
Browse files Browse the repository at this point in the history
braces checked for all script files
  • Loading branch information
m-1-k-3 committed Nov 6, 2023
2 parents e368a68 + d43a43d commit 9904576
Show file tree
Hide file tree
Showing 11 changed files with 456 additions and 456 deletions.
2 changes: 1 addition & 1 deletion helpers/helpers_emba_dependency_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ dependency_check()
check_dep_file "sudo-parser script" "${EXT_DIR}""/sudo-parser.pl"

# BMC firmware decryptor - https://github.com/c0d3z3r0/smcbmc
check_dep_file "BMC decryptor" "$EXT_DIR""/smcbmc/smcbmc.py"
check_dep_file "BMC decryptor" "${EXT_DIR}""/smcbmc/smcbmc.py"

# sh3llcheck - I know it's a typo, but this particular tool nags about it
check_dep_tool "shellcheck script" "shellcheck"
Expand Down
138 changes: 69 additions & 69 deletions installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
STRICT_MODE=1

ORIG_USER="${SUDO_USER:-${USER}}"
ORIG_GROUP=$(groups "$ORIG_USER" | cut -d: -f2 | awk '{print $1}')
ORIG_GROUP=$(groups "${ORIG_USER}" | cut -d: -f2 | awk '{print $1}')

export DEBIAN_FRONTEND=noninteractive
export INSTALL_APP_LIST=()
export DOWNLOAD_FILE_LIST=()
export INSTALLER_DIR="./installer"

if [[ "$STRICT_MODE" -eq 1 ]]; then
if [[ "${STRICT_MODE}" -eq 1 ]]; then
export DEBUG_SCRIPT=0
if [[ -f "./helpers/helpers_emba_load_strict_settings.sh" ]]; then
# shellcheck source=/dev/null
Expand Down Expand Up @@ -68,58 +68,58 @@ export NC="\033[0m" # no color
## Attribute definition
export BOLD="\033[1m"

echo -e "\\n""$ORANGE""$BOLD""EMBA - Embedded Linux Analyzer Installer""$NC"
echo -e "$BOLD""=================================================================""$NC"
echo -e "\\n""${ORANGE}""${BOLD}""EMBA - Embedded Linux Analyzer Installer""${NC}"
echo -e "${BOLD}""=================================================================""${NC}"

# import all the installation modules
mapfile -t INSTALLERS < <(find "$INSTALLER_DIR" -iname "*.sh" 2> /dev/null)
mapfile -t INSTALLERS < <(find "${INSTALLER_DIR}" -iname "*.sh" 2> /dev/null)
INSTALLER_COUNT=0
for INSTALLER_FILE in "${INSTALLERS[@]}" ; do
# https://github.com/koalaman/shellcheck/wiki/SC1090
# shellcheck source=/dev/null
source "$INSTALLER_FILE"
source "${INSTALLER_FILE}"
(( INSTALLER_COUNT+=1 ))
done

echo ""
echo -e "==> ""$GREEN""Imported ""$INSTALLER_COUNT"" installer module files""$NC"
echo -e "==> ""${GREEN}""Imported ""${INSTALLER_COUNT}"" installer module files""${NC}"
echo ""

if [[ "$#" -le 1 ]] && [[ "$#" -gt 2 ]]; then
echo -e "$RED""$BOLD""Invalid number of arguments""$NC"
echo -e "${RED}""${BOLD}""Invalid number of arguments""${NC}"
echo -e "\n\n------------------------------------------------------------------"
echo -e "If you are going to install EMBA in default mode you can use:"
echo -e "$CYAN"" sudo ./installer.sh -d""$NC"
echo -e "${CYAN}"" sudo ./installer.sh -d""${NC}"
echo -e "------------------------------------------------------------------\n\n"
print_help
exit 1
fi

while getopts CdDFghlrsc: OPT ; do
case $OPT in
case ${OPT} in
d)
export DOCKER_SETUP=1
export CVE_SEARCH=0
echo -e "$GREEN""$BOLD""Install all dependecies for EMBA in default/docker mode""$NC"
echo -e "${GREEN}""${BOLD}""Install all dependecies for EMBA in default/docker mode""${NC}"
;;
D)
export IN_DOCKER=1
export DOCKER_SETUP=0
export CVE_SEARCH=0
echo -e "$GREEN""$BOLD""Install EMBA in docker image - used for building a docker image""$NC"
echo -e "${GREEN}""${BOLD}""Install EMBA in docker image - used for building a docker image""${NC}"
;;
F)
export FULL=1
export DOCKER_SETUP=0
export CVE_SEARCH=1
echo -e "$GREEN""$BOLD""Install all dependecies for developer mode""$NC"
echo -e "${GREEN}""${BOLD}""Install all dependecies for developer mode""${NC}"
;;
g)
export DOCKER_SETUP=1
export GH_ACTION=1
export CVE_SEARCH=0
echo -e "$GREEN""$BOLD""Install all dependecies for EMBA test via Github actions""$NC"
echo -e "$GREEN""$BOLD""This mode is a default installation without populating the CVE-search database""$NC"
echo -e "${GREEN}""${BOLD}""Install all dependecies for EMBA test via Github actions""${NC}"
echo -e "${GREEN}""${BOLD}""This mode is a default installation without populating the CVE-search database""${NC}"
;;
h)
print_help
Expand All @@ -129,21 +129,21 @@ while getopts CdDFghlrsc: OPT ; do
export LIST_DEP=1
export CVE_SEARCH=0
export DOCKER_SETUP=0
echo -e "$GREEN""$BOLD""List all dependecies (Warning: deprecated feature)""$NC"
echo -e "${GREEN}""${BOLD}""List all dependecies (Warning: deprecated feature)""${NC}"
;;
r)
export REMOVE=1
echo -e "$GREEN""$BOLD""Remove EMBA from the system""$NC"
echo -e "${GREEN}""${BOLD}""Remove EMBA from the system""${NC}"
;;
s)
export SSL_REPOS=1
echo -e "$GREEN""$BOLD""HTTPS repos are used for installation""$NC"
echo -e "${GREEN}""${BOLD}""HTTPS repos are used for installation""${NC}"
;;
c)
export CONTAINER="$OPTARG"
export CONTAINER="${OPTARG}"
;;
*)
echo -e "$RED""$BOLD""Invalid option""$NC"
echo -e "${RED}""${BOLD}""Invalid option""${NC}"
print_help
exit 1
;;
Expand All @@ -158,24 +158,24 @@ if ! [[ -v CONTAINER ]]; then
fi
fi

if [[ "$LIST_DEP" -eq 1 ]]; then
echo -e "\n${ORANGE}WARNING: This feature is deprecated and not maintained anymore.$NC"
if [[ "${LIST_DEP}" -eq 1 ]]; then
echo -e "\n${ORANGE}WARNING: This feature is deprecated and not maintained anymore.${NC}"
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi

# WSL support - currently experimental!
if grep -q -i wsl /proc/version; then
echo -e "\n${ORANGE}INFO: System running in WSL environment!$NC"
echo -e "\n${ORANGE}INFO: WSL is currently experimental!$NC"
echo -e "\n${ORANGE}Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites$NC"
echo -e "\n${ORANGE}WARNING: If you are using WSL2, disable docker integration from the docker-desktop daemon!$NC"
echo -e "\n${ORANGE}INFO: System running in WSL environment!${NC}"
echo -e "\n${ORANGE}INFO: WSL is currently experimental!${NC}"
echo -e "\n${ORANGE}Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites${NC}"
echo -e "\n${ORANGE}WARNING: If you are using WSL2, disable docker integration from the docker-desktop daemon!${NC}"
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
WSL=1
fi

# distribution check
if ! grep -Eq "ID(_LIKE)?=(\")?(ubuntu)?( )?(debian)?" /etc/os-release 2>/dev/null ; then
echo -e "\\n""$RED""EMBA only supports debian based distributions!""$NC\\n"
echo -e "\\n""${RED}""EMBA only supports debian based distributions!""${NC}\\n"
print_help
exit 1
elif ! grep -q "kali" /etc/debian_version 2>/dev/null ; then
Expand All @@ -184,14 +184,14 @@ elif ! grep -q "kali" /etc/debian_version 2>/dev/null ; then
OTHER_OS=1
UBUNTU_OS=1
elif grep -q "PRETTY_NAME=\"Ubuntu 20.04 LTS\"" /etc/os-release 2>/dev/null ; then
echo -e "\\n""$RED""EMBA is not fully supported on Ubuntu 20.04 LTS.""$NC"
echo -e "$RED""For EMBA installation you need to update docker-compose manually. See also https://github.com/e-m-b-a/emba/issues/247""$NC"
echo -e "\\n""$ORANGE""Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites""$NC"
echo -e "\\n""${RED}""EMBA is not fully supported on Ubuntu 20.04 LTS.""${NC}"
echo -e "${RED}""For EMBA installation you need to update docker-compose manually. See also https://github.com/e-m-b-a/emba/issues/247""${NC}"
echo -e "\\n""${ORANGE}""Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites""${NC}"
read -p "If you have updated docker-compose you can press any key to continue ..." -n1 -s -r
OTHER_OS=0 # installation procedure identical to kali install
UBUNTU_OS=0 # installation procedure identical to kali install
else
echo -e "\n${ORANGE}WARNING: compatibility of distribution/version unknown!$NC"
echo -e "\n${ORANGE}WARNING: compatibility of distribution/version unknown!${NC}"
OTHER_OS=1
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi
Expand All @@ -205,8 +205,8 @@ if ! uname -m | grep -q "x86_64" 2>/dev/null; then
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi

if ! [[ $EUID -eq 0 ]] && [[ $LIST_DEP -eq 0 ]] ; then
echo -e "\\n""$RED""Run EMBA installation script with root permissions!""$NC\\n"
if ! [[ ${EUID} -eq 0 ]] && [[ ${LIST_DEP} -eq 0 ]] ; then
echo -e "\\n""${RED}""Run EMBA installation script with root permissions!""${NC}\\n"
print_help
exit 1
fi
Expand All @@ -215,14 +215,14 @@ fi

HOME_PATH=$(pwd)

if [[ "$REMOVE" -eq 1 ]]; then
if [[ "${REMOVE}" -eq 1 ]]; then
R00_emba_remove
exit 0
fi

# quick check if we have enough disk space for the docker image

if [[ "$IN_DOCKER" -eq 0 ]]; then
if [[ "${IN_DOCKER}" -eq 0 ]]; then
if [[ -d "/var/lib/docker/" ]]; then
# docker is already installed
DDISK="/var/lib/docker"
Expand All @@ -231,41 +231,41 @@ if [[ "$IN_DOCKER" -eq 0 ]]; then
DDISK="/var/lib/"
fi

FREE_SPACE=$(df --output=avail "$DDISK" | awk 'NR==2')
if [[ "$FREE_SPACE" -lt 13000000 ]]; then
echo -e "\\n""$ORANGE""EMBA installation in default mode needs a minimum of 13Gig for the docker image""$NC"
echo -e "\\n""$ORANGE""Please free enough space on /var/lib/docker""$NC"
echo -e "\\n""$ORANGE""Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites""$NC"
FREE_SPACE=$(df --output=avail "${DDISK}" | awk 'NR==2')
if [[ "${FREE_SPACE}" -lt 13000000 ]]; then
echo -e "\\n""${ORANGE}""EMBA installation in default mode needs a minimum of 13Gig for the docker image""${NC}"
echo -e "\\n""${ORANGE}""Please free enough space on /var/lib/docker""${NC}"
echo -e "\\n""${ORANGE}""Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites""${NC}"
echo ""
df -h || true
echo ""
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi

TOTAL_MEMORY="$(grep MemTotal /proc/meminfo | awk '{print $2}' || true)"
if [[ "$TOTAL_MEMORY" -lt 4000000 ]]; then
echo -e "\\n""$ORANGE""EMBA installation in default mode needs a minimum of 4Gig of RAM""$NC"
echo -e "\\n""$ORANGE""Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites""$NC"
if [[ "${TOTAL_MEMORY}" -lt 4000000 ]]; then
echo -e "\\n""${ORANGE}""EMBA installation in default mode needs a minimum of 4Gig of RAM""${NC}"
echo -e "\\n""${ORANGE}""Please check the documentation https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites""${NC}"
echo ""
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi
fi

if [[ $LIST_DEP -eq 0 ]] ; then
if [[ ${LIST_DEP} -eq 0 ]] ; then
if ! [[ -d "external" ]] ; then
echo -e "\\n""$ORANGE""Created external directory: ./external""$NC"
echo -e "\\n""${ORANGE}""Created external directory: ./external""${NC}"
mkdir external
# currently this is needed for full install on Ubuntu
# the freetz installation is running as freetzuser and needs write access:
chown "$ORIG_USER":"$ORIG_GROUP" ./external
chown "${ORIG_USER}":"${ORIG_GROUP}" ./external
chmod 777 ./external
else
echo -e "\\n""$ORANGE""WARNING: external directory available: ./external""$NC"
echo -e "$ORANGE""Please remove it before proceeding ... exit now""$NC"
echo -e "\\n""${ORANGE}""WARNING: external directory available: ./external""${NC}"
echo -e "${ORANGE}""Please remove it before proceeding ... exit now""${NC}"
exit 1
fi

echo -e "\\n""$ORANGE""Update package lists.""$NC"
echo -e "\\n""${ORANGE}""Update package lists.""${NC}"
if [[ "${SSL_REPOS}" -eq 1 ]]; then
sed -i 's/deb http:\/\//deb https:\/\//g' /etc/apt/sources.list
sed -i 's/deb-src http:\/\//deb-src https:\/\//g' /etc/apt/sources.list
Expand All @@ -283,30 +283,30 @@ activate_pipenv "./external/emba_venv"
I01_default_apps_host

DOCKER_COMP_VER=$(docker-compose -v | grep version | tr '-' ' ' | awk '{print $4}' | tr -d ',' | sed 's/^v//')
if [[ $(version "$DOCKER_COMP_VER") -lt $(version "1.28.5") ]]; then
echo -e "\n${ORANGE}WARNING: compatibility of the used docker-compose version is unknown!$NC"
echo -e "\n${ORANGE}Please consider updating your docker-compose installation to version 1.28.5 or later.$NC"
echo -e "\n${ORANGE}Please check the EMBA wiki for further details: https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites$NC"
if [[ $(version "${DOCKER_COMP_VER}") -lt $(version "1.28.5") ]]; then
echo -e "\n${ORANGE}WARNING: compatibility of the used docker-compose version is unknown!${NC}"
echo -e "\n${ORANGE}Please consider updating your docker-compose installation to version 1.28.5 or later.${NC}"
echo -e "\n${ORANGE}Please check the EMBA wiki for further details: https://github.com/e-m-b-a/emba/wiki/Installation#prerequisites${NC}"
read -p "If you know what you are doing you can press any key to continue ..." -n1 -s -r
fi

if [[ "$OTHER_OS" -eq 1 ]]; then
if [[ "${OTHER_OS}" -eq 1 ]]; then
# UBUNTU
if [[ "$UBUNTU_OS" -eq 1 ]]; then
if [[ "${UBUNTU_OS}" -eq 1 ]]; then
ID1_ubuntu_os
fi
fi

INSTALL_APP_LIST=()

if [[ "$WSL" -eq 1 ]]; then
if [[ "${WSL}" -eq 1 ]]; then
echo "[*] Starting dockerd manually in wsl environments:"
dockerd --iptables=false &
sleep 3
reset
fi

if [[ "$CVE_SEARCH" -ne 1 ]] || [[ "$DOCKER_SETUP" -ne 1 ]] || [[ "$IN_DOCKER" -eq 1 ]]; then
if [[ "${CVE_SEARCH}" -ne 1 ]] || [[ "${DOCKER_SETUP}" -ne 1 ]] || [[ "${IN_DOCKER}" -eq 1 ]]; then

I01_default_apps

Expand Down Expand Up @@ -349,25 +349,25 @@ fi
IF20_cve_search
deactivate

cd "$HOME_PATH" || exit 1
cd "${HOME_PATH}" || exit 1

# we reset the permissions of external from 777 back to 755:
chmod 755 ./external

if [[ "$LIST_DEP" -eq 0 ]] || [[ $IN_DOCKER -eq 0 ]] || [[ $DOCKER_SETUP -eq 1 ]] || [[ $FULL -eq 1 ]]; then
echo -e "\\n""$MAGENTA""$BOLD""Installation notes:""$NC"
echo -e "\\n""$MAGENTA""INFO: The cron.daily update script for EMBA is located in config/emba_updater""$NC"
echo -e "$MAGENTA""INFO: For automatic updates it should be copied to /etc/cron.daily/""$NC"
echo -e "$MAGENTA""INFO: For manual updates just start it via sudo ./config/emba_updater""$NC"
if [[ "${LIST_DEP}" -eq 0 ]] || [[ ${IN_DOCKER} -eq 0 ]] || [[ ${DOCKER_SETUP} -eq 1 ]] || [[ ${FULL} -eq 1 ]]; then
echo -e "\\n""${MAGENTA}""${BOLD}""Installation notes:""${NC}"
echo -e "\\n""${MAGENTA}""INFO: The cron.daily update script for EMBA is located in config/emba_updater""${NC}"
echo -e "${MAGENTA}""INFO: For automatic updates it should be copied to /etc/cron.daily/""${NC}"
echo -e "${MAGENTA}""INFO: For manual updates just start it via sudo ./config/emba_updater""${NC}"

echo -e "\\n""$MAGENTA""WARNING: If you plan using the emulator (-E switch) your host and your internal network needs to be protected.""$NC"
echo -e "\\n""${MAGENTA}""WARNING: If you plan using the emulator (-E switch) your host and your internal network needs to be protected.""${NC}"

echo -e "\\n""$MAGENTA""INFO: Do not forget to checkout current development of EMBA at https://github.com/e-m-b-a.""$NC"
echo -e "\\n""${MAGENTA}""INFO: Do not forget to checkout current development of EMBA at https://github.com/e-m-b-a.""${NC}"
fi
if [[ "$WSL" -eq 1 ]]; then
echo -e "\\n""$MAGENTA""INFO: In the current WSL installation the docker and mongod services started manually!""$NC"
if [[ "${WSL}" -eq 1 ]]; then
echo -e "\\n""${MAGENTA}""INFO: In the current WSL installation the docker and mongod services started manually!""${NC}"
fi

if [[ "$LIST_DEP" -eq 0 ]]; then
echo -e "$GREEN""EMBA installation finished ""$NC"
if [[ "${LIST_DEP}" -eq 0 ]]; then
echo -e "${GREEN}""EMBA installation finished ""${NC}"
fi

0 comments on commit 9904576

Please sign in to comment.