-
-
Notifications
You must be signed in to change notification settings - Fork 295
/
check-kernel-config.sh
executable file
·133 lines (114 loc) · 2.47 KB
/
check-kernel-config.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
#!/bin/bash
FILE=$1
[ -f "$FILE" ] || {
echo "Provide a config file as argument"
exit
}
write=false
if [ "$2" = "-w" ]; then
write=true
fi
CONFIGS_ON="
CONFIG_SW_SYNC_USER
CONFIG_NET_CLS_CGROUP
CONFIG_CGROUP_NET_CLASSID
CONFIG_VETH
CONFIG_BRIDGE
CONFIG_NETFILTER_XT_TARGET_CHECKSUM
"
CONFIGS_OFF="
"
CONFIGS_EQ="
CONFIG_ANDROID_BINDER_DEVICES=\"binder,hwbinder,vndbinder,anbox-binder,anbox-hwbinder,anbox-vndbinder\"
"
ered() {
echo -e "\033[31m" $@
}
egreen() {
echo -e "\033[32m" $@
}
ewhite() {
echo -e "\033[37m" $@
}
echo -e "\n\nChecking config file for Halium specific config options.\n\n"
errors=0
fixes=0
for c in $CONFIGS_ON $CONFIGS_OFF;do
cnt=`grep -w -c $c $FILE`
if [ $cnt -gt 1 ];then
ered "$c appears more than once in the config file, fix this"
errors=$((errors+1))
fi
if [ $cnt -eq 0 ];then
if $write ; then
ewhite "Creating $c"
echo "# $c is not set" >> "$FILE"
fixes=$((fixes+1))
else
ered "$c is neither enabled nor disabled in the config file"
errors=$((errors+1))
fi
fi
done
for c in $CONFIGS_ON;do
if grep "$c=y\|$c=m" "$FILE" >/dev/null;then
egreen "$c is already set"
else
if $write ; then
ewhite "Setting $c"
sed -i "s,# $c is not set,$c=y," "$FILE"
fixes=$((fixes+1))
else
ered "$c is not set, set it"
errors=$((errors+1))
fi
fi
done
for c in $CONFIGS_EQ;do
lhs=$(awk -F= '{ print $1 }' <(echo $c))
rhs=$(awk -F= '{ print $2 }' <(echo $c))
if grep "^$c" "$FILE" >/dev/null;then
egreen "$c is already set correctly."
continue
elif grep "^$lhs" "$FILE" >/dev/null;then
cur=$(awk -F= '{ print $2 }' <(grep "$lhs" "$FILE"))
ered "$lhs is set, but to $cur not $rhs."
if $write ; then
egreen "Setting $c correctly"
sed -i 's,^'"$lhs"'.*,# '"$lhs"' was '"$cur"'\n'"$c"',' "$FILE"
fixes=$((fixes+1))
fi
else
if $write ; then
ewhite "Setting $c"
echo "$c" >> "$FILE"
fixes=$((fixes+1))
else
ered "$c is not set"
errors=$((errors+1))
fi
fi
done
for c in $CONFIGS_OFF;do
if grep "$c=y\|$c=m" "$FILE" >/dev/null;then
if $write ; then
ewhite "Unsetting $c"
sed -i "s,$c=.*,# $c is not set," $FILE
fixes=$((fixes+1))
else
ered "$c is set, unset it"
errors=$((errors+1))
fi
else
egreen "$c is already unset"
fi
done
if [ $errors -eq 0 ];then
egreen "\n\nConfig file checked, found no errors.\n\n"
else
ered "\n\nConfig file checked, found $errors errors that I did not fix.\n\n"
fi
if [ $fixes -gt 0 ];then
egreen "Made $fixes fixes.\n\n"
fi
ewhite " "