Changed all instances of EVMS2/LVM2 to EVMS/LVM, respectively. This will keep everyt...
[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 "        --gensplash             Install gensplash support into bzImage"
34   echo "        --no-gensplash          Do not use gensplash"
35   echo "        --install               Install the kernel after building"
36   echo "        --no-install            Do not install the kernel after building"
37   echo "        --symlink               Manage symlinks in /boot for installed images"
38   echo "        --no-symlink            Do not manage symlinks"
39   echo "        --no-initrdmodules      Don't copy any modules to the initrd"
40   echo "        --callback=<...>        Run the specified arguments after the"
41   echo "                                kernel and modules have been compiled"
42   echo "        --static                Build a static (monolithic kernel)."
43   echo "        --initramfs             Builds initramfs before kernel and embeds it"
44   echo "                                into the kernel."
45   echo "  Kernel settings"
46   echo "        --kerneldir=<dir>       Location of the kernel sources"
47   echo "        --kernel-config=<file>  Kernel configuration file to use for compilation"
48   echo "        --module-prefix=<dir>   Prefix to kernel module destination, modules"
49   echo "                                will be installed in <prefix>/lib/modules"
50   echo "  Low-Level Compile settings"
51   echo "        --kernel-cc=<compiler>  Compiler to use for kernel (e.g. distcc)"
52   echo "        --kernel-as=<assembler> Assembler to use for kernel"
53   echo "        --kernel-ld=<linker>    Linker to use for kernel"
54   echo "        --kernel-cross-compile=<cross var> CROSS_COMPILE kernel variable"
55   echo "        --kernel-make=<makeprg> GNU Make to use for kernel"
56   echo "        --utils-cc=<compiler>   Compiler to use for utilities"
57   echo "        --utils-as=<assembler>  Assembler to use for utils"
58   echo "        --utils-ld=<linker>     Linker to use for utils"
59   echo "        --utils-make=<makeprog> GNU Make to use for utils"
60   echo "        --utils-cross-compile=<cross var> CROSS_COMPILE utils variable"
61   echo "        --utils-arch=<arch>     Force to arch for utils only instead of"
62   echo "                                autodetect."
63   echo "        --makeopts=<makeopts>   Make options such as -j2, etc..."
64   echo "        --mountboot             Mount BOOTDIR automatically if mountable"
65   echo "        --no-mountboot          Don't mount BOOTDIR automatically"  
66   echo "        --bootdir=<dir>         Set the location of the boot-directory, default is /boot"
67   echo "  Initialization"
68   echo "        --gensplash=<theme>     Force gensplash using <theme>"
69   echo "        --gensplash-res=<res>   Select gensplash resolutions"
70   echo "        --do-keymap-auto        Forces keymap selection at boot"
71   echo "        --evms                  Include EVMS support"
72   echo "                                --> 'emerge evms' in the host operating system"
73   echo "                                first"
74   echo "        --evms2                 Include EVMS support"
75   echo "                                --> 'emerge evms' in the host operating system"
76   echo "                                first"
77   echo "        --lvm                   Include LVM support"
78   echo "        --lvm2                  Include LVM support"
79   echo "        --dmraid                Include DMRAID support"
80   echo "        --slowusb               Enables extra pauses for slow USB CD boots"
81   echo "        --bootloader=grub       Add new kernel to GRUB configuration"
82   echo "        --linuxrc=<file>        Specifies a user created linuxrc"
83   echo "        --disklabel             Include disk label and uuid support in your"
84   echo "                                initrd"
85   echo "        --luks                  Include LUKS support"
86   echo "                                --> 'emerge cryptsetup-luks' with USE=-dynamic"
87   echo "  Internals"
88   echo "        --arch-override=<arch>  Force to arch instead of autodetect"
89   echo "        --cachedir=<dir>        Override the default cache location"
90   echo "        --tempdir=<dir>         Location of Genkernel's temporary directory"
91   echo "        --postclear             Clear all tmp files and caches after genkernel has run"
92   echo "  Output Settings"
93   echo "        --kernname=<...>        Tag the kernel and initrd with a name:"
94   echo "                                If not defined the option defaults to"
95   echo "                                'genkernel'"
96   echo "        --minkernpackage=<tbz2> File to output a .tar.bz2'd kernel and initrd:"
97   echo "                                No modules outside of the initrd will be"
98   echo "                                included..."
99   echo "        --modulespackage=<tbz2> File to output a .tar.bz2'd modules after the"
100   echo "                                callbacks have run"
101   echo "        --kerncache=<tbz2>      File to output a .tar.bz2'd kernel contents"
102   echo "                                of /lib/modules/ and the kernel config"
103   echo "                                NOTE: This is created before the callbacks"
104   echo "                                are run!"
105   echo "        --no-kernel-sources     This option is only valid if kerncache is"
106   echo "                                defined. If there is a valid kerncache no checks"
107   echo "                                will be made against a kernel source tree"
108   echo "        --initramfs-overlay=<dir>"
109   echo "                                Directory structure to include in the initramfs,"
110   echo "                                only available on 2.6 kernels"
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               --bootdir=*)
197                       BOOTDIR=`parse_opt "$*"`
198                       print_info 2 "BOOTDIR: ${BOOTDIR}"
199               ;;
200               --do-keymap-auto)
201                       CMD_DOKEYMAPAUTO=1
202                       print_info 2 "CMD_DOKEYMAPAUTO: ${CMD_DOKEYMAPAUTO}"
203               ;;
204               --evms)
205                       CMD_EVMS=1
206                       print_info 2 "CMD_EVMS: ${CMD_EVMS}"
207               ;;
208               --evms2)
209                       CMD_EVMS=1
210                       print_info 2 "CMD_EVMS: ${CMD_EVMS}"
211                           echo
212                           print_warning 1 "Please use --evms, as --evms2 is deprecated."
213               ;;
214               --unionfs)
215                       CMD_UNIONFS=1
216                       print_info 2 "CMD_UNIONFS: ${CMD_UNIONFS}"
217                       echo
218                       print_warning 1 "WARNING: unionfs support is in active development and is not meant for general"
219                           print_warning 1 "use."
220                       print_warning 1 "Bug Reports without patches/fixes will be ignored."
221                       print_warning 1 "Use at your own risk as this could blow up your system."
222                       print_warning 1 "This code is subject to change at any time."
223                       echo
224               ;;
225               --lvm)
226                       CMD_LVM=1
227                       print_info 2 "CMD_LVM: ${CMD_LVM}"
228               ;;
229               --lvm2)
230                       CMD_LVM=1
231                       print_info 2 "CMD_LVM: ${CMD_LVM}"
232                           echo
233                           print_warning 1 "Please use --lvm, as --lvm2 is deprecated."
234               ;;
235               --no-busybox)
236                       CMD_NO_BUSYBOX=1
237                       print_info 2 "CMD_NO_BUSYBOX: ${CMD_NO_BUSYBOX}"
238               ;;
239               --slowusb)
240                       CMD_SLOWUSB=1
241                       print_info 2 "CMD_SLOWUSB: ${CMD_SLOWUSB}"
242               ;;
243               --dmraid)
244                       if [ ! -e /usr/include/libdevmapper.h ]
245                       then
246                         echo 'Error: --dmraid requires device-mapper to be installed'
247                         echo '       on the host system; try "emerge device-mapper".'
248                         exit 1
249                       fi
250                       CMD_DMRAID=1
251                       print_info 2 "CMD_DMRAID: ${CMD_DMRAID}"
252               ;;
253               --bootloader=*)
254                       CMD_BOOTLOADER=`parse_opt "$*"`
255                       print_info 2 "CMD_BOOTLOADER: ${CMD_BOOTLOADER}"
256               ;;
257               --debuglevel=*)
258                       CMD_DEBUGLEVEL=`parse_opt "$*"`
259                       DEBUGLEVEL="${CMD_DEBUGLEVEL}"
260                       print_info 2 "CMD_DEBUGLEVEL: ${CMD_DEBUGLEVEL}"
261               ;;
262               --menuconfig)
263                       TERM_LINES=`stty -a | head -n 1 | cut -d\  -f5 | cut -d\; -f1`
264                       TERM_COLUMNS=`stty -a | head -n 1 | cut -d\  -f7 | cut -d\; -f1`
265
266                       if [[ TERM_LINES -lt 19 || TERM_COLUMNS -lt 80 ]]
267                       then
268                         echo "Error: You need a terminal with at least 80 columns"
269                         echo "       and 19 lines for --menuconfig; try --nomenuconfig..."
270                         exit 1
271                       fi
272                       CMD_MENUCONFIG=1
273                       print_info 2 "CMD_MENUCONFIG: ${CMD_MENUCONFIG}"
274               ;;
275               --no-menuconfig)
276                       CMD_MENUCONFIG=0
277                       print_info 2 "CMD_MENUCONFIG: ${CMD_MENUCONFIG}"
278               ;;
279               --gconfig)
280                       CMD_GCONFIG=1
281                       print_info 2 "CMD_GCONFIG: ${CMD_GCONFIG}"
282               ;;
283               --xconfig)
284                       CMD_XCONFIG=1
285                       print_info 2 "CMD_XCONFIG: ${CMD_XCONFIG}"
286               ;;
287               --save-config)
288                       CMD_SAVE_CONFIG=1
289                       print_info 2 "CMD_SAVE_CONFIG: ${CMD_SAVE_CONFIG}"
290               ;;
291               --no-save-config)
292                       CMD_SAVE_CONFIG=0
293                       print_info 2 "CMD_SAVE_CONFIG: ${CMD_SAVE_CONFIG}"
294               ;;
295               --mrproper)
296                       CMD_MRPROPER=1
297                       print_info 2 "CMD_MRPROPER: ${CMD_MRPROPER}"
298               ;;
299               --no-mrproper)
300                       CMD_MRPROPER=0
301                       print_info 2 "CMD_MRPROPER: ${CMD_MRPROPER}"
302               ;;
303               --clean)
304                       CMD_CLEAN=1
305                       print_info 2 "CMD_CLEAN: ${CMD_CLEAN}"
306               ;;
307               --no-clean)
308                       CMD_CLEAN=0
309                       print_info 2 "CMD_CLEAN: ${CMD_CLEAN}"
310               ;;
311               --oldconfig)
312                       CMD_CLEAN=0
313                       CMD_OLDCONFIG=1
314                       print_info 2 "CMD_CLEAN: ${CMD_CLEAN}"
315                       print_info 2 "CMD_OLDCONFIG: ${CMD_OLDCONFIG}"
316               ;;
317               --gensplash=*)
318                       CMD_GENSPLASH=1
319                       GENSPLASH_THEME=`parse_opt "$*"`
320                       print_info 2 "CMD_GENSPLASH: ${CMD_GENSPLASH}"
321                       print_info 2 "GENSPLASH_THEME: ${GENSPLASH_THEME}"
322               ;;
323               --gensplash)
324                       CMD_GENSPLASH=1
325                       GENSPLASH_THEME='default'
326                       print_info 2 "CMD_GENSPLASH: ${CMD_GENSPLASH}"
327               ;;
328               --no-gensplash)
329                       CMD_GENSPLASH=0
330                       print_info 2 "CMD_GENSPLASH: ${CMD_GENSPLASH}"
331               ;;
332               --gensplash-res=*)
333                       GENSPLASH_RES=`parse_opt "$*"`
334                       print_info 2 "GENSPLASH_RES: ${GENSPLASH_RES}"
335               ;;
336               --install)
337                       CMD_NOINSTALL=0
338                       print_info 2 "CMD_NOINSTALL: ${CMD_NOINSTALL}"
339               ;;
340               --no-install)
341                       CMD_NOINSTALL=1
342                       print_info 2 "CMD_NOINSTALL: ${CMD_NOINSTALL}"
343               ;;
344               --no-initrdmodules)
345                       CMD_NOINITRDMODULES=1
346                       print_info 2 "CMD_NOINITRDMODULES: ${CMD_NOINITRDMODULES}"
347               ;;
348               --callback=*)
349                       CMD_CALLBACK=`parse_opt "$*"`
350                       print_info 2 "CMD_CALLBACK: ${CMD_CALLBACK}/$*"
351               ;;
352               --static)
353                       CMD_STATIC=1
354                       print_info 2 "CMD_STATIC: ${CMD_STATIC}"
355               ;;
356               --initramfs)
357                       CMD_INITRAMFS=1
358                       print_info 2 "CMD_INITRAMFS: ${CMD_INITRAMFS}"
359               ;;
360               --tempdir=*)
361                       TMPDIR=`parse_opt "$*"`
362                       TEMP=${TMPDIR}/$RANDOM.$RANDOM.$RANDOM.$$
363                       print_info 2 "TMPDIR: ${TMPDIR}"
364                       print_info 2 "TEMP: ${TEMP}"
365               ;; 
366               --postclear)
367                       CMD_POSTCLEAR=1
368                       print_info 2 "CMD_POSTCLEAR: ${CMD_POSTCLEAR}"
369               ;; 
370               --arch-override=*)
371                       CMD_ARCHOVERRIDE=`parse_opt "$*"`
372                       print_info 2 "CMD_ARCHOVERRIDE: ${CMD_ARCHOVERRIDE}"
373               ;;
374               --color)
375                       USECOLOR=1
376                       print_info 2 "USECOLOR: ${USECOLOR}"
377                       setColorVars
378               ;;
379               --no-color)
380                       USECOLOR=0
381                       print_info 2 "USECOLOR: ${USECOLOR}"
382                       setColorVars
383               ;;
384               --debugfile=*)
385                       CMD_DEBUGFILE=`parse_opt "$*"`
386                       DEBUGFILE=`parse_opt "$*"`
387                       print_info 2 "CMD_DEBUGFILE: ${CMD_DEBUGFILE}"
388                       print_info 2 "DEBUGFILE: ${CMD_DEBUGFILE}"
389               ;;
390               --kerneldir=*)
391                       CMD_KERNELDIR=`parse_opt "$*"`
392                       print_info 2 "CMD_KERNELDIR: ${CMD_KERNELDIR}"
393               ;;
394               --kernel-config=*)
395                       CMD_KERNEL_CONFIG=`parse_opt "$*"`
396                       print_info 2 "CMD_KERNEL_CONFIG: ${CMD_KERNEL_CONFIG}"
397               ;;
398               --module-prefix=*)
399                       CMD_INSTALL_MOD_PATH=`parse_opt "$*"`
400                       print_info 2 "CMD_INSTALL_MOD_PATH: ${CMD_INSTALL_MOD_PATH}"
401               ;;
402               --cachedir=*)
403                       CACHE_DIR=`parse_opt "$*"`
404                       print_info 2 "CACHE_DIR: ${CACHE_DIR}"
405               ;;
406               --minkernpackage=*)
407                       CMD_MINKERNPACKAGE=`parse_opt "$*"`
408                       print_info 2 "MINKERNPACKAGE: ${CMD_MINKERNPACKAGE}"
409               ;;
410               --modulespackage=*)
411                       CMD_MODULESPACKAGE=`parse_opt "$*"`
412                       print_info 2 "MODULESPACKAGE: ${CMD_MODULESPACKAGE}"
413               ;;
414               --kerncache=*)
415                       CMD_KERNCACHE=`parse_opt "$*"`
416                       print_info 2 "KERNCACHE: ${CMD_KERNCACHE}"
417               ;;
418               --kernname=*)
419                       CMD_KERNNAME=`parse_opt "$*"`
420                       print_info 2 "KERNNAME: ${CMD_KERNNAME}"
421               ;;
422               --symlink)
423                       CMD_SYMLINK=1
424                       print_info 2 "CMD_SYMLINK: ${CMD_SYMLINK}"
425               ;;
426               --no-symlink)
427                       CMD_SYMLINK=0
428                       print_info 2 "CMD_SYMLINK: ${CMD_SYMLINK}"
429               ;;
430               --no-kernel-sources)
431                       CMD_NO_KERNEL_SOURCES=1
432                       print_info 2 "CMD_NO_KERNEL_SOURCES: ${CMD_NO_KERNEL_SOURCES}"
433               ;;
434               --initramfs-overlay=*)
435                       CMD_INITRAMFS_OVERLAY=`parse_opt "$*"`
436                       print_info 2 "CMD_INITRAMFS_OVERLAY: ${CMD_INITRAMFS_OVERLAY}"
437               ;;
438               --linuxrc=*)
439                         CMD_LINUXRC=`parse_opt "$*"`
440                         print_info 2 "CMD_LINUXRC: ${CMD_LINUXRC}"
441               ;;
442               --genzimage)
443                         KERNEL_MAKE_DIRECTIVE_2='zImage.initrd'
444                         KERNEL_BINARY_2='arch/powerpc/boot/zImage.initrd'
445                         GENERATE_Z_IMAGE=1
446                         print_info 2 "GENERATE_Z_IMAGE: ${GENERATE_Z_IMAGE}"
447               ;;
448               --disklabel)
449                       CMD_DISKLABEL=1
450                       print_info 2 "CMD_DISKLABEL: ${CMD_DISKLABEL}"
451               ;;
452               --luks)
453                       CMD_LUKS=1
454                       print_info 2 "CMD_LUKS: ${CMD_LUKS}"
455               ;;
456               all)
457                       BUILD_KERNEL=1
458                       BUILD_MODULES=1
459                       BUILD_INITRD=1
460               ;;
461               initrd)
462                       BUILD_INITRD=1
463               ;;
464               kernel)
465                       BUILD_KERNEL=1
466                       BUILD_MODULES=1
467                       BUILD_INITRD=0
468               ;;
469               bzImage)
470                       BUILD_KERNEL=1
471                       BUILD_MODULES=0
472                       BUILD_INITRD=1
473                       CMD_NOINITRDMODULES=1
474                       print_info 2 "CMD_NOINITRDMODULES: ${CMD_NOINITRDMODULES}"
475               ;;
476               --help)
477                       longusage
478                       exit 1
479               ;;
480               --version)
481                       echo "${GK_V}"
482                       exit 0
483               ;;
484               *)
485                       echo "Error: Unknown option '$*'!"
486                       exit 1
487               ;;
488         esac
489 }