forked from e-m-b-a/emba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_project.sh
executable file
·83 lines (70 loc) · 2.3 KB
/
check_project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# emba - EMBEDDED LINUX ANALYZER
#
# Copyright 2020-2021 Siemens AG
# Copyright 2020-2021 Siemens Energy AG
#
# emba comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
# welcome to redistribute it under the terms of the GNU General Public License.
# See LICENSE file for usage of this software.
#
# emba is licensed under GPLv3
#
# Author(s): Michael Messner, Pascal Eckmann
# Description: Check all shell scripts inside ./helpers, ./modules, emba.sh and itself with shellchecker
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BOLD='\033[1m'
NC='\033[0m' # no color
HELP_DIR="./helpers"
MOD_DIR="./modules"
SOURCES=()
import_helper() {
HELPERS=$(find "$HELP_DIR" -iname "*.sh" 2>/dev/null)
for LINE in $HELPERS; do
if (file "$LINE" | grep -q "shell script"); then
echo "$LINE"
SOURCES+=("$LINE")
fi
done
}
import_module() {
MODULES=$(find "$MOD_DIR" -iname "*.sh" 2>/dev/null)
for LINE in $MODULES; do
if (file "$LINE" | grep -q "shell script"); then
echo "$LINE"
SOURCES+=("$LINE")
fi
done
}
check()
{
echo -e "\\n""$ORANGE""$BOLD""Embedded Linux Analyzer Shellcheck""$NC""\\n""$BOLD""=================================================================""$NC"
if ! command -v shellcheck >/dev/null 2>&1; then
echo -e "\\n""$ORANGE""Shellcheck not found!""$NC""\\n""$ORANGE""Install shellcheck via 'apt-get install shellcheck'!""$NC\\n"
exit 1
fi
echo -e "\\n""$GREEN""Run shellcheck on this script:""$NC""\\n"
if shellcheck ./check_project.sh || [[ $? -ne 1 && $? -ne 2 ]]; then
echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n"
else
echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n"
fi
echo -e "\\n""$GREEN""Run shellcheck on installer:""$NC""\\n"
if shellcheck ./installer.sh || [[ $? -ne 1 && $? -ne 2 ]]; then
echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n"
else
echo -e "\\n""$ORANGE$BOLD==> FIX ERRORS""$NC""\\n"
fi
echo -e "\\n""$GREEN""Load all files for check:""$NC""\\n"
echo "./emba.sh"
import_helper
import_module
echo -e "\\n""$GREEN""Run shellcheck:""$NC""\\n"
if shellcheck -P "$HELP_DIR":"$MOD_DIR" -a ./emba.sh "${SOURCES[@]}" || [[ $? -ne 1 && $? -ne 2 ]]; then
echo -e "$GREEN""$BOLD""==> SUCCESS""$NC""\\n"
else
echo -e "\\n""$ORANGE""$BOLD""==> FIX ERRORS""$NC""\\n"
fi
}
check