Added check for --lvm2 and enable lvm2-required modules if they are not enabled alrea...
[genkernel.git] / gen_configkernel.sh
1 #!/bin/bash
2
3 determine_config_file() {
4         if [ "${CMD_KERNEL_CONFIG}" != "" ]
5         then
6                 KERNEL_CONFIG="${CMD_KERNEL_CONFIG}"
7         elif [ -f "/etc/kernels/kernel-config-${ARCH}-${KV}" ]
8         then
9                 KERNEL_CONFIG="/etc/kernels/kernel-config-${ARCH}-${KV}"
10         elif [ -f "${GK_SHARE}/${ARCH}/kernel-config-${KV}" ]
11         then
12                 KERNEL_CONFIG="${GK_SHARE}/${ARCH}/kernel-config-${KV}"
13         elif [ "${DEFAULT_KERNEL_CONFIG}" != "" -a -f "${DEFAULT_KERNEL_CONFIG}" ]
14         then
15                 KERNEL_CONFIG="${DEFAULT_KERNEL_CONFIG}"
16         elif [ -f "${GK_SHARE}/${ARCH}/kernel-config-${VER}.${PAT}" ]
17         then
18                 KERNEL_CONFIG="${GK_SHARE}/${ARCH}/kernel-config-${VER}.${PAT}"
19         elif [ -f "${GK_SHARE}/${ARCH}/kernel-config" ]
20         then
21                 KERNEL_CONFIG="${GK_SHARE}/${ARCH}/kernel-config"
22         else
23                 gen_die 'Error: No kernel .config specified, or file not found!'
24         fi
25 }
26
27 config_kernel() {
28         determine_config_file
29         cd "${KERNEL_DIR}" || gen_die 'Could not switch to the kernel directory!'
30
31         isTrue "${CLEAN}" && cp "${KERNEL_DIR}/.config" "${KERNEL_DIR}/.config.bak" > /dev/null 2>&1
32         if isTrue ${MRPROPER}
33         then
34                 print_info 1 'kernel: >> Running mrproper...'
35                 compile_generic mrproper kernel
36         fi
37
38         # If we're not cleaning, then we don't want to try to overwrite the configs there
39         # or we might remove configurations someone is trying to test.
40
41         if isTrue "${CLEAN}"
42         then
43                 print_info 1 "config: Using config from ${KERNEL_CONFIG}"
44                 print_info 1 '        Previous config backed up to .config.bak'
45                 cp "${KERNEL_CONFIG}" "${KERNEL_DIR}/.config" || gen_die 'Could not copy configuration file!'
46         fi
47         if isTrue "${CLEAN}" || isTrue "${OLDCONFIG}"
48         then
49                 if ! isTrue "${CLEAN}"
50                 then
51                         print_info 1 'config: >> Running oldconfig...'
52                 else
53                         print_info 1 '        >> Running oldconfig...'
54                 fi
55                 yes '' 2>/dev/null | compile_generic oldconfig kernel 2>/dev/null # Nullify to stop broken pipe messages
56         fi
57         if isTrue "${CLEAN}"
58         then
59                 print_info 1 'kernel: >> Cleaning...'
60                 compile_generic clean kernel
61         else
62                 print_info 1 "config: --no-clean is enabled; leaving the .config alone."
63         fi
64         
65         if isTrue ${MENUCONFIG}
66         then
67                 print_info 1 'config: >> Invoking menuconfig...'
68                 compile_generic menuconfig runtask
69                 [ "$?" ] || gen_die 'Error: menuconfig failed!'
70         elif isTrue ${CMD_GCONFIG}
71         then
72                 if [ "${VER}" == '2' ] && [ "${PAT}" -lt '6' ]
73                 then
74                         print_warning 1 'config: gconfig is not available in 2.4 series kernels. Running xconfig'
75                         print_warning 1 '        instead...'
76
77                         CMD_GCONFIG=0
78                         CMD_XCONFIG=1
79                 else
80                         print_info 1 'config: >> Invoking gconfig...'
81                         compile_generic gconfig kernel
82                         [ "$?" ] || gen_die 'Error: gconfig failed!'
83
84                         CMD_XCONFIG=0
85                 fi
86         fi
87
88         if isTrue ${CMD_XCONFIG}
89         then
90                 print_info 1 'config: >> Invoking xconfig...'
91                 compile_generic xconfig kernel
92                 [ "$?" ] || gen_die 'Error: xconfig failed!'
93         fi
94
95         # Make sure Ext2 support is on...
96         sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_EXT2_FS[ =].*/CONFIG_EXT2_FS=y/g'
97
98         # Make sure lvm2 modules are on if --lvm2
99         if isTrue ${CMD_LVM2}
100         then
101                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_BLK_DEV_DM[ =].*/CONFIG_BLK_DEV_DM=m/g'
102                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_DM_SNAPSHOT[ =].*/CONFIG_DM_SNAPSHOT=m/g'
103                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_DM_SNAPSHOT[ =].*/CONFIG_DM_SNAPSHOT=m/g'
104         fi
105 }