]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - scripts/check-kernel-config.sh
more confs
[waydroid.git] / scripts / check-kernel-config.sh
1 #!/bin/bash
2
3 FILE=$1
4
5 [ -f "$FILE" ] || {
6 echo "Provide a config file as argument"
7 exit
8 }
9
10 write=false
11
12 if [ "$2" = "-w" ]; then
13 write=true
14 fi
15
16 CONFIGS_ON="
17 CONFIG_SW_SYNC_USER
18 CONFIG_NET_CLS_CGROUP
19 CONFIG_CGROUP_NET_CLASSID
20 CONFIG_VETH
21 CONFIG_BRIDGE
22 CONFIG_NETFILTER_XT_TARGET_CHECKSUM
23 "
24
25 CONFIGS_OFF="
26 "
27
28 CONFIGS_EQ="
29 CONFIG_ANDROID_BINDER_DEVICES=\"binder,hwbinder,vndbinder,anbox-binder,anbox-hwbinder,anbox-vndbinder\"
30 "
31 ered() {
32 echo -e "\033[31m" $@
33 }
34
35 egreen() {
36 echo -e "\033[32m" $@
37 }
38
39 ewhite() {
40 echo -e "\033[37m" $@
41 }
42
43 echo -e "\n\nChecking config file for Halium specific config options.\n\n"
44
45 errors=0
46 fixes=0
47
48 for c in $CONFIGS_ON $CONFIGS_OFF;do
49 cnt=`grep -w -c $c $FILE`
50 if [ $cnt -gt 1 ];then
51 ered "$c appears more than once in the config file, fix this"
52 errors=$((errors+1))
53 fi
54
55 if [ $cnt -eq 0 ];then
56 if $write ; then
57 ewhite "Creating $c"
58 echo "# $c is not set" >> "$FILE"
59 fixes=$((fixes+1))
60 else
61 ered "$c is neither enabled nor disabled in the config file"
62 errors=$((errors+1))
63 fi
64 fi
65 done
66
67 for c in $CONFIGS_ON;do
68 if grep "$c=y\|$c=m" "$FILE" >/dev/null;then
69 egreen "$c is already set"
70 else
71 if $write ; then
72 ewhite "Setting $c"
73 sed -i "s,# $c is not set,$c=y," "$FILE"
74 fixes=$((fixes+1))
75 else
76 ered "$c is not set, set it"
77 errors=$((errors+1))
78 fi
79 fi
80 done
81
82 for c in $CONFIGS_EQ;do
83 lhs=$(awk -F= '{ print $1 }' <(echo $c))
84 rhs=$(awk -F= '{ print $2 }' <(echo $c))
85 if grep "^$c" "$FILE" >/dev/null;then
86 egreen "$c is already set correctly."
87 continue
88 elif grep "^$lhs" "$FILE" >/dev/null;then
89 cur=$(awk -F= '{ print $2 }' <(grep "$lhs" "$FILE"))
90 ered "$lhs is set, but to $cur not $rhs."
91 if $write ; then
92 egreen "Setting $c correctly"
93 sed -i 's,^'"$lhs"'.*,# '"$lhs"' was '"$cur"'\n'"$c"',' "$FILE"
94 fixes=$((fixes+1))
95 fi
96 else
97 if $write ; then
98 ewhite "Setting $c"
99 echo "$c" >> "$FILE"
100 fixes=$((fixes+1))
101 else
102 ered "$c is not set"
103 errors=$((errors+1))
104 fi
105 fi
106 done
107
108 for c in $CONFIGS_OFF;do
109 if grep "$c=y\|$c=m" "$FILE" >/dev/null;then
110 if $write ; then
111 ewhite "Unsetting $c"
112 sed -i "s,$c=.*,# $c is not set," $FILE
113 fixes=$((fixes+1))
114 else
115 ered "$c is set, unset it"
116 errors=$((errors+1))
117 fi
118 else
119 egreen "$c is already unset"
120 fi
121 done
122
123 if [ $errors -eq 0 ];then
124 egreen "\n\nConfig file checked, found no errors.\n\n"
125 else
126 ered "\n\nConfig file checked, found $errors errors that I did not fix.\n\n"
127 fi
128
129 if [ $fixes -gt 0 ];then
130 egreen "Made $fixes fixes.\n\n"
131 fi
132
133 ewhite " "