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