forked from thesofproject/sof-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv-check.sh
executable file
·151 lines (134 loc) · 5.21 KB
/
env-check.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/bin/bash
mydir=$(cd "$(dirname "$0")"; pwd)
# enable dynamic debug logs for SOF modules
DYNDBG="/etc/modprobe.d/sof-dyndbg.conf"
# check for the system package
out_str=""
func_check_pkg(){
if command -v "$1" >/dev/null; then
return
else
out_str="$out_str""\tPlease install the \e[31m $1 \e[0m package\n"
check_res=1
fi
}
func_check_python_pkg(){
if command -v python3 >/dev/null; then
if python3 -c "import $1" &> /dev/null; then
return
else
out_str="$out_str""\tPlease install the \e[31m python3-$1 \e[0m package\n"
check_res=1
fi
else
return
fi
}
func_check_file(){
if [ -e "$1" ]; then
return
fi
out_str="$out_str""Optional: Enable dynamic debug logs in \e[31m $1 \e[0m file\n\tFor example,\n\toptions snd_sof dyndbg=+p\n\toptions snd_sof_pci dyndbg=+p\n"
check_res=1
}
check_res=0
printf "Checking for some OS packages:\t\t"
func_check_pkg expect
func_check_pkg aplay
func_check_pkg python3
func_check_python_pkg graphviz
func_check_file "$DYNDBG"
if [ $check_res -eq 0 ]; then
printf "pass\n"
else
printf '\e[31mWarning\e[0m\n'
# Need ANSI color characters to be the format string. This is not
# unsanitized input.
# shellcheck disable=SC2059
printf "$out_str"
fi
# check for the tools folder
out_str="" check_res=0
echo -ne "Check for tools folder:\t\t"
cd "$mydir"
[[ "$(stat -c "%A" ./tools/* |grep -v 'x')" ]] && check_res=1 && out_str=$out_str"\n
\tMissing execution permission of script/binary in tools folder\n
\tWarning: you need to make sure the current user has execution permssion\n
\tPlease use the following command to give execution permission:\n
\t\e[31mcd ${mydir}\n
\tchmod a+x tools/*\e[0m"
[[ $check_res -eq 0 ]] && echo "pass" || \
echo -e "\e[31mWarning\e[0m\nSolution:"$out_str
out_str="" check_res=0
echo -ne "Checking for case folder:\t\t"
[[ "$(stat -c "%A" ./test-case/* |grep -v 'x')" ]] && check_res=1 && out_str="\n
\tMissing execution permission of script/binary in test-case folder\n
\tWarning: you need to make sure the current user has execution permssion\n
\tPlease use the following command to give execution permission:\n
\t\e[31mcd ${mydir}\n
\tchmod a+x test-case/*\e[0m"
[[ $check_res -eq 0 ]] && echo "pass" || \
echo -e "\e[31mWarning\e[0m\nSolution:"$out_str
out_str="" check_res=0
echo -ne "Checking the permission:\t\t"
if [[ "$SUDO_USER" ]]; then
user="$SUDO_USER"
elif [[ "$UID" -ne 0 ]]; then
user="$USER"
else
user=""
fi
[[ "$user" ]] && [[ ! $(awk -F ':' '/^adm:/ {print $NF;}' /etc/group|grep "$user") ]] && \
check_res=1 && out_str=$out_str"\n
\tMissing permission to access /var/log/kern.log\n
\t\tPlease use the following command to add current user to the adm group:\n
\t\e[31msed -i '/^adm:/s:$:,$user:g' /etc/group\e[0m"
[[ "$user" ]] && [[ ! $(awk -F ':' '/^sudo:/ {print $NF;}' /etc/group|grep "$user") ]] && \
check_res=1 && out_str=$out_str"\n
\tMissing permission to run command as sudo\n
\t\tPlease use the following command to add current user to the sudo group:\n
\t\e[31msed -i '/^sudo:/s:$:,$user:g' /etc/group\e[0m"
[[ "$user" ]] && [[ ! $(awk -F ':' '/^audio:/ {print $NF;}' /etc/group|grep "$user") ]] && \
check_res=1 && out_str=$out_str"\n
\tMissing audio group membership to access /dev/snd/* devices\n
\t\tPlease use the following command to add current user to the audio group, then log in again:\n
\t\e[31msudo usermod --append --groups audio $user
\e[0m"
[[ ! -e "/var/log/kern.log" ]] && \
check_res=1 && out_str=$out_str"\n
\tMissing /var/log/kern.log file, which is where we'll catch the kernel log\n
\t\tPlease create the \e[31mlink\e[0m of your distribution kernel log file at \e[31m/var/log/kern.log\e[0m"
[[ $check_res -eq 0 ]] && echo "pass" || \
echo -e "\e[31mWarning\e[0m\nSolution:"$out_str
out_str="" check_res=0
echo -ne "Checking the config setup:\t\t"
# shellcheck source=case-lib/config.sh
source "${mydir}/case-lib/config.sh"
# effect check
case "$SUDO_LEVEL" in
'0'|'1'|'2')
if [[ "$SUDO_LEVEL" -eq 2 ]]; then
[[ ! "$SUDO_PASSWD" ]] && check_res=1 && out_str=$out_str"\n
\tPlease setup \e[31mSUDO_PASSWD\e[0min ${mydir}/case-lib/config.sh file\n
\t\tIf you don't want modify to this value, you will need to export SUDO_PASSWD\n
\t\tso our scripts can access debugfs, as some test cases need it.\n
\t\tYou also can modify the SUDO_LEVEL to 1, using visudo to modify the permission"
fi
;;
*)
if [[ "$SUDO_LEVEL" ]]; then
check_res=1 && out_str=$out_str"\n
\tSUDO_LEVEL only accepts 0-2\n
\t\t\e[31m0\e[0m: means: run as root, don't need to preface with sudo \n
\t\t\e[31m1\e[0m: means: run sudo command without password\n
\t\t\e[31m2\e[0m: means: run sudo command, but need password\n
\t\t\t\e[31mSUDO_PASSWD\e[0m: Is the sudo password sent to the sudo command?"
fi
;;
esac
[[ "$LOG_ROOT" ]] && [[ ! -d $LOG_ROOT ]] && check_res=1 && out_str=$out_str"\n
\tAlready setup LOG_ROOT, but missing the folder: $LOG_ROOT\n
\t\tPossible permission error occurred during script execution. Please ensure\n
\t\tthe permissions are properly set up according to instructions."
[[ $check_res -eq 0 ]] && echo "pass" || \
echo -e "\e[31mWarning\e[0m\nSolution:"$out_str