Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copyright and exceptions linter functions #965

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 65 additions & 1 deletion check_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# EMBA is licensed under GPLv3
#
# Author(s): Michael Messner, Pascal Eckmann
# Contributor(s): Benedikt Kuehne

# Description: Check all shell scripts inside ./helpers, ./modules, emba and itself with shellchecker

Expand Down Expand Up @@ -50,6 +51,7 @@ MODULES_TO_CHECK_ARR_DOCKER=()
MODULES_TO_CHECK_ARR_PERM=()
MODULES_TO_CHECK_ARR_COMMENT=()
MODULES_TO_CHECK_ARR_GREP=()
MODULES_TO_CHECK_ARR_COPYRIGHT=()

import_config_scripts() {
mapfile -t HELPERS < <(find "${CONF_DIR}" -iname "*.sh" 2>/dev/null)
Expand Down Expand Up @@ -311,15 +313,77 @@ check_tools() {
fi
}

list_linter_exceptions(){
# lists all linter exceptions for a given toolname inside a directory
# $1 tool name
# $2 directory
# $3 excluded dir for find
local TOOL_NAME_="${1:-}"
local DIR_="${2:-}"
local EXCLUDE_="${3:-}"
local SEARCH_PAR_=""
local SEARCH_TYPE_=""
echo -e "\\n""${GREEN}""Checking for ${TOOL_NAME_} exceptions inside ${DIR_}:""${NC}""\\n"
case "${TOOL_NAME_}" in
shellcheck)
SEARCH_PAR_="shellcheck disable"
SEARCH_TYPE_="sh"
;;
semgrep)
SEARCH_PAR_="nosemgrep"
SEARCH_TYPE_="sh"
;;
esac
mapfile -t EXCEPTION_SCRIPTS < <(find "${DIR_}" -type d -path "${EXCLUDE_}" -prune -false -o -iname "*.${SEARCH_TYPE_}" -exec grep -H "${SEARCH_PAR_}" {} \;)
if [[ "${#EXCEPTION_SCRIPTS[@]}" -gt 0 ]]; then
for EXCEPTION_ in "${EXCEPTION_SCRIPTS[@]}"; do
echo -e "\\n""${GREEN}""Found exception in ${EXCEPTION_%%:*}:""${ORANGE}""${EXCEPTION_##*:}""${NC}""\\n"
EXCEPTIONS_TO_CHECK_ARR+=( "${EXCEPTION_%%:*}" )
done
else
echo -e "\\n""${GREEN}""=> Found no exceptions for ${TOOL_NAME_}""${NC}""\\n"
fi
}

copy_right_check(){
# checks all Copyright occurences for supplied end-year
# $1 copyright holder
# $2 end-year
# $3 dir to look in
# $4 excluded dir for find
local OWNER_="${1:-}"
local YEAR_="${2:-}"
local DIR_="${3:-}"
local EXCLUDE_="${4:-}"
echo -e "\\n""${ORANGE}""${BOLD}""EMBA Copyright check""${NC}""\\n""${BOLD}""=================================================================""${NC}"
mapfile -t COPYRIGHT_LINE_ < <(find "${DIR_}" -type d -path "${EXCLUDE_}" -prune -false -o -type f -not -wholename "${0}" -iname "*.sh" -exec grep -H "Copyright" {} \;)
if [[ "${#COPYRIGHT_LINE_[@]}" -gt 0 ]]; then
for LINE_ in "${COPYRIGHT_LINE_[@]}"; do
if [[ "${LINE_##*:}" == *"${OWNER_}" && "${LINE_##*:}" != *"${YEAR_}"* ]]; then
MODULES_TO_CHECK_ARR_COPYRIGHT+=( "${LINE_%%:*}" )
echo -e "Found problem with Copyright for ${GREEN}${OWNER_}${NC} in ${LINE_%%:*}: ${ORANGE}${LINE_##*:}""${NC}""\\n"
echo -e "\\n""${ORANGE}${BOLD}==> FIX ERRORS""${NC}""\\n"
fi
done
fi
if [[ "${#MODULES_TO_CHECK_ARR_COPYRIGHT[@]}" -eq 0 ]]; then
echo -e "\\n""${GREEN}""==> Found no problems with copyrights""${NC}""\\n"
fi
}

# main:
check_tools
check
dockerchecker
copy_right_check "Siemens Energy AG" 2023 ./ ./external
list_linter_exceptions shellcheck ./ ./external
list_linter_exceptions semgrep ./ ./external
summary

