Add a modified version of the two LUKS patches that made their way into bugzilla...
[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 "  bzImage                       Build only the kernel"
11   echo "  kernel                        Build only the kernel and modules"
12   echo "  initrd                        Build only the initrd"
13   echo
14   echo "Available Options: "
15   echo "  Debug settings"
16   echo "        --debuglevel=<0-5>      Debug Verbosity Level"
17   echo "        --debugfile=<outfile>   Output file for debug info"
18   echo "        --color                 Output debug in color"
19   echo "        --no-color              Do not output debug in color"
20   echo "  Kernel Configuration settings"
21   echo "        --menuconfig            Run menuconfig after oldconfig"
22   echo "        --no-menuconfig         Do not run menuconfig after oldconfig"
23   echo "        --gconfig               Run gconfig after oldconfig"
24   echo "        --xconfig               Run xconfig after oldconfig"
25   echo "        --save-config           Save the configuration to /etc/kernels"
26   echo "        --no-save-config        Don't save the configuration to /etc/kernels"
27   echo "  Kernel Compile settings"
28   echo "        --clean                 Run make clean before compilation"
29   echo "        --mrproper              Run make mrproper before compilation"
30   echo "        --no-clean              Do not run make clean before compilation"
31   echo "        --no-mrproper           Do not run make mrproper before compilation"
32   echo "        --oldconfig             Implies --no-clean and runs a 'make oldconfig'"
33   echo "        --bootsplash            Install bootsplash support to the initrd"
34   echo "        --no-bootsplash         Do not use bootsplash"
35   echo "        --gensplash             Install gensplash support into bzImage"
36   echo "        --no-gensplash          Do not use gensplash"
37   echo "        --install               Install the kernel after building"
38   echo "        --no-install            Do not install the kernel after building"
39   echo "        --no-initrdmodules      Don't copy any modules to the initrd"
40   echo "        --no-udev               Disable udev support"
41   echo "        --no-devfs              Disable devfs support"
42   echo "        --callback=<...>        Run the specified arguments after the"
43   echo "                                kernel and modules have been compiled"
44   echo "        --static                Build a static (monolithic kernel)."
45   echo "        --initramfs             Builds initramfs before kernel and embeds it"
46   echo "                                into the kernel."
47   echo "  Kernel settings"
48   echo "        --kerneldir=<dir>       Location of the kernel sources"
49   echo "        --kernel-config=<file>  Kernel configuration file to use for compilation"
50   echo "        --module-prefix=<dir>   Prefix to kernel module destination, modules"
51   echo "                                will be installed in <prefix>/lib/modules"
52   echo "  Low-Level Compile settings"
53   echo "        --kernel-cc=<compiler>  Compiler to use for kernel (e.g. distcc)"
54   echo "        --kernel-as=<assembler> Assembler to use for kernel"
55   echo "        --kernel-ld=<linker>    Linker to use for kernel"
56   echo "        --kernel-cross-compile=<cross var> CROSS_COMPILE kernel variable"
57   echo "        --kernel-make=<makeprg> GNU Make to use for kernel"
58   echo "        --utils-cc=<compiler>   Compiler to use for utilities"
59   echo "        --utils-as=<assembler>  Assembler to use for utils"
60   echo "        --utils-ld=<linker>     Linker to use for utils"
61   echo "        --utils-make=<makeprog> GNU Make to use for utils"
62   echo "        --utils-cross-compile=<cross var> CROSS_COMPILE utils variable"
63   echo "        --utils-arch=<arch>     Force to arch for utils only instead of"
64   echo "                                autodetect."
65   echo "        --makeopts=<makeopts>   Make options such as -j2, etc..."
66   echo "        --mountboot             Mount /boot automatically"
67   echo "        --no-mountboot          Don't mount /boot automatically"  
68   echo "  Initialization"
69   echo "        --bootsplash=<theme>    Force bootsplash using <theme>"
70   echo "        --gensplash=<theme>     Force gensplash using <theme>"
71   echo "        --gensplash-res=<res>   Select gensplash resolutions"
72   echo "        --do-keymap-auto        Forces keymap selection at boot"
73   echo "        --evms2                 Include EVMS2 support"
74   echo "                                --> 'emerge evms' in the host operating system"
75   echo "                                first"
76   echo "        --lvm2                  Include LVM2 support"
77 #  echo "       --unionfs               Include UNIONFS support"
78   echo "        --dmraid                Include DMRAID support"
79   echo "        --slowusb               Enables extra pauses for slow USB CD boots"
80   echo "        --bootloader=grub       Add new kernel to GRUB configuration"
81   echo "        --linuxrc=<file>        Specifies a user created linuxrc"
82   echo "        --disklabel             Include disk label and uuid support in your"
83   echo "                                initrd"
84   echo "        --luks                  Include LUKS support"
85   echo "                                --> 'emerge cryptsetup-luks' with USE=-dynamic"
86   echo "  Internals"
87   echo "        --arch-override=<arch>  Force to arch instead of autodetect"
88   echo "        --cachedir=<dir>        Override the default cache location"
89   echo "        --tempdir=<dir>         Location of Genkernel's temporary directory"
90   echo "        --postclear             Clear all tmp files and caches after genkernel has run"
91   echo "  Output Settings"
92   echo "        --kernname=<...>        Tag the kernel and initrd with a name:"
93   echo "                                If not defined the option defaults to"
94   echo "                                'genkernel'"
95   echo "        --minkernpackage=<tbz2> File to output a .tar.bz2'd kernel and initrd:"
96   echo "                                No modules outside of the initrd will be"
97   echo "                                included..."
98   echo "        --modulespackage=<tbz2> File to output a .tar.bz2'd modules after the"
99   echo "                                callbacks have run"
100   echo "        --kerncache=<tbz2>      File to output a .tar.bz2'd kernel contents"
101   echo "                                of /lib/modules/ and the kernel config"
102   echo "                                NOTE: This is created before the callbacks"
103   echo "                                are run!"
104   echo "        --no-kernel-sources     This option is only valid if kerncache is"
105   echo "                                defined. If there is a valid kerncache no checks"
106   echo "                                will be made against a kernel source tree"
107   echo "        --initramfs-overlay=<dir>"
108   echo "                                Directory structure to include in the initramfs,"
109   echo "                                only available on 2.6 kernels that do not use"
110   echo "                                bootsplash"
111 }
112
113 usage() {
114   echo "Gentoo Linux Genkernel ${GK_V}"
115   echo "Usage: "
116   echo "        genkernel [options] all"
117   echo
118   echo 'Some useful options:'
119   echo '        --menuconfig            Run menuconfig after oldconfig'
120   echo '        --no-clean              Do not run make clean before compilation'
121   echo '        --no-mrproper           Do not run make mrproper before compilation,'
122   echo '                                this is implied by --no-clean.'
123   echo
124   echo 'For a detailed list of supported options and flags; issue:'
125   echo '        genkernel --help'
126 }
127
128 parse_opt() {
129         case "$1" in
130                 *\=*)
131                         echo "$1" | cut -f2- -d=
132                 ;;
133         esac
134 }
135
136 parse_cmdline() {
137         case "$*" in
138               --kernel-cc=*)
139                       CMD_KERNEL_CC=`parse_opt "$*"`
140                       print_info 2 "CMD_KERNEL_CC: $CMD_KERNEL_CC"
141               ;;
142               --kernel-ld=*)
143                       CMD_KERNEL_LD=`parse_opt "$*"`
144                       print_info 2 "CMD_KERNEL_LD: $CMD_KERNEL_LD"
145               ;;
146               --kernel-as=*)
147                       CMD_KERNEL_AS=`parse_opt "$*"`
148                       print_info 2 "CMD_KERNEL_AS: $CMD_KERNEL_AS"
149               ;;
150               --kernel-make=*)
151                       CMD_KERNEL_MAKE=`parse_opt "$*"`
152                       print_info 2 "CMD_KERNEL_MAKE: $CMD_KERNEL_MAKE"
153               ;;
154               --kernel-cross-compile=*)
155                       CMD_KERNEL_CROSS_COMPILE=`parse_opt "$*"`
156                       CMD_KERNEL_CROSS_COMPILE=$(echo ${CMD_KERNEL_CROSS_COMPILE}|sed -e 's/.*[^-]$/&-/g')
157                       print_info 2 "CMD_KERNEL_CROSS_COMPILE: $CMD_KERNEL_CROSS_COMPILE"
158               ;;
159               --utils-cc=*)
160                       CMD_UTILS_CC=`parse_opt "$*"`
161                       print_info 2 "CMD_UTILS_CC: $CMD_UTILS_CC"
162               ;;
163               --utils-ld=*)
164                       CMD_UTILS_LD=`parse_opt "$*"`
165                       print_info 2 "CMD_UTILS_LD: $CMD_UTILS_LD"
166               ;;
167               --utils-as=*)
168                       CMD_UTILS_AS=`parse_opt "$*"`
169                       print_info 2 "CMD_UTILS_AS: $CMD_UTILS_AS"
170               ;;
171               --utils-make=*)
172                       CMD_UTILS_MAKE=`parse_opt "$*"`
173                       print_info 2 "CMD_UTILS_MAKE: $CMD_UTILS_MAKE"
174               ;;
175               --utils-cross-compile=*)
176                       CMD_UTILS_CROSS_COMPILE=`parse_opt "$*"`
177                       CMD_UTILS_CROSS_COMPILE=$(echo ${CMD_UTILS_CROSS_COMPILE}|sed -e 's/.*[^-]$/&-/g')
178                       print_info 2 "CMD_UTILS_CROSS_COMPILE: $CMD_UTILS_CROSS_COMPILE"
179               ;;
180               --utils-arch=*)
181                       CMD_UTILS_ARCH=`parse_opt "$*"`
182                       print_info 2 "CMD_UTILS_ARCH: $CMD_ARCHOVERRIDE"
183               ;;
184               --makeopts=*)
185                       CMD_MAKEOPTS=`parse_opt "$*"`
186                       print_info 2 "CMD_MAKEOPTS: $CMD_MAKEOPTS"
187               ;;
188               --mountboot)
189                       CMD_MOUNTBOOT=1
190                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
191               ;;
192               --no-mountboot)
193                       CMD_MOUNTBOOT=0
194                       print_info 2 "CMD_MOUNTBOOT: $CMD_MOUNTBOOT"
195               ;;
196               --do-keymap-auto)
197                       CMD_DOKEYMAPAUTO=1
198                       print_info 2 "CMD_DOKEYMAPAUTO: $CMD_DOKEYMAPAUTO"
199               ;;
200               --evms2)
201                       CMD_EVMS2=1
202                       print_info 2 "CMD_EVMS2: $CMD_EVMS2"
203               ;;
204               --unionfs)
205                       echo
206                       print_warning 1 "WARNING: unionfs support is in active development and is not meant for general use."
207                       print_warning 1 "DISABLING UNIONFS SUPPORT AT THIS TIME."
208                       echo
209               ;;
210               --unionfs-dev)
211                       CMD_UNIONFS=1
212                       print_info 2 "CMD_UNIONFS: $CMD_UNIONFS"
213                       echo
214                       print_warning 1 "WARNING: unionfs support is in active development and is not meant for general use."
215                       print_warning 1 "Bug Reports without patches/fixes will be ignored."
216                       print_warning 1 "Use at your own risk as this could blow up your system."
217                       print_warning 1 "This code is subject to change at any time."
218                       echo
219               ;;
220               --lvm2)
221                       CMD_LVM2=1
222                       print_info 2 "CMD_LVM2: $CMD_LVM2"
223               ;;
224               --no-busybox)
225                       CMD_NO_BUSYBOX=1
226                       print_info 2 "CMD_NO_BUSYBOX: $CMD_NO_BUSYBOX"
227               ;;
228               --slowusb)
229                       CMD_SLOWUSB=1
230                       print_info 2 "CMD_SLOWUSB: $CMD_SLOWUSB"
231               ;;
232               --dmraid)
233                       if [ ! -e /usr/include/libdevmapper.h ]
234                       then
235                         echo 'Error: --dmraid requires device-mapper to be installed'
236                         echo '       on the host system; try "emerge device-mapper".'
237                         exit 1
238                       fi
239                       CMD_DMRAID=1
240                       print_info 2 "CMD_DMRAID: $CMD_DMRAID"
241               ;;
242               --bootloader=*)
243                       CMD_BOOTLOADER=`parse_opt "$*"`
244                       print_info 2 "CMD_BOOTLOADER: $CMD_BOOTLOADER"
245               ;;
246               --debuglevel=*)
247                       CMD_DEBUGLEVEL=`parse_opt "$*"`
248                       DEBUGLEVEL="${CMD_DEBUGLEVEL}"
249                       print_info 2 "CMD_DEBUGLEVEL: $CMD_DEBUGLEVEL"
250               ;;
251               --menuconfig)
252                       TERM_LINES=`stty -a | head -n 1 | cut -d\  -f5 | cut -d\; -f1`
253                       TERM_COLUMNS=`stty -a | head -n 1 | cut -d\  -f7 | cut -d\; -f1`
254
255                       if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]]
256                       then
257                         echo "Error: You need a terminal with at least 80 columns"
258                         echo "       and 19 lines for --menuconfig; try --nomenuconfig..."
259                         exit 1
260                       fi
261                       CMD_MENUCONFIG=1
262                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
263               ;;
264               --no-menuconfig)
265                       CMD_MENUCONFIG=0
266                       print_info 2 "CMD_MENUCONFIG: $CMD_MENUCONFIG"
267               ;;
268               --gconfig)
269                       CMD_GCONFIG=1
270                       print_info 2 "CMD_GCONFIG: $CMD_GCONFIG"
271               ;;
272               --xconfig)
273                       CMD_XCONFIG=1
274                       print_info 2 "CMD_XCONFIG: $CMD_XCONFIG"
275               ;;
276               --save-config)
277                       CMD_SAVE_CONFIG=1
278                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
279               ;;
280               --no-save-config)
281                       CMD_SAVE_CONFIG=0
282                       print_info 2 "CMD_SAVE_CONFIG: $CMD_SAVE_CONFIG"
283               ;;
284               --mrproper)
285                       CMD_MRPROPER=1
286                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
287               ;;
288               --no-mrproper)
289                       CMD_MRPROPER=0
290                       print_info 2 "CMD_MRPROPER: $CMD_MRPROPER"
291               ;;
292               --clean)
293                       CMD_CLEAN=1
294                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
295               ;;
296               --no-clean)
297                       CMD_CLEAN=0
298                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
299               ;;
300               --oldconfig)
301                       CMD_CLEAN=0
302                       CMD_OLDCONFIG=1
303                       print_info 2 "CMD_CLEAN: $CMD_CLEAN"
304                       print_info 2 "CMD_OLDCONFIG: $CMD_OLDCONFIG"
305               ;;
306               --bootsplash=*)
307                       CMD_BOOTSPLASH=1
308                       CMD_GENSPLASH=0
309                       BOOTSPLASH_THEME=`parse_opt "$*"`
310                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
311                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
312                       print_info 2 "BOOTSPLASH_THEME: $BOOTSPLASH_THEME"
313               ;;
314               --bootsplash)
315                       CMD_BOOTSPLASH=1
316                       CMD_GENSPLASH=0
317                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
318                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
319               ;;
320               --no-bootsplash)
321                       CMD_BOOTSPLASH=0
322                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
323               ;;
324               --gensplash=*)
325                       CMD_GENSPLASH=1
326                       CMD_BOOTSPLASH=0
327                       GENSPLASH_THEME=`parse_opt "$*"`
328                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
329                       print_info 2 "GENSPLASH_THEME: $GENSPLASH_THEME"
330                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
331               ;;
332               --gensplash)
333                       CMD_GENSPLASH=1
334                       CMD_BOOTSPLASH=0
335                       GENSPLASH_THEME='default'
336                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
337                       print_info 2 "CMD_BOOTSPLASH: $CMD_BOOTSPLASH"
338               ;;
339               --no-gensplash)
340                       CMD_GENSPLASH=0
341                       print_info 2 "CMD_GENSPLASH: $CMD_GENSPLASH"
342               ;;
343               --gensplash-res=*)
344                       GENSPLASH_RES=`parse_opt "$*"`
345                       print_info 2 "GENSPLASH_RES: $GENSPLASH_RES"
346               ;;
347               --install)
348                       CMD_NOINSTALL=0
349                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
350               ;;
351               --no-install)
352                       CMD_NOINSTALL=1
353                       print_info 2 "CMD_NOINSTALL: $CMD_NOINSTALL"
354               ;;
355               --no-initrdmodules)
356                       CMD_NOINITRDMODULES=1
357                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
358               ;;
359               --udev)
360                       echo
361                       echo
362                       print_info 1 "--udev is deprecated and no longer necessary as udev is on by default"
363                       sleep 3
364                       echo
365                       echo
366                       print_info 2 "CMD_UDEV: $CMD_UDEV"
367               ;;
368               --no-udev)
369                       CMD_NO_UDEV=1
370                       print_info 2 "CMD_NO_UDEV: $CMD_NO_UDEV"
371               ;;
372               --no-devfs)
373                       CMD_NO_DEVFS=1
374                       print_info 2 "CMD_NO_DEVFS: $CMD_NO_DEVFS"
375               ;;
376               --callback=*)
377                       CMD_CALLBACK=`parse_opt "$*"`
378                       print_info 2 "CMD_CALLBACK: $CMD_CALLBACK/$*"
379               ;;
380               --static)
381                       CMD_STATIC=1
382                       print_info 2 "CMD_STATIC: $CMD_STATIC"
383               ;;
384               --initramfs)
385                       CMD_INITRAMFS=1
386                       print_info 2 "CMD_INITRAMFS: $CMD_INITRAMFS"
387               ;;
388               --tempdir=*)
389                       TMPDIR=`parse_opt "$*"`
390                       TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$
391                       print_info 2 "TMPDIR: $TMPDIR"
392                       print_info 2 "TEMP: $TEMP"
393               ;; 
394               --postclear)
395                       CMD_POSTCLEAR=1
396                       print_info 2 "CMD_POSTCLEAR: $CMD_POSTCLEAR"
397               ;; 
398               --arch-override=*)
399                       CMD_ARCHOVERRIDE=`parse_opt "$*"`
400                       print_info 2 "CMD_ARCHOVERRIDE: $CMD_ARCHOVERRIDE"
401               ;;
402               --color)
403                       CMD_USECOLOR=1
404                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
405               ;;
406               --no-color)
407                       CMD_USECOLOR=0
408                       print_info 2 "CMD_USECOLOR: $CMD_USECOLOR"
409               ;;
410               --debugfile=*)
411                       CMD_DEBUGFILE=`parse_opt "$*"`
412                       DEBUGFILE=`parse_opt "$*"`
413                       print_info 2 "CMD_DEBUGFILE: $CMD_DEBUGFILE"
414                       print_info 2 "DEBUGFILE: $CMD_DEBUGFILE"
415               ;;
416               --kerneldir=*)
417                       CMD_KERNELDIR=`parse_opt "$*"`
418                       print_info 2 "CMD_KERNELDIR: $CMD_KERNELDIR"
419               ;;
420               --kernel-config=*)
421                       CMD_KERNEL_CONFIG=`parse_opt "$*"`
422                       print_info 2 "CMD_KERNEL_CONFIG: $CMD_KERNEL_CONFIG"
423               ;;
424               --module-prefix=*)
425                       CMD_INSTALL_MOD_PATH=`parse_opt "$*"`
426                       print_info 2 "CMD_INSTALL_MOD_PATH: $CMD_INSTALL_MOD_PATH"
427               ;;
428               --cachedir=*)
429                       CACHE_DIR=`parse_opt "$*"`
430                       print_info 2 "CACHE_DIR: $CACHE_DIR"
431               ;;
432               --minkernpackage=*)
433                       CMD_MINKERNPACKAGE=`parse_opt "$*"`
434                       print_info 2 "MINKERNPACKAGE: $CMD_MINKERNPACKAGE"
435               ;;
436               --modulespackage=*)
437                       CMD_MODULESPACKAGE=`parse_opt "$*"`
438                       print_info 2 "MODULESPACKAGE: $CMD_MODULESPACKAGE"
439               ;;
440               --kerncache=*)
441                       CMD_KERNCACHE=`parse_opt "$*"`
442                       print_info 2 "KERNCACHE: $CMD_KERNCACHE"
443               ;;
444               --kernname=*)
445                       CMD_KERNNAME=`parse_opt "$*"`
446                       print_info 2 "KERNNAME: $CMD_KERNNAME"
447               ;;
448               --symlink)
449                       CMD_SYMLINK=1
450                       print_info 2 "CMD_SYMLINK: $CMD_SYMLINK"
451               ;;
452               --no-kernel-sources)
453                       CMD_NO_KERNEL_SOURCES=1
454                       print_info 2 "CMD_NO_KERNEL_SOURCES: $CMD_NO_KERNEL_SOURCES"
455               ;;
456               --initramfs-overlay=*)
457                       CMD_INITRAMFS_OVERLAY=`parse_opt "$*"`
458                       print_info 2 "CMD_INITRAMFS_OVERLAY: $CMD_INITRAMFS_OVERLAY"
459               ;;
460               --linuxrc=*)
461                         CMD_LINUXRC=`parse_opt "$*"`
462                         print_info 2 "CMD_LINUXRC: $CMD_LINUXRC"
463               ;;
464               --genzimage)
465                         KERNEL_MAKE_DIRECTIVE_2='zImage.initrd'
466                         KERNEL_BINARY_2='arch/ppc/boot/images/zImage.initrd.chrp'
467                         GENERATE_Z_IMAGE=1
468                         print_info 2 "GENERATE_Z_IMAGE: $GENERATE_Z_IMAGE"
469               ;;
470               --disklabel)
471                       CMD_DISKLABEL=1
472                       print_info 2 "CMD_DISKLABEL: $CMD_DISKLABEL"
473               ;;
474               --luks)
475                       CMD_LUKS=1
476                       print_info 2 "CMD_LUKS: $CMD_LUKS"
477               ;;
478               all)
479                       BUILD_KERNEL=1
480                       BUILD_MODULES=1
481                       BUILD_INITRD=1
482               ;;
483               initrd)
484                       BUILD_INITRD=1
485               ;;
486               kernel)
487                       BUILD_KERNEL=1
488                       BUILD_MODULES=1
489                       BUILD_INITRD=0
490               ;;
491               bzImage)
492                       BUILD_KERNEL=1
493                       BUILD_MODULES=0
494                       BUILD_INITRD=1
495                       CMD_NOINITRDMODULES=1
496                       print_info 2 "CMD_NOINITRDMODULES: $CMD_NOINITRDMODULES"
497               ;;
498               --help)
499                       longusage
500                       exit 1
501               ;;
502               --version)
503                       echo "${GK_V}"
504                       exit 0
505               ;;
506               *)
507                       echo "Error: Unknown option '$*'!"
508                       exit 1
509               ;;
510         esac
511 }