Handle missing kernel .config better (bug #271528)
[genkernel.git] / gen_configkernel.sh
1 #!/bin/bash
2 # $Id$
3
4 determine_config_file() {
5         if [ "${CMD_KERNEL_CONFIG}" != "" ]
6         then
7                 KERNEL_CONFIG="${CMD_KERNEL_CONFIG}"
8         elif [ -f "/etc/kernels/kernel-config-${ARCH}-${KV}" ]
9         then
10                 KERNEL_CONFIG="/etc/kernels/kernel-config-${ARCH}-${KV}"
11         elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config-${KV}" ]
12         then
13                 KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config-${KV}"
14         elif [ "${DEFAULT_KERNEL_CONFIG}" != "" -a -f "${DEFAULT_KERNEL_CONFIG}" ]
15         then
16                 KERNEL_CONFIG="${DEFAULT_KERNEL_CONFIG}"
17         elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config-${VER}.${PAT}" ]
18         then
19                 KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config-${VER}.${PAT}"
20         elif [ -f "${GK_SHARE}/arch/${ARCH}/kernel-config" ]
21         then
22                 KERNEL_CONFIG="${GK_SHARE}/arch/${ARCH}/kernel-config"
23         else
24                 gen_die 'Error: No kernel .config specified, or file not found!'
25         fi
26 }
27
28 config_kernel() {
29         determine_config_file
30         cd "${KERNEL_DIR}" || gen_die 'Could not switch to the kernel directory!'
31
32         # Backup and replace kernel .config
33         if isTrue "${CLEAN}" || [ ! -f "${KERNEL_DIR}/.config" ]
34         then
35                 print_info 1 "config: Using config from ${KERNEL_CONFIG}"
36                 if [ -f "${KERNEL_DIR}/.config" ]
37                 then
38                         cp "${KERNEL_DIR}/.config" "${KERNEL_DIR}/.config.bak" \
39                                         || gen_die "Could not backup kernel config (${KERNEL_DIR}/.config)"
40                         print_info 1 '        Previous config backed up to .config.bak'
41                 fi
42                 cp "${KERNEL_CONFIG}" "${KERNEL_DIR}/.config" || gen_die 'Could not copy configuration file!'
43         fi
44
45         if isTrue ${MRPROPER}
46         then
47                 print_info 1 'kernel: >> Running mrproper...'
48                 compile_generic mrproper kernel
49         fi
50
51         # If we're not cleaning, then we don't want to try to overwrite the configs
52         # or we might remove configurations someone is trying to test.
53
54         if isTrue "${OLDCONFIG}"
55         then
56                 print_info 1 '        >> Running oldconfig...'
57                 yes '' 2>/dev/null | compile_generic oldconfig kernel 2>/dev/null
58         fi
59         if isTrue "${CLEAN}"
60         then
61                 print_info 1 'kernel: >> Cleaning...'
62                 compile_generic clean kernel
63         else
64                 print_info 1 "config: --no-clean is enabled; not running 'make clean'."
65         fi
66         
67         if isTrue ${MENUCONFIG}
68         then
69                 print_info 1 'config: >> Invoking menuconfig...'
70                 compile_generic menuconfig runtask
71                 [ "$?" ] || gen_die 'Error: menuconfig failed!'
72         elif isTrue ${CMD_GCONFIG}
73         then
74                 print_info 1 'config: >> Invoking gconfig...'
75                 compile_generic gconfig kernel
76                 [ "$?" ] || gen_die 'Error: gconfig failed!'
77
78                 CMD_XCONFIG=0
79         fi
80
81         if isTrue ${CMD_XCONFIG}
82         then
83                 print_info 1 'config: >> Invoking xconfig...'
84                 compile_generic xconfig kernel
85                 [ "$?" ] || gen_die 'Error: xconfig failed!'
86         fi
87
88         # Force this on if we are using --genzimage
89         if isTrue ${CMD_GENZIMAGE}
90         then
91                 # Make sure Ext2 support is on...
92                 sed -e 's/#\? \?CONFIG_EXT2_FS[ =].*/CONFIG_EXT2_FS=y/g' \
93                         -i ${KERNEL_DIR}/.config 
94         fi
95
96         # Make sure lvm modules are on if --lvm
97         if isTrue ${CMD_LVM}
98         then
99                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_BLK_DEV_DM is.*/CONFIG_BLK_DEV_DM=m/g'
100                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_DM_SNAPSHOT is.*/CONFIG_DM_SNAPSHOT=m/g'
101                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_DM_MIRROR is.*/CONFIG_DM_MIRROR=m/g'
102         fi
103
104         # Make sure dmraid modules are on if --dmraid
105         if isTrue ${CMD_DMRAID}
106         then
107                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_BLK_DEV_DM is.*/CONFIG_BLK_DEV_DM=m/g'
108         fi
109
110         # Make sure iSCSI modules are enabled in the kernel, if --iscsi
111         # CONFIG_SCSI_ISCSI_ATTRS
112         # CONFIG_ISCSI_TCP
113         if isTrue ${CMD_ISCSI}
114         then
115                 sed -i ${KERNEL_DIR}/.config -e 's/\# CONFIG_ISCSI_TCP is not set/CONFIG_ISCSI_TCP=m/g'
116                 sed -i ${KERNEL_DIR}/.config -e 's/\# CONFIG_SCSI_ISCSI_ATTRS is not set/CONFIG_SCSI_ISCSI_ATTRS=m/g'
117
118                 sed -i ${KERNEL_DIR}/.config -e 's/CONFIG_ISCSI_TCP=y/CONFIG_ISCSI_TCP=m/g'
119                 sed -i ${KERNEL_DIR}/.config -e 's/CONFIG_SCSI_ISCSI_ATTRS=y/CONFIG_SCSI_ISCSI_ATTRS=m/g'
120         fi
121
122         if isTrue ${SPLASH}
123         then
124                 sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_FB_SPLASH is.*/CONFIG_FB_SPLASH=y/g'
125         fi
126 }