if [[ "${#MODULES_TO_CHECK_ARR_TAB[@]}" -gt 0 ]] || [[ "${#MODULES_TO_CHECK_ARR[@]}" -gt 0 ]] || \
[[ "${#MODULES_TO_CHECK_ARR[@]}" -gt 0 ]] || [[ "${#MODULES_TO_CHECK_ARR_SEMGREP[@]}" -gt 0 ]] || \
[[ "${#MODULES_TO_CHECK_ARR_DOCKER[@]}" -gt 0 ]] || [[ "${#MODULES_TO_CHECK_ARR_PERM[@]}" -gt 0 ]] || \
[[ "${#MODULES_TO_CHECK_ARR_COMMENT[@]}" -gt 0 ]] || [[ "${#MODULES_TO_CHECK_ARR_GREP[@]}" -gt 0 ]]; then
[[ "${#MODULES_TO_CHECK_ARR_COMMENT[@]}" -gt 0 ]] || [[ "${#MODULES_TO_CHECK_ARR_GREP[@]}" -gt 0 ]] || \
[[ "${#MODULES_TO_CHECK_ARR_COPYRIGHT[@]}" -gt 0 ]]; then
exit 1
fi
2 changes: 1 addition & 1 deletion modules/F50_base_aggregator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# EMBA - EMBEDDED LINUX ANALYZER
#
# Copyright 2021-2022 Siemens Energy AG
# Copyright 2021-2023 Siemens Energy AG
# Copyright 2021-2022 Siemens AG
#
# EMBA comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
Expand Down
2 changes: 1 addition & 1 deletion modules/L10_system_emulation/fixImage.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2015 - 2016, Daming Dominic Chen
# Copyright (c) 2017 - 2020, Mingeun Kim, Dongkwan Kim, Eunsoo Kim
# Copyright (c) 2022, Siemens Energy AG
# Copyright (c) 2022 - 2023 Siemens Energy AG

# use busybox statically-compiled version of all binaries
# shellcheck disable=SC2148
Expand Down
2 changes: 1 addition & 1 deletion modules/L10_system_emulation/inferFile.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2015 - 2016, Daming Dominic Chen
# Copyright (c) 2017 - 2020, Mingeun Kim, Dongkwan Kim, Eunsoo Kim
# Copyright (c) 2022, Siemens Energy AG
# Copyright (c) 2022 - 2023 Siemens Energy AG

# shellcheck disable=SC2148
BUSYBOX="/busybox"
Expand Down
2 changes: 1 addition & 1 deletion modules/L10_system_emulation/inferService.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2015 - 2016, Daming Dominic Chen
# Copyright (c) 2017 - 2020, Mingeun Kim, Dongkwan Kim, Eunsoo Kim
# Copyright (c) 2022, Siemens Energy AG
# Copyright (c) 2022 - 2023 Siemens Energy AG

# shellcheck disable=SC2148
BUSYBOX="/busybox"
Expand Down
2 changes: 1 addition & 1 deletion modules/L10_system_emulation/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Copyright (c) 2015 - 2016, Daming Dominic Chen
# Copyright (c) 2017 - 2020, Mingeun Kim, Dongkwan Kim, Eunsoo Kim
# Copyright (c) 2022, Siemens Energy AG
# Copyright (c) 2022 - 2023 Siemens Energy AG

BUSYBOX=/firmadyne/busybox
ACTION=$("${BUSYBOX}" cat /firmadyne/network_type)
Expand Down
2 changes: 1 addition & 1 deletion modules/L10_system_emulation/preInit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Copyright (c) 2015 - 2016, Daming Dominic Chen
# Copyright (c) 2017 - 2020, Mingeun Kim, Dongkwan Kim, Eunsoo Kim
# Copyright (c) 2022, Siemens Energy AG
# Copyright (c) 2022 - 2023 Siemens Energy AG

BUSYBOX=/firmadyne/busybox

Expand Down
2 changes: 1 addition & 1 deletion modules/L10_system_emulation/run_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Copyright (c) 2015 - 2016, Daming Dominic Chen
# Copyright (c) 2017 - 2020, Mingeun Kim, Dongkwan Kim, Eunsoo Kim
# Copyright (c) 2022, Siemens Energy AG
# Copyright (c) 2022 - 2023 Siemens Energy AG

BUSYBOX=/firmadyne/busybox

Expand Down