--no-lvm-2 >> --no-lvm2 as it should be.
[genkernel.git] / gen_cmdline.sh
1 #!/bin/bash
2
3 longusage() {
4   echo "Gentoo Linux Genkernel ${GK_V}"
5   echo "Usage: "
6   echo "  genkernel [options] action"
7   echo
8   echo "Available Actions: "
9   echo "  all                           Build all steps"
10   echo "  kernel                        Build only the kernel and modules"
11   echo "  initrd                        Build only the initrd"
12   echo
13   echo "Available Options: "
14   echo "  Debug settings"
15   echo "        --debuglevel=<0-5>      Debug Verbosity Level"
16   echo "        --debugfile=<outfile>   Output file for debug info"
17   echo "        --color                 Output debug in color"
18   echo "        --no-color              Do not output debug in color"
19   echo "  Kernel Configuration settings"
20   echo "        --menuconfig            Run menuconfig after oldconfig"
21   echo "        --no-menuconfig         Do not run menuconfig after oldconfig"
22   echo "        --gconfig               Run gconfig after oldconfig"
23   echo "        --xconfig               Run xconfig after oldconfig"
24   echo "        --save-config           Save the configuration to /etc/kernels"
25   echo "        --no-save-config        Don't save the configuration to /etc/kernels"
26   echo "  Kernel Compile settings"
27   echo "        --clean                 Run make clean before compilation"
28   echo "        --mrproper              Run make mrproper before compilation"
29   echo "        --no-clean              Do not run make clean before compilation"
30   echo "        --no-mrproper           Do not run make mrproper before compilation"
31   echo "        --oldconfig             Implies --no-clean and runs a 'make oldconfig'"
32   echo "        --bootsplash            Install bootsplash support to the initrd"
33   echo "        --no-bootsplash         Do not use bootsplash"
34   echo "        --install               Install the kernel after building"
35   echo "        --no-install            Do not install the kernel after building"
36   echo "        --no-initrdmodules      Don't copy any modules to the initrd"
37   echo "        --udev                  Add in udev support."
38   echo "        --callback=<...>        Run the specified arguments after"
39   echo "                                the kernel and modules have been"
40   echo "                                compiled."
41   echo "  Kernel settings"
42   echo "        --kerneldir=<dir>       Location of the kernel sources"
43   echo "        --kernel-config=<file>  Kernel configuration file to use for compilation"
44   echo "        --module-prefix=<dir>   Prefix to kernel module destination, modules will"
45   echo "                                be installed in <prefix>/lib/modules"
46   echo "  Low-Level Compile settings"
47   echo "        --kernel-cc=<compiler>  Compiler to use for kernel (e.g. distcc)"
48   echo "        --kernel-as=<assembler> Assembler to use for kernel"
49   echo "        --kernel-ld=<linker>    Linker to use for kernel"
50   echo "        --kernel-make=<makeprg> GNU Make to use for kernel"
51   echo "        --utils-cc=<compiler>   Compiler to use for utilities"
52   echo "        --utils-as=<assembler>  Assembler to use for utils"
53   echo "        --utils-ld=<linker>     Linker to use for utils"
54   echo "        --utils-make=<makeprog> GNU Make to use for utils"
55   echo "        --makeopts=<makeopts>   Make options such as -j2, etc."
56   echo "        --mountboot             Mount /boot automatically"
57   echo "        --no-mountboot          Don't mount /boot automatically"  
58   echo "  Initialization"
59   echo "        --bootsplash=<theme>    Force bootsplash using <theme>."
60   echo "        --do-keymap-auto        Forces keymap selection at boot."
61   echo "        --no-lvm2               Don't add in LVM2 support."
62   echo "        --bootloader=grub       Add new kernel to GRUB configuration"
63   echo "  Internals"
64   echo "        --arch-override=<arch>  Force to arch instead of autodetect"
65   echo "        --cachedir=<dir>        Override the default cache location"
66   echo "        --tempdir=<dir>         Location of Genkernel's temporary directory"
67   echo "  Output Settings"
68   echo "        --minkernpackage=<tbz2> File to output a .tar.bz2'd kernel and initrd:"
69   echo "                                No modules outside of the initrd will be"
70   echo "                                included..."
71 }
72
73 usage() {
74   echo "Gentoo Linux Genkernel ${GK_V}"
75   echo "Usage: "
76   echo "        genkernel [options] all"
77   echo
78   echo 'Some useful options:'
79   echo '        --menuconfig            Run menuconfig after oldconfig'
80   echo '        --no-clean              Do not run make clean before compilation'
81   echo '        --no-mrproper           Do not run make mrproper before compilation,'
82   echo '                                this is implied by --no-clean.'
83   echo
84   echo 'For a detailed list of supported options and flags; issue:'
85   echo '        genkernel --help'
86 }
87
88 parse_opt() {
89         case "$1" in
90                 *\=*)
91                         echo "$1" | cut -f2- -d=
92                 ;;
93         esac
94 }
95
96 parse_cmdline() {
97         case "$*" in
98               --kernel-cc*)
99                       CMD_KERNEL_CC=`parse_opt "$*"`
100                       print_info 2 "CMD_KERNEL_CC: $CMD_KERNEL_CC"
101               ;;
102               --kernel-ld*)
103                       CMD_KERNEL_LD=`parse_opt "$*"`
104                       print_info 2 "CMD_KERNEL_LD: $CMD_KERNEL_LD"
105               ;;
106               --kernel-as*)
107                       CMD_KERNEL_AS=`parse_opt "$*"`
108                       print_info 2 "CMD_KERNEL_AS: $CMD_KERNEL_AS"
109               ;;
110               --kernel-make*)
111                       CMD_KERNEL_MAKE=`parse_opt "$*"`
112                       print_info 2 "CMD_KERNEL_MAKE: $CMD_KERNEL_MAKE"
113               ;;
114               --utils-cc*)
115                       CMD_UTILS_CC=`parse_opt "$*"`
116                       print_info 2 "CMD_UTILS_CC: $CMD_UTILS_CC"
117               ;;
118               --utils-ld*)
119                       CMD_UTILS_LD=`parse_opt "$*"`
120                       print_info 2 "CMD_UTILS_LD: $CMD_UTILS_LD"
121               ;;
122               --utils-as*)
123                       CMD_UTILS_AS=`parse_opt "$*"`
124                       print_info 2 "CMD_UTILS_AS: $CMD_UTILS_AS"
125               ;;
126               --utils-make*)
127                       CMD_UTILS_MAKE=`parse_opt "$*"`
128                       print_info 2 "CMD_UTILS_MAKE: $CMD_UTILS_MAKE"
129               ;;
130               --makeopts*)
131                       CMD_MAKEOPTS=`parse_opt "$*"`
132                       print_info 2 "CMD_MAKEOPTS: $CMD_MAKEOPTS"
133               ;;
134               --mountboot)
135                       CMD_MOUNTBOOT=1
136                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
137               ;;
138               --no-mountboot)
139                       CMD_MOUNTBOOT=0
140                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
141               ;;
142               --do-keymap-auto)
143                       CMD_DOKEYMAPAUTO=1
144                       print_info 2 "CMD_DOKEYMAPAUTO: $CMD_DOKEYMAPAUTO"
145               ;;
146               --no-lvm2)
147                       CMD_NOLVM2=1
148                       print_info 2 'CMD_NOLVM2: 1'
149               ;;
150               --bootloader*)
151                       CMD_BOOTLOADER=`parse_opt "$*"`
152                       print_info 2 "CMD_BOOTLOADER: $CMD_BOOTLOADER"
153               ;;
154               --debuglevel*)
155                       CMD_DEBUGLEVEL=`parse_opt "$*"`
156                       DEBUGLEVEL="${CMD_DEBUGLEVEL}"
157                       print_info 2 "CMD_DEBUGLEVEL: $CMD_DEBUGLEVEL"
158               ;;
159               --menuconfig)
160                       TERM_LINES=`stty -a | head -n 1 | cut -d\  -f5 | cut -d\; -f1`
161                       TERM_COLUMNS=`stty -a | head -n 1 | cut -d\  -f7 | cut -d\; -f1`
162
163                       if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]]
164                       then
165                               echo "Error: You need a terminal with at least 80 columns"
166                               echo "       and 19 lines for --menuconfig; try --nomenuconfig..."
167                               exit 1
168                       fi
169                       CMD_MENUCONFIG=1
170                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
171               ;;
172               --no-menuconfig)
173                       CMD_MENUCONFIG=0
174                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
175               ;;
176               --gconfig)
177                       CMD_GCONFIG=1
178                       print_info 2 "CMD_GCONFIG: $CMD_GCONFIG"
179               ;;
180               --xconfig)
181                       CMD_XCONFIG=1
182                       print_info 2 "CMD_XCONFIG: $CMD_XCONFIG"
183               ;;
184               --save-config)
185                       CMD_SAVE_CONFIG=1
186                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
187               ;;
188               --no-save-config)
189                       CMD_SAVE_CONFIG=0
190                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
191               ;;
192               --mrproper)
193                       CMD_MRPROPER=1
194                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
195               ;;
196               --no-mrproper)
197                       CMD_MRPROPER=0
198                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
199               ;;
200               --clean)
201                       CMD_CLEAN=1
202                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
203               ;;
204               --no-clean)
205                       CMD_CLEAN=0
206                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
207               ;;
208               --oldconfig)
209                       CMD_CLEAN=0
210                       CMD_OLDCONFIG=1
211                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
212                       print_info 2 "CMD_OLDCONFIG: $CMD_OLDCONFIG"
213               ;;
214               --bootsplash=*)
215                       CMD_BOOTSPLASH=1
216                       BOOTSPLASH_THEME=`parse_opt "$*"`
217                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
218                       print_info 2 "BOOTSPLASH_THEME: $BOOTSPLASH_THEME"
219               ;;
220               --bootsplash)
221                       CMD_BOOTSPLASH=1
222                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
223               ;;
224               --no-bootsplash)
225                       CMD_BOOTSPLASH=0
226                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
227               ;;
228               --install)
229                       CMD_NOINSTALL=0
230                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
231               ;;
232               --no-install)
233                       CMD_NOINSTALL=1
234                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
235               ;;
236               --no-initrdmodules)
237                       CMD_NOINITRDMODULES=1
238                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
239               ;;
240               --udev)
241                       CMD_UDEV=1
242                       print_info 2 "CMD_UDEV: $CMD_UDEV"
243               ;;
244               --callback*)
245                       CMD_CALLBACK=`parse_opt "$*"`
246                       print_info 2 "CMD_CALLBACK: $CMD_CALLBACK/$*"
247               ;;
248               --tempdir*)
249                 TEMP=`parse_opt "$*"`
250                 print_info 2 "TEMP: $TEMP"
251               ;; 
252               --arch-override*)
253                       CMD_ARCHOVERRIDE=`parse_opt "$*"`
254                       print_info 2 "CMD_ARCHOVERRIDE: $CMD_ARCHOVERRIDE"
255               ;;
256               --color)
257                       CMD_USECOLOR=1
258                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
259               ;;
260               --no-color)
261                       CMD_USECOLOR=0
262                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
263               ;;
264               --debugfile*)
265                       CMD_DEBUGFILE=`parse_opt "$*"`
266                       DEBUGFILE=`parse_opt "$*"`
267                       print_info 2 "CMD_DEBUGFILE: $CMD_DEBUGFILE"
268                       print_info 2 "DEBUGFILE: $CMD_DEBUGFILE"
269               ;;
270               --kerneldir*)
271                       CMD_KERNELDIR=`parse_opt "$*"`
272                       print_info 2 "CMD_KERNELDIR: $CMD_KERNELDIR"
273               ;;
274               --kernel-config*)
275                       CMD_KERNEL_CONFIG=`parse_opt "$*"`
276                       print_info 2 "CMD_KERNEL_CONFIG: $CMD_KERNEL_CONFIG"
277               ;;
278               --module-prefix*)
279                       CMD_INSTALL_MOD_PATH=`parse_opt "$*"`
280                       print_info 2 "CMD_INSTALL_MOD_PATH: $CMD_INSTALL_MOD_PATH"
281               ;;
282               --cachedir*)
283                       CACHE_DIR=`parse_opt "$*"`
284                       print_info 2 "CACHE_DIR: $CACHE_DIR"
285               ;;
286               --minkernpackage*)
287                       CMD_MINKERNPACKAGE=`parse_opt "$*"`
288                       print_info 2 "MINKERNPACKAGE: $CMD_MINKERNPACKAGE"
289               ;;
290               all)
291                       BUILD_KERNEL=1
292                       BUILD_INITRD=1
293               ;;
294               initrd)
295                       BUILD_INITRD=1
296               ;;
297               kernel)
298                       BUILD_KERNEL=1
299               ;;
300               --help)
301                       longusage
302                       exit 1
303               ;;
304               --version)
305                       echo "${GK_V}"
306                       exit 0
307               ;;
308               *)
309                       echo "Error: Unknown option '$*'!"
310                       exit 1
311               ;;
312         esac
313 }