summaryrefslogtreecommitdiff
path: root/sys-kernel/linux/files/config_prepare.sh
blob: c2b5854da182f0bb67edd1c6626c8042833b5aff (plain)
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
#!/bin/sh
set -e

B="$(dirname $0)"

BASE=arch.config
OVERLAY=overlay.config

if [ "$1" = "amd" ]; then
	OVERLAY=amd.config
elif [ "$1" = "virt" ]; then
	BASE=
	OVERLAY=virt.config
fi
#################################################################################

# First just deploy base configuration (provided or just kernel default)
if [ -n "$BASE" ]; then
	cp "$B/$BASE" .config
else
	make defconfig
fi

# We are done if no overlay is specified
[ -n "$OVERLAY" ] || exit 0

# And now apply changes from overlay.config
while read L; do
	echo "$L" | grep -qE "^[[:space:]]*$" && continue # ignore empty lines
	echo "$L" | grep -qE "#.*" && continue # Ignore comments
	# Remove lines with changed settings
	OPTION="$(echo "$L" | grep -oE '^CONFIG_.*=')"
	sed -i "#^$OPTION#d" .config
	# Put config
	echo "$L" >> .config
done < "$B/$OVERLAY"

# As next step run olddefconfig (note: stderr contains some output about overrided
# options so I am ignoring it)
make olddefconfig 2>/dev/null

# Now let's check that configuration
EC=0
while read L; do
	echo "$L" | grep -qE "^[[:space:]]*$" && continue # ignore empty lines
	echo "$L" | grep -qE "#.*" && continue # Ignore comments
	OPTION="$(echo "$L" | grep -oE '^CONFIG_.*=')"
	VALUE="$(echo "$L" | grep -oE '=.*$')"
	if [ "$VALUE" = "=n" ]; then
		if grep -qE "^$OPTION=y" .config; then
			EC=1
			echo -e "\e[1;31mY:\e[0m$L"
		fi
	else
		if ! grep -qE "^$L$" .config; then
			EC=1
			echo -e "\e[1;31mN:\e[0m$L"
		fi
	fi
done < "$B/$OVERLAY"

exit $EC