Bootoption hostname: use grml-hostname to adjust configuration files on the fly.
[grml-autoconfig.git] / autoconfig.functions
1 #!/bin/zsh
2 # Filename:      autoconfig.functions
3 # Purpose:       basic system configuration and hardware setup for grml system
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8
9 # {{{ path, variables, signals, umask, zsh
10 export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
11 DEBUG="/dev/null"
12 KERNEL="$(uname -r)"
13 ARCH="$(uname -m)"
14 umask 022
15
16 # old linuxrc version:
17 [ -d /cdrom ]      && export LIVECD_PATH=/cdrom
18 # new initramfs layout:
19 [ -d /live/image ] && export LIVECD_PATH=/live/image
20
21 # Ignore these signals in non-interactive mode: INT, TERM, SEGV
22 [ -z "$PS1" ] && trap "" 2 3 11
23
24 # zsh stuff
25 iszsh(){
26 if [ -n "$ZSH_VERSION" ] ; then
27   return 0
28 else
29   return 1
30 fi
31 }
32 # avoid 'no matches found: ...'
33 iszsh && setopt no_nomatch # || echo "Warning: not running under zsh!"
34 # }}}
35
36 # {{{ Read in boot parameters
37 if [ -z "$CMDLINE" ]; then
38   # if CMDLINE was set from the outside, we're debugging.
39   # otherwise, take CMDLINE from Kernel and config files.
40   CMDLINE="$(cat /proc/cmdline)"
41   [ -d /cdrom/bootparams/ ]      && CMDLINE="$CMDLINE $(cat /cdrom/bootparams/* | tr '\n' ' ')"
42   [ -d /live/image/bootparams/ ] && CMDLINE="$CMDLINE $(cat /live/image/bootparams/* | tr '\n' ' ')"
43 fi
44 # }}}
45
46 ### {{{ Utility Functions
47
48 # Get a bootoption's parameter: read boot command line and either
49 # echo last parameter's argument or return false.
50 getbootparam(){
51   local line
52   local ws
53   ws='   '
54   line=" $CMDLINE "
55   case "$line" in
56     *[${ws}]"$1="*)
57       result="${line##*[$ws]$1=}"
58       result="${result%%[$ws]*}"
59       echo "$result"
60       return 0 ;;
61     *) # no match?
62       return 1 ;;
63   esac
64 }
65
66 # Check boot commandline for specified option
67 checkbootparam(){
68   [ -n "$1" ] || ( echo "Error: missing argument to checkbootparam()" ; return 1 )
69   local line
70   local ws
71   ws='   '
72   line=" $CMDLINE "
73   case "$line" in
74     *[${ws}]"$1"=*|*[${ws}]"$1"[${ws}]*)
75       return 0 ;;
76     *)
77       return 1 ;;
78   esac
79 }
80
81 # Check if currently using a framebuffer
82 hasfb() {
83     [ -e /dev/fb0 ] && return 0 || return 1
84 }
85
86 # Check wheter a configuration variable (like $CONFIG_TOHD) is
87 # enabled or not
88 checkvalue(){
89   case "$1" in
90     [yY][eE][sS])     return 0 ;; # it's set to 'yes'
91     [tT][rR][uU][eE]) return 0 ;; # it's set to 'true'
92                    *) return 1 ;; # default
93   esac
94 }
95
96 # Are we using grml-small?
97 checkgrmlsmall(){
98   grep -q small /etc/grml_version 2>>$DEBUG && return 0 || return 1
99 }
100
101 # execute flite only if it's present
102 flitewrapper() {
103    [ -x /usr/bin/flite ] && flite -o play -t "$*"
104 }
105 ### }}}
106
107 # {{{ filesystems (proc, pts, sys) and fixes
108 mount_proc(){
109   [ -f /proc/version ] || mount -t proc /proc /proc 2>/dev/null
110 }
111
112 mount_pts(){
113   grep -q "/dev/pts" /proc/mounts || mount -t devpts /dev/pts /dev/pts 2>/dev/null
114 }
115
116 mount_sys(){
117   [ -d /sys/devices ] || mount -t sysfs /sys /sys 2>/dev/null
118 }
119 # }}}
120
121 # {{{ Check if we are running in live mode or from HD
122 INSTALLED=""
123 [ -e /etc/grml_cd ] || INSTALLED="yes"
124
125 # testcd
126 TESTCD=""
127 checkbootparam 'testcd' >>$DEBUG 2>&1 && TESTCD="yes"
128 # }}}
129
130 # {{{ source lsb-functions , color handling
131 if checkbootparam 'nocolor'; then
132   RC_NOCOLOR=yes
133   . /etc/grml/lsb-functions
134   einfo "Disabling colors in bootsequence as requested on commandline." ; eend 0
135 else
136   . /etc/grml/lsb-functions
137   . /etc/grml_colors
138 fi
139 # }}}
140
141 # {{{ debug
142 config_debug(){
143  checkbootparam 'debug'            && BOOTDEBUG="yes"
144  checkbootparam "BOOT_IMAGE=debug" && BOOTDEBUG="yes"
145
146  rundebugshell(){
147   if [ -n "$BOOTDEBUG" ]; then
148      einfo "Starting intermediate shell stage $stage as requested by \"debug\" option."
149      if [ grep -q "debug=noscreen" "$CMDLINE" ] ; then
150         einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
151         einfo "Just exit the shell to continue boot process..."
152         /bin/zsh
153      else
154         eindent
155         if [ -r /etc/grml/screenrc ] ; then
156            einfo "Starting GNU screen to be able to use a full featured shell environment."
157            einfo "Just exit the shells (and therefore screen) to continue boot process..."
158            /bin/zsh -c "screen -c /etc/grml/screenrc"
159         else
160            einfo "Notice that the shell does not provide job handling: ctrl-z, bg and fg won't work!"
161            einfo "Just exit the shell to continue boot process..."
162            /bin/zsh
163         fi
164         eoutdent
165      fi
166   fi
167  }
168 }
169 # }}}
170
171 # {{{ log
172 config_log(){
173 if checkbootparam 'log' || checkbootparam 'debug' ; then
174    export DEBUG="/tmp/grml.log.`date +%Y%m%d`"
175    touch $DEBUG
176    einfo "Bootparameter log found. Log files: ${DEBUG} and /var/log/boot"
177    eindent
178      einfo "Starting bootlogd." # known to be *very* unreliable :(
179      bootlogd -r -c 1>>$DEBUG 2>&1 ; eend $?
180    eoutdent
181 else
182    DEBUG="/dev/null"
183 fi
184 }
185 # }}}
186
187 # {{{ set firmware timeout via bootparam
188 config_fwtimeout(){
189  if checkbootparam 'fwtimeout' ; then
190    TIMEOUT="$(getbootparam 'fwtimeout' 2>>$DEBUG)"
191    einfo "Bootoption fwtimeout found. (Re)Loading firmware_class module."
192    rmmod firmware_class 1>>$DEBUG 2>&1
193    modprobe firmware_class ; eend $?
194  fi
195  if [ -z "$TIMEOUT" ] ; then
196    TIMEOUT="100" # linux kernel default: 10
197  fi
198  if [ -f /sys/class/firmware/timeout ] ; then
199    einfo "Setting timeout for firmware loading to ${TIMEOUT}."
200    echo 100 > /sys/class/firmware/timeout ; eend $?
201  fi
202 }
203 # }}}
204
205 ### {{{ language configuration / localization
206 config_language(){
207
208  einfo "Activating language settings:"
209  eindent
210
211  # people can specify $LANGUAGE and $CONSOLEFONT in a config file:
212  [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
213
214  grep -q ' lang=.*-utf8' /proc/cmdline && UTF8='yes' || UTF8=''
215
216  # check for bootoption which overrides config from /etc/grml/autoconfig:
217  BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
218  [ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"
219
220  # set default to 'en' in live-cd mode if $LANGUAGE is not yet set:
221  if [ -z "$INSTALLED" ] ; then
222     [ -n "$LANGUAGE" ] || LANGUAGE='en'
223  fi
224
225  if [ -x /usr/sbin/grml-setlang ] ; then
226    # if bootoption lang is used update /etc/default/locale accordingly
227    if [ -n "$BOOT_LANGUAGE" ] ; then
228      checkgrmlsmall && /usr/sbin/grml-setlang "POSIX" || /usr/sbin/grml-setlang "$LANGUAGE"
229    # otherwise default to lang=en
230    else
231      checkgrmlsmall && /usr/sbin/grml-setlang "POSIX" || /usr/sbin/grml-setlang "en"
232    fi
233  fi
234
235  # set console font
236  if [ -z "$CONSOLEFONT" ] ; then
237     if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
238        # [ -n "$UTF8" ] && CONSOLEFONT='LatArCyrHeb-16' || CONSOLEFONT='Lat15-Terminus16'
239        # if [ -r /usr/share/consolefonts/Lat15-Terminus16.psf.gz ] ; then
240        if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
241           CONSOLEFONT='Uni3-Terminus16'
242        else
243           ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-terminus." ; eend 1
244        fi
245        if ! hasfb ; then
246           CONSOLEFONT='Lat15-Terminus16'
247        fi
248     fi
249  fi
250
251  # export it now, so error messages get translated, too
252  if checkgrmlsmall ; then
253     export LANG='C' # grml-small does not provide any further locales
254  else
255     [ -r /etc/default/locale ] && . /etc/default/locale
256     export LANG LANGUAGE
257  fi
258
259  # configure keyboard layout, read in already set values first:
260  [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
261
262  # now allow keyboard override by boot commandline for later use:
263  KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
264  [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
265  # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
266  [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
267  [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
268
269  # modify /etc/sysconfig/keyboard only in live-cd mode:
270  if [ -z "$INSTALLED" ] ; then
271
272    local LANGUAGE="$BOOT_LANGUAGE"
273    . /etc/grml/language-functions
274    # allow setting xkeyboard explicitly different than console keyboard
275    KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
276    if [ -n "$KXKEYBOARD" ]; then
277       XKEYBOARD="$KXKEYBOARD"
278       KDEKEYBOARD="$KXKEYBOARD"
279    elif [ -n "$KKEYBOARD" ]; then
280       XKEYBOARD="$KKEYBOARD"
281       KDEKEYBOARD="$KKEYBOARD"
282    fi
283
284    # duplicate of previous code to make sure /etc/grml/language-functions
285    # does not overwrite our values....
286    # now allow keyboard override by boot commandline for later use:
287    KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
288    [ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
289    # notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
290    [[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
291    [[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys
292
293    # write keyboard related variables to file for later use
294    [ -d /etc/sysconfig ] || mkdir /etc/sysconfig
295    if ! [ -e /etc/sysconfig/keyboard ] ; then
296       echo "KEYTABLE=\"$KEYTABLE\""          > /etc/sysconfig/keyboard
297       echo "XKEYBOARD=\"$XKEYBOARD\""       >> /etc/sysconfig/keyboard
298       echo "KDEKEYBOARD=\"$KDEKEYBOARD\""   >> /etc/sysconfig/keyboard
299       echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
300    fi
301  fi
302
303  [ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
304
305  # activate unicode console if running within utf8 environment
306  if [ -r /etc/default/locale ] ; then
307     if grep -q "LANG=.*UTF" /etc/default/locale ; then
308        einfo "Setting up unicode environment."
309        unicode_start 2>>$DEBUG ; eend $?
310     fi
311  fi
312
313  # Set default keyboard before interactive setup
314  if [ -n "$KEYTABLE" ] ; then
315     einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
316     loadkeys -q $KEYTABLE &
317     eend $?
318  fi
319
320  # we have to set up all consoles, therefore loop it over all ttys:
321  NUM_CONSOLES=$(fgconsole --next-available)
322  NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
323  [ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
324  CUR_CONSOLE=$(fgconsole)
325
326  if [ -n "$CHARMAP" ] ; then
327     einfo "Running consolechars for ${CHARMAP}"
328     for vc in `seq 0 ${NUM_CONSOLES}`  ; do
329         consolechars --tty=/dev/tty${vc} -m ${CHARMAP} ; RC=$?
330     done
331     [ -n "$CUR_CONSOLE" ] && chvt $CUR_CONSOLE
332     eend $RC
333  fi
334
335  if checkbootparam 'noconsolefont' ; then
336     ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
337  else
338     if [ -n "$CONSOLEFONT" ] ; then
339        einfo "Running consolechars using ${CONSOLEFONT}"
340        for vc in `seq 0 ${NUM_CONSOLES}`  ; do
341            consolechars --tty=/dev/tty${vc} -f $CONSOLEFONT ; RC=$?
342        done
343        [ -n "$CUR_CONSOLE" ] && chvt $CUR_CONSOLE
344        eend $?
345     fi
346  fi
347
348  eoutdent
349 }
350 # }}}
351
352 # {{{ Set hostname
353 config_hostname(){
354  if checkbootparam 'hostname' ; then
355   HOSTNAME="$(getbootparam 'hostname' 2>>$DEBUG)"
356   einfo "Setting hostname to $HOSTNAME as requested."
357   grml-hostname $HOSTNAME >>$DEBUG ; RC=$?
358   [ "$RC" = "0" ] && hostname $HOSTNAME
359   eend $RC
360  else
361   hostname --file /etc/hostname
362  fi
363 }
364 # }}}
365
366 # fstabuser (needed when running from harddisk with username != grml {{{
367 config_userfstab(){
368   [ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
369   if [ -n "$CONFIG_FSTAB_USER" ] ; then
370      fstabuser="$CONFIG_FSTAB_USER"
371   else
372      fstabuser=$(getent passwd 1000 | cut -d: -f1)
373   fi
374   # if not yet set fall back to default 'grml' user
375   [ -n "$fstabuser" ] || fstabuser='grml'
376 }
377 # }}}
378
379 # {{{ Set clock (Local time is more often used than GMT, so it is default)
380 config_time(){
381  # don't touch the files if running from harddisk:
382  if [ -z "$INSTALLED" ]; then
383     # The default hardware clock timezone is stated as representing local time.
384     UTC="--localtime"
385     grep -q "^UTC=" /etc/default/rcS || echo "UTC=no" >> /etc/default/rcS
386     checkbootparam 'utc'       >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
387     checkbootparam 'gmt'       >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=yes|" /etc/default/rcS
388     checkbootparam 'localtime' >>$DEBUG 2>&1 && sed -i "s|^UTC=.*$|UTC=no|"  /etc/default/rcS
389     grep -q -i "^UTC=yes" /etc/default/rcS && UTC="-u"
390     # hwclock uses the TZ variable
391     KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
392     [ -z "$KTZ" ] && [ -r /etc/timezone ] && KTZ=$(cat /etc/timezone)
393     if [ ! -f "/usr/share/zoneinfo/$KTZ" ] ; then
394        ewarn "Warning: unknown timezone $KTZ" ; eend 1
395        KTZ="Europe/Vienna"
396        ewarn "Falling back to timezone $KTZ" ; eend 0
397     fi
398
399     if ! [ -r /dev/rtc ] ; then
400       ewarn "Warning: realtime clock not available, trying to execute hwclock anyway." ; eend 0
401     fi
402
403     ERROR=$(TZ="$KTZ" hwclock $UTC -s 2>&1 | head -1) ; RC=$?
404     if [ -n "$ERROR" ] ; then
405        eindent
406        ERROR=$(TZ="$KTZ" hwclock $UTC -s --directisa 2>&1 | head -1)
407        if [ -n "$ERROR" ] ; then
408           eerror "Problem running hwclock: $ERROR" ; eend 1
409        fi
410        eoutdent
411     fi
412
413  fi
414 }
415 # }}}
416
417 # {{{ print kernel info
418 config_kernel(){
419   vmware-detect &>/dev/null && VMWARE="inside ${WHITE}VMware/Qemu${NORMAL}"
420   [ -d /proc/xen ] && VMWARE='' # vmware-detect returns '0' when running with a Xen-enabled kernel
421   einfo "Running Linux Kernel $KERNEL $VMWARE" ; eend 0
422   if [ -r /proc/cpuinfo ] ; then
423      if egrep -q '^flags.*(vmx|svm)' /proc/cpuinfo ; then
424        eindent
425        einfo 'CPU(s) featuring virtualization technology detected' ; eend 0
426        eoutdent
427      fi
428   fi
429   if [ -d /proc/xen ] ; then
430      eindent
431      einfo 'Running kernel featuring support for Xen detected' ; eend 0
432      eoutdent
433   fi
434 }
435 # }}}
436
437 # {{{ vmware specific stuff
438 config_vmware(){
439 if checkbootparam 'novmware' ; then
440    ewarn "Skipping running vmware specific stuff as requested on boot commandline." ; eend 0
441 else
442    if [ -z "$INSTALLED" ] ; then
443       if vmware-detect || checkbootparam "BOOT_IMAGE=vmware" ; then
444          if ! checkbootparam 'qemu' ; then
445             if [ -r /etc/X11/xorg.conf.vmware ] ; then
446                einfo "VMware: Copying /etc/X11/xorg.conf.vmware to /etc/X11/xorg.conf"
447                cp /etc/X11/xorg.conf.vmware /etc/X11/xorg.conf ; eend $?
448             fi
449          fi
450       elif [ -r /proc/acpi/battery/BAT0/info -a -r /etc/X11/xorg.conf.virtualbox ] ; then
451          if grep -q 'OEM info:                innotek' /proc/acpi/battery/BAT0/info ; then
452             einfo 'Virtual Box: Copying /etc/X11/xorg.conf.virtualbox to /etc/X11/xorg.conf'
453             cp /etc/X11/xorg.conf.virtualbox /etc/X11/xorg.conf ; eend $?
454          fi
455       fi
456    fi
457 fi
458 }
459 # }}}
460
461 # {{{ qemu specific stuff
462 config_qemu(){
463 if checkbootparam 'qemu' ; then
464    if [ -r /etc/X11/xorg.conf.example ] ; then
465       einfo "Qemu: Copying /etc/X11/xorg.conf.example to /etc/X11/xorg.conf"
466       cp /etc/X11/xorg.conf.example /etc/X11/xorg.conf ; eend $?
467    fi
468 fi
469 }
470 # }}}
471
472 # {{{ ld.so.cache + depmod
473 config_ld_mod(){
474 if [ -n "$INSTALLED" ]; then
475  if ! [ -r /etc/grml.first.boot ] ; then
476   einfo "Running from HD for the first time, regenerate ld.so.cache and modules.dep:"
477   eindent
478 # Regenerate ld.so.cache and module dependencies on HD
479     einfo "Running ldconfig" ; ldconfig  ; eend $?
480     einfo "Running depmod"   ; depmod -a ; eend $?
481     touch /etc/grml.first.boot
482     eend 0
483   eoutdent
484  fi
485 fi
486 }
487 # }}}
488
489 # {{{ timezone
490 config_timezone(){
491  # don't touch the files if running from harddisk:
492  if [ -z "$INSTALLED" ]; then
493     KTZ="$(getbootparam 'tz' 2>>$DEBUG)"
494     if [ -n "$KTZ" ] ; then
495        if [ ! -f "/usr/share/zoneinfo/$KTZ" ]
496        then
497           ewarn "Warning: unknown timezone $KTZ"; eend 0
498        else
499           einfo "Setting timezone."
500           # update debconf
501           area=$(echo $KTZ | cut -d '/' -f1)
502           zone=$(echo $KTZ | cut -d '/' -f2)
503           echo "tzdata tzdata/Areas       select $area" | debconf-set-selections
504           echo "tzdata tzdata/Zones/$area select $zone" | debconf-set-selections
505           # update files
506           echo $KTZ > /etc/timezone
507           rm -f /etc/localtime
508           cp "/usr/share/zoneinfo/$KTZ" /etc/localtime ; eend $?
509        fi
510     fi
511  fi
512 }
513 # }}}
514
515 # small computer / nearly no ram {{{
516 config_small(){
517
518 RAM=$(/usr/bin/gawk '/MemTotal/{print $2}' /proc/meminfo)
519 # MEM=$(/usr/bin/gawk 'BEGIN{m=0};/MemFree|Cached|SwapFree/{m+=$2};END{print m}' /proc/meminfo)
520 eindent
521
522 if checkbootparam 'small'; then
523   einfo "Information: ${RAM} kB of RAM available." ; eend 0
524   einfo "Bootoption small detected. Activating small system."
525   if [ -r /etc/inittab.small ] ; then
526     mv /etc/inittab /etc/inittab.normal
527     mv /etc/inittab.small /etc/inittab
528   else
529     sed -i 's/^9/#&/' /etc/inittab
530     sed -i 's/^10/#&/' /etc/inittab
531     sed -i 's/^11/#&/' /etc/inittab
532     sed -i 's/^12/#&/' /etc/inittab
533   fi
534   /sbin/telinit q ; eend $?
535 else
536   if checkgrmlsmall ; then
537     if [[ $RAM -lt 25000 ]] ; then
538       ewarn "Information: ${RAM} kB of RAM available." ; eend 1
539       ewarn "At least 32MB of RAM should be available for grml-small." ; eend 1
540       ewarn "Use the bootoption small to save some more MB of memory usage." ; eend 0
541       ewarn "Dropping you into a rescue shell. To continue booting exit the shell." ; eend 0
542       /bin/zsh --login
543     else
544       einfo "Information: ${RAM} kB of RAM available." ; eend 0
545     fi
546   else
547     if [[ $RAM -lt 58000 ]] ; then
548       ewarn "Information: ${RAM} kB of RAM available." ; eend 1
549       ewarn "At least 64MB of RAM should be available for grml." ; eend 1
550       ewarn "Use the bootoption small to save some more MB of memory usage." ; eend 0
551       ewarn "Dropping you into a rescue shell. To continue booting exit the shell." ; eend 0
552       /bin/zsh --login
553     else
554       einfo "Information: ${RAM} kB of RAM available." ; eend 0
555     fi
556   fi
557 fi
558 eoutdent
559 }
560 # }}}
561
562 # skip startup of w3m {{{
563 config_fast(){
564 if checkbootparam 'fast'; then
565   ewarn "Bootoption fast detected. Skipping startup of grml-quickconfig."
566     sed -i 's#^1:.*#1:12345:respawn:/usr/bin/openvt -f -c 1 -w -- /bin/zsh#' /etc/inittab
567   /sbin/telinit q ; eend $?
568 fi
569 }
570 # }}}
571
572 # activate serial console {{{
573 config_console(){
574 if checkbootparam 'console'; then
575   einfo "Bootoption (for serial) console detected."
576   eindent
577     if [ -r /etc/mgetty/mgetty.config ] ; then
578        MODE=$(getbootparam 'console' | awk -F, '{print $2}')
579        MODE=${MODE%%n*}
580        [ -n "$MODE" ] || MODE=9600 # default mode
581        einfo "Setting speed in /etc/mgetty/mgetty.config to $MODE bps"
582        sed -i "s/speed [0-9]*/speed $MODE/" /etc/mgetty/mgetty.config ; eend $?
583     fi
584
585     einfo "Activating mgetty."
586     sed -i 's/^#T0/T0/' /etc/inittab
587     sed -i 's/^#T1/T1/' /etc/inittab
588     /sbin/telinit q ; eend $?
589   eoutdent
590 fi
591 }
592 # }}}
593
594 # For burning on IDE-CD-Roms, k3b (and others) check for special permissions {{{
595 config_cdrom_perm(){
596 CDROMS=""
597 for DEVICE in /proc/ide/hd?; do
598  [ "$(cat $DEVICE/media 2>/dev/null)" = "cdrom" ] && CDROMS="$CDROMS /dev/${DEVICE##*/}"
599 done
600 [ -n "$CDROMS" ] && { chown root.cdrom $CDROMS; chmod 666 $CDROMS; } 2>/dev/null
601 }
602 # }}}
603
604 # {{{ Bring up loopback interface now
605 config_local_net(){
606  if [ -z "$INSTALLED" ] ; then
607     if grep -q 'iface lo inet loopback' /etc/network/interfaces 2>/dev/null ; then
608        grep -q lo=lo /etc/network/run/ifstate 2>/dev/null || ifup lo
609     else
610        ifconfig lo up
611     fi
612  fi
613 }
614 # }}}
615
616 # firewire devices {{{
617 # the raw1394 driver does not yet export info into SYSFS,
618 # so let's create raw1394 device manually
619 # http://www.michael-prokop.at/blog/index.php?p=352
620 config_firewire_dev(){
621 if checkbootparam 'nofirewiredev' ; then
622   ewarn "Skipping creating some firewire devices as requested on boot commandline." ; eend 0
623 else
624 #if [ "${KERNEL%-*}" == "2.6.11" ] ; then
625   einfo "Creating some firewire devices (fix kernel 2.6-bug)."
626 #  cd /dev && MAKEDEV video1394 raw1394
627   [ -r /dev/raw1394 ]   || mknod /dev/raw1394 c 171 0
628   [ -r /dev/video1394 ] || mknod -m 666 /dev/video1394 c 171 16
629 # mknod -m 666 /dev/dv1394 c 171 32 # for NTSC
630   [ -r /dev/dv1394 ]    || mknod -m 666 /dev/dv1394 c 171 34 # for PAL
631   chown -R root:video /dev/raw1394 /dev/video1394 /dev/dv1394
632   chmod -R 664 /dev/raw1394 /dev/video1394 /dev/dv1394 ; eend $?
633 fi
634 #fi
635 }
636 # }}}
637
638 # {{{ copy passwd-lockfile to ramdisk (fix unionfs-behaviour)
639 # otherwise we will get: passwd: Authentication token lock busy
640 config_fix_passwd(){
641  if [ -z "$INSTALLED" ] ; then
642   touch /etc/.pwd.lock
643  fi
644 }
645 # }}}
646
647 # {{{ CD Checker
648 config_testcd(){
649 if [ -n "$TESTCD" ]; then
650    einfo "Checking CD data integrity as requested by '${WHITE}testcd${NORMAL}' boot option."
651    einfo "Reading files and checking against GRML/md5sums, this may take a while..."
652    echo -n "${RED}"
653
654    if [ -n "${LIVECD_PATH}"/GRML ] ; then
655       ( cd "${LIVECD_PATH}"/GRML ; rm -f /tmp/md5sum.log ; md5sum -c md5sums 2>&1 | tee /tmp/md5sum.log ; RC=$? )
656    else
657       echo "${RED} *** Error: Could not find md5sum file.                           ***"
658    fi
659
660    if [ "$RC" = "0" ]; then
661       einfo "Everything looks OK" ; eend 0
662    else
663       eerror 'Checksum failed for theses files:' ; eend 1
664       egrep -v '(^md5sum:|OK$)' /tmp/md5sum.log
665       eerror 'Data on the grml medium is possibly incomplete/damaged or...'
666       eerror '... RAM of your computer is broken.' ; eend 1
667       einfon "Hit return to continue, or press the reset button to quit."
668      read a
669    fi
670
671    eend 0
672 fi
673 }
674 # }}}
675
676 # {{{ hardware detection via discover
677 config_discover(){
678 if checkbootparam 'nodisc' ; then
679   ewarn "Skipping hardware detection via discover as requested on boot commandline." ; eend 0
680 else
681  if [ -x /sbin/discover ] ; then
682   einfo "Discovering hardware. Trying to load the following modules in background:"
683    eindent
684    einfo "$(discover --data-path=linux/module/name --data-path=linux/modules/options --format="%s %s" --data-version=`uname -r` --enable-bus all | sort -u | xargs echo)"
685    eoutdent
686   /sbin/discover-modprobe -v 1>>$DEBUG 2>&1 &
687   eend 0
688  else
689   eerror "Application discover not available. Information: udev should handle hardware recognition." ; eend 0
690  fi
691 fi
692 }
693 # }}}
694
695 # {{{ hardware detection via hwinfo
696 config_hwinfo(){
697 if checkbootparam 'hwinfo' >>$DEBUG 2>&1; then
698   einfo "Discovering hardware via hwinfo:"
699   MODULES=$(su grml hwinfo | grep "Cmd: \"modprobe" | awk '{print $5}' | sed 's/"//')
700   echo -n "  Loading modules: "
701   for i in `echo $MODULES` ; do echo -n $i && modprobe $i ; done
702   eend 0
703 fi
704 }
705 # }}}
706
707 # {{{ disable hotplug agents on request
708 config_hotplug_agent(){
709 if checkbootparam 'noagent' ; then
710   AGENT="$(getbootparam 'noagent' 2>>$DEBUG)"
711   AGENTLIST=$(echo "$AGENT" | sed 's/,/\\n/g')
712   AGENTNL=$(echo "$AGENT" | sed 's/,/ /g')
713   einfo "Disabling hotplug-agent(s) $AGENTNL"
714   for agent in $(echo -e $AGENTLIST) ; do
715     mv /etc/hotplug/${agent}.rc /etc/hotplug/${agent}.norc
716   done
717   [ "$?" == "0" ] ; eend $?
718 fi
719 }
720 # }}}
721
722 # {{{ blacklist of hotplug-modules
723 config_hotplug_blacklist(){
724 if checkbootparam 'black' ; then
725   BLACK="$(getbootparam 'black' 2>>$DEBUG)"
726   BLACKLIST=$(echo "$BLACK" | sed 's/,/\\n/g')
727   BLACKNL=$(echo "$BLACK" | sed 's/,/ /g')
728   einfo "Blacklisting $BLACKNL via /etc/hotplug/blacklist.d/hotplug-light"
729   echo -e "$BLACKLIST" >> /etc/hotplug/blacklist.d/hotplug-light
730   echo -e "$BLACKLIST" >> /etc/hotplug/blacklist
731   eend 0
732 fi
733 }
734 # }}}
735
736 # {{{ run hotplug
737 config_hotplug(){
738 if checkbootparam 'nohotplug' ; then
739   ewarn "Skipping running hotplug as requested on boot commandline." ; eend 0
740 else
741   if [ -r /etc/init.d/hotplug ] ; then
742     einfo "Starting hotplug system in background."
743     /etc/init.d/hotplug start 1>>$DEBUG 2>>$DEBUG &
744     eend 0
745   elif [ -r /etc/init.d/hotplug-light ] ; then
746     einfo "Starting hotplug-light system in background."
747     /etc/init.d/hotplug-light start 1>>$DEBUG 2>>$DEBUG &
748     eend 0
749   else
750     ewarn "No hotplug system found. Should be handled by udev. Skipping execution." ; eend 0
751   fi
752 fi
753 }
754 # }}}
755
756 # {{{ blacklist specific module [ used in /etc/init.d/udev ]
757 config_blacklist(){
758 if checkbootparam 'blacklist' ; then
759  if [ -z "$INSTALLED" ]; then
760   einfo "Bootoption blacklist found."
761   BLACK="$(getbootparam 'blacklist' 2>>$DEBUG)"
762   BLACKLIST_FILE='/etc/modprobe.d/grml.conf'
763   if [ -n "$BLACK" ] ; then
764     for module in $(echo ${BLACK//,/ }) ; do
765         einfo "Blacklisting module ${module} via ${BLACKLIST_FILE}."
766         echo "# begin entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE"
767         echo "blacklist $module"     >> "$BLACKLIST_FILE"
768         echo "alias     $module off" >> "$BLACKLIST_FILE"
769         echo "# end   entry generated by config_blacklist of grml-autoconfig" >> "$BLACKLIST_FILE" ; eend $?
770     done
771   else
772    eerror "No given module for blacklist found. Blacklisting will not work therefore."
773   fi
774  else
775   ewarn "Backlisting via bootoption is not intended for use on harddisk installations." ; eend 1
776   eindent
777    einfo "Please blacklist the module(s) manually using the 'blacklist' script."
778   eoutdent
779  fi
780 fi
781 }
782 # }}}
783
784 # {{{ ACPI
785 config_acpi_apm(){
786 if [ -d /proc/acpi ]; then
787   if checkbootparam 'noacpi'; then
788     ewarn "Skipping ACPI Bios detection as requested via noacpi on boot commandline." ; eend 0
789   elif checkbootparam 'nogrmlacpi' ; then
790     ewarn "Skipping ACPI Bios detection as requested via nogrmlacpi on boot commandline." ; eend 0
791   else
792     einfo "ACPI Bios found, activating modules (disable via bootoption noacpi / nogrmlacpi): "
793     eindent
794     found=""
795     for a in /lib/modules/$KERNEL/kernel/drivers/acpi/*; do
796       basename="${a##*/}"
797       basename="${basename%%.*}"
798       case "$basename" in *_acpi)
799        egrep -qi "${basename%%_acpi}" /proc/acpi/dsdt 2>>$DEBUG || continue ;;
800       esac
801       modprobe $basename >>$DEBUG 2>&1 && found="yes"
802       local BASE="$BASE $basename"
803     done
804     if [ -n "$found" ] ; then
805       einfo "$BASE"  ; eend 0
806     else
807       ewarn "(none)" ; eend 1
808     fi
809     if ! ps x | grep -q /usr/sbin/acpid ; then
810       if ! [ -r /var/run/dbus/pid ] ; then
811         einfo "Starting acpi daemon."
812         /etc/init.d/acpid start 1>>$DEBUG 2>&1 ; eend $?
813       else
814         eerror "acpid error: it seems you are running d-bus/hal, but acpid needs to be started before d-bus."
815         eerror "Solution: please activate acpid via /etc/runlevel.conf"
816         eend 1
817       fi
818     else
819       ewarn "acpi daemon already running."
820       eend 0
821     fi
822     eoutdent
823   fi
824 else
825 # APM
826   if checkbootparam 'noapm'; then
827     ewarn "Skipping APM Bios detection as requested on boot commandline." ; eend 0
828   else
829     modprobe apm power_off=1 >>$DEBUG 2>&1
830     if [ "$?" = "0" ] ; then
831        if [ -x /etc/init.d/apmd ] ;then
832           einfo "APM Bios found, enabling power management functions."
833           /etc/init.d/apmd start ; eend $?
834        fi
835     else
836       eerror "Loading apm module failed." ; eend 1
837     fi
838   fi
839 fi
840 }
841 # }}}
842
843 # {{{ PCMCIA Check/Setup
844 # This needs to be done before other modules are being loaded (by hwsetup)
845 config_pcmcia(){
846 if checkbootparam 'nopcmcia'; then
847   ewarn "Skipping PCMCIA detection as requested on boot commandline." ; eend 0
848 else
849   if /usr/sbin/laptop-detect ; then
850     einfo "Detected Laptop - checking for PCMCIA." && eend 0
851     modprobe pcmcia_core >>$DEBUG 2>&1
852     # Try Cardbus or normal PCMCIA socket drivers
853     modprobe yenta_socket >>$DEBUG 2>&1 || modprobe i82365 >>$DEBUG 2>&1 || modprobe pd6729 >>$DEBUG 2>&1 || modprobe tcic >>$DEBUG 2>&1
854     if [ "$?" = "0" ]; then
855       modprobe ds >>$DEBUG 2>&1
856       if [ -d /proc/bus/pccard ] ; then
857        if [ -x /sbin/cardmgr ] ; then
858         einfo "PCMCIA found, starting cardmgr."
859         cardmgr >>$DEBUG 2>&1 && sleep 6 && eend 0
860        else
861         eerror "No cardmgr found. Make sure package pcmciautils is installed, it should handle it instead." ; eend 1
862        fi
863       fi
864     fi
865   fi
866 fi
867 }
868 # }}}
869
870 # {{{ run software synthesizer via speakup
871 config_swspeak(){
872    if checkbootparam 'swspeak' ; then
873       einfo "Bootoption swspeak found."
874
875       if [ ! -d /proc/speakup/ ] && ! grep -q speakup_soft /proc/modules ; then
876          ewarn "Kernel does not support software speakup - trying to load kernel module:" ; eend 0
877          eindent
878          einfo "Loading speakup_soft"
879          if modprobe speakup_soft ; then
880             eend 0
881          else
882             flitewrapper "Fatal error setting up software speakup"
883             eend 1
884             return 1
885          fi
886          eoutdent
887       fi
888
889       if [ -d /proc/speakup/ ] || grep -q speakup_soft /proc/modules ; then
890          einfo "Kernel supports speakup." ; eend 0
891          eindent
892             einfo "Just run swspeak if you want to use software synthesizer via speakup."
893             flitewrapper "Finished activating software speakup. Just run swspeak when booting finished."
894          eoutdent
895       else
896          eerror "Kernel does not seem to support speakup. Skipping swspeak." ; eend 1
897          flitewrapper "Kernel does not seem to support speakup. Sorry."
898       fi
899    fi
900 }
901 # }}}
902
903 # {{{ support hardware synthesizer via speakup
904 config_hwspeak(){
905    if checkbootparam 'speakup.synth' ; then
906       einfo "Bootoption speakup.synth found."
907       eindent
908
909       module="$(getbootparam 'speakup.synth' 2>>$DEBUG)"
910       if [ -z "$module" ] ; then
911          eerror "Sorry, no speakup module specified for bootoption speakup.synth."
912          flitewrapper "Sorry, no speakup module specified for bootoption speakup.synth."
913       else
914          einfo "Trying to load $module"
915          modprobe "speakup_${module}"
916          eend $?
917       fi
918
919       if [ -d /proc/speakup/ ] || grep -q speakup /proc/modules ; then
920          einfo "Kernel should support speakup now." ; eend 0
921          flitewrapper "Kernel should support speakup now."
922       else
923          eerror "Kernel or hardware do not seem to support speakup. Skipping hwspeak." ; eend 1
924          flitewrapper "Kernel or hardware do not seem to support speakup. Sorry."
925       fi
926
927       eoutdent
928
929    # hwspeak:
930    elif checkbootparam 'hwspeak' ; then
931       einfo "Bootoption hwspeak found."
932
933       if [ ! -d /proc/speakup/ ] && ! grep -q speakup /proc/modules ; then
934          ewarn "Kernel does not support hardware speakup - trying to load kernel modules:" ; eend 0
935          eindent
936          if ! [ -d "/lib/modules/${KERNEL}/extra/speakup/" ] ; then
937             eerror "Kernel does not provide speakup modules, sorry." ; eend 1
938          else
939            for module in $(find "/lib/modules/${KERNEL}/extra/speakup/" -name \*.ko | \
940                            sed 's#.*speakup/##g ; s#.ko$##g' | \
941                            grep -ve speakup_soft -ve speakup_dummy | sort -u) ; do
942               einfo "Trying to load $module"
943               modprobe $module
944               eend $?
945            done
946          fi
947          eoutdent
948       fi
949
950       if [ -d /proc/speakup/ ] || grep -q speakup /proc/modules ; then
951          einfo "Kernel should support speakup now." ; eend 0
952          flitewrapper "Kernel should support speakup now."
953       else
954          eerror "Kernel or hardware do not seem to support speakup. Skipping hwspeak." ; eend 1
955          flitewrapper "Kernel or hardware do not seem to support speakup. Sorry."
956       fi
957    fi
958 }
959 # }}}
960
961 # {{{ Check for blind option or brltty
962 config_blind(){
963 BLIND=""
964 checkbootparam 'blind' && BLIND="yes"
965 BRLTTY="$(getbootparam 'brltty' 2>>$DEBUG)"
966
967 if [ -n "$BLIND" -o -n "$BRLTTY" ]; then
968   if [ -x /sbin/brltty ]; then
969     # Blind option detected, start brltty now.
970     # modprobe serial_core parport_serial generic_serial && echo "done"
971     CMD=brltty
972     BRLTYPE=""
973     BRLDEV=""
974     BRLTEXT=""
975     if [ -n "$BRLTTY" ]; then
976       # Extra options
977       BRLTYPE="${BRLTTY%%,*}"
978       R="${BRLTTY#*,}"
979       if [ -n "$R" -a "$R" != "$BRLTTY" ]; then
980         BRLTTY="$R"
981         BRLDEV="${BRLTTY%%,*}"
982         R="${BRLTTY#*,}"
983         if [ -n "$R" -a "$R" != "$BRLTTY" ]; then
984           BRLTTY="$R"
985           BRLTEXT="${BRLTTY%%,*}"
986           R="${BRLTTY#*,}"
987         fi
988       fi
989     fi
990     [ -n "$BRLTYPE" ] && CMD="$CMD -b $BRLTYPE"
991     [ -n "$BRLDEV"  ] && CMD="$CMD -d $BRLDEV"
992     [ -n "$BRLTEXT" ] && CMD="$CMD -t $BRLTEXT"
993     einfo "Starting braille-display manager."
994 #    ( exec $CMD & )
995     ( sh -c "$CMD" & )
996     sleep 2 && BLINDSOUND="yes"
997     eend 0
998   fi
999 fi
1000 }
1001 # }}}
1002
1003 # {{{ Interactive configuration
1004 config_interactive(){
1005   ewarn "config_interactive is deprecated nowadays."
1006   ewarn "Please set CONFIG_INTERACTIVE='no' in /etc/grml/autoconfig" ; eend 0
1007 }
1008 # }}}
1009
1010 # {{{ AGP
1011 config_agp(){
1012 if checkbootparam 'forceagp' ; then
1013 # Probe for AGP. Hope this can fail safely
1014   grep -q "AGP" "/proc/pci" 2>>$DEBUG && { modprobe agpgart || modprobe agpgart agp_try_unsupported=1; } >>$DEBUG 2>&1 && einfo "AGP bridge detected." ; eend 0
1015 fi
1016 }
1017 # }}}
1018
1019 # {{{ automount(er)
1020 config_automounter(){
1021 if checkbootparam 'automounter' ; then
1022   RUNLEVEL="$(runlevel)"
1023   AUTOMOUNTER=""
1024   [ -x /etc/init.d/autofs ] && [ "$RUNLEVEL" != "N 1" ] && [ "$RUNLEVEL" != "N S" ] && AUTOMOUNTER="yes"
1025
1026 addautomount(){
1027 # /dev/ice  options
1028   d="${1##*/}"
1029   if [ -n "$AUTOMOUNTER" ]; then
1030     [ -d "/mnt/$d" -a ! -L "/mnt/$d" ] && rmdir /mnt/$d
1031     [ -d "/mnt/auto/$d" ] || mkdir -p "/mnt/auto/$d"
1032     [ -L "/mnt/$d" ]      || ln -s "/mnt/auto/$d" "/mnt/$d"
1033     anew="$d        -fstype=auto,$2 :$i"
1034     grep -q "$anew" "/etc/auto.mnt" || echo "$anew" >> /etc/auto.mnt
1035     AUTOMOUNTS="$AUTOMOUNTS $d"
1036     new="$1 /mnt/auto/$d  auto   users,noauto,exec,$2 0 0"
1037   else
1038     [ -d /mnt/$d ] && mkdir -p /mnt/$d
1039     new="$1 /mnt/$d  auto   users,noauto,exec,$2 0 0"
1040   fi
1041   grep -q "$new" "/etc/fstab" || echo "$new" >> /etc/fstab
1042 }
1043
1044   AUTOMOUNTS="floppy cdrom"
1045 # Add new devices to /etc/fstab and /etc/auto.mnt
1046   for i in /dev/cdrom?*; do
1047     if [ -L $i ]; then
1048       addautomount "$i" "ro"
1049     fi
1050   done
1051 fi
1052
1053 if [ -n "$AUTOMOUNTER" ]; then
1054 # Check for floppy dir, reinstall with automounter
1055   [ -d /mnt/floppy -a ! -L /mnt/floppy ] && rmdir /mnt/floppy
1056   [ -d /mnt/auto/floppy ] || mkdir -p /mnt/auto/floppy
1057   [ -L /mnt/floppy ] || ln -s /mnt/auto/floppy /mnt/floppy
1058   [ -d /mnt/cdrom -a ! -L /mnt/cdrom ] && rmdir /mnt/cdrom
1059   [ -d /mnt/auto/cdrom ] || mkdir -p /mnt/auto/cdrom
1060   [ -L /mnt/cdrom ] || ln -s /mnt/auto/cdrom /mnt/cdrom
1061   rm -f /etc/fstab.new
1062 # Replace paths from bootfloppy
1063   sed 's|/mnt/cdrom|/mnt/auto/cdrom|g;s|/mnt/floppy|/mnt/auto/floppy|g' /etc/fstab > /etc/fstab.new
1064   mv -f /etc/fstab.new /etc/fstab
1065 # Start automounter now
1066   einfo "Starting automounter for ${AUTOMOUNTS}."
1067   /etc/init.d/autofs start >>$DEBUG ; eend $?
1068 fi
1069 }
1070 # }}}
1071
1072 # {{{ Collect partitions from /proc/partitions first for enabling DMA
1073 check_partitions(){
1074 partitions=""
1075 IDEDISKS=""
1076 while read major minor blocks partition relax; do
1077   partition="${partition##*/}"
1078   [ -z "$partition" -o ! -e "/dev/$partition" ] && continue
1079   case "$partition" in
1080     hd?) IDEDISKS="$IDEDISKS $partition";;                # IDE  Harddisk, entire disk
1081     sd?) ;;                                               # SCSI Harddisk, entire disk
1082 #    [hs]d*) partitions="$partitions /dev/$partition";;    # IDE or SCSI disk partition
1083     [hs]d*|ub*) partitions="$partitions /dev/$partition";;    # IDE, USB or SCSI disk partition
1084   esac
1085 done <<EOT
1086 $(awk 'BEGIN{old="__start"}{if($0==old){exit}else{old=$0;if($4&&$4!="name"){print $0}}}' /proc/partitions)
1087 EOT
1088 }
1089 check_partitions 1>/dev/null 2>&1 # avoid output "check_partitions:3: read-only file system"
1090 # }}}
1091
1092 # {{{ Enable DMA for all IDE drives now if not disabled
1093 # Notice: Already done by linuxrc, but make sure it's done also on harddisk-installed systems
1094 config_dma(){
1095 if checkbootparam 'nodma'; then
1096   ewarn "Skipping DMA accelleration as requested on boot commandline." ; eend 0
1097 else
1098   for d in $(cd /proc/ide 2>>$DEBUG && echo hd[a-z]); do
1099     if test -d /proc/ide/$d; then
1100       if egrep -q 'using_dma[ \t]+0' /proc/ide/$d/settings 2>>$DEBUG; then
1101         MODEL="$(cat /proc/ide/$d/model 2>>$DEBUG)"
1102         test -z "$MODEL" && MODEL="[GENERIC IDE DEVICE]"
1103         einfo "Enabling DMA acceleration for: ${WHITE}$d        ${YELLOW}[${MODEL}]${NORMAL}"
1104         echo "using_dma:1" >/proc/ide/$d/settings
1105         eend 0
1106       fi
1107     fi
1108   done
1109 fi
1110 }
1111 # }}}
1112
1113 # {{{ Start creating /etc/fstab with HD partitions and USB SCSI devices now
1114 config_fstab(){
1115
1116 NOSWAP="yes" # we do not use swap by default!
1117 if checkbootparam 'swap' || checkbootparam 'anyswap' ; then
1118    NOSWAP=''
1119    checkbootparam 'anyswap' && export ANYSWAP='yes' || export ANYSWAP=""
1120 fi
1121
1122 if checkbootparam 'nofstab' || checkbootparam 'forensic' ; then
1123   ewarn "Skipping /etc/fstab creation as requested on boot commandline." ; eend 0
1124 else
1125   einfo "Scanning for harddisk partitions and creating /etc/fstab. (Disable this via boot option: nofstab)"
1126   iszsh && setopt nonomatch
1127   if [ -x /usr/sbin/rebuildfstab ] ; then
1128      config_userfstab || fstabuser=grml
1129      /usr/sbin/rebuildfstab -r -u $fstabuser -g $fstabuser ; eend $?
1130   else
1131      ewarn "Command rebuildfstab not found. Install package grml-rebuildfstab." ; eend 1
1132   fi
1133 fi # checkbootparam nofstab/forensic
1134
1135 # Scan for swap, config, homedir - but only in live-mode
1136 if [ -z "$INSTALLED" ] ; then
1137    [ -z "$NOSWAP" ] && einfo "Searching for swap partition(s) as requested."
1138    GRML_IMG=""
1139    GRML_SWP=""
1140    HOMEDIR="$(getbootparam 'home')"
1141    if [ -n "$partitions" ]; then
1142       while read p m f relax; do
1143         case "$p" in *fd0*|*proc*|*sys*|*\#*) continue;; esac
1144         partoptions="users,exec"
1145         fnew=""
1146         # it's a swap partition?
1147         case "$f" in swap)
1148           eindent
1149           if [ -n "$NOSWAP" ]; then
1150              ewarn "Ignoring swap partition ${WHITE}$p${NORMAL}. (Force usage via boot option 'swap', or execute grml-swapon)"
1151              eend 0
1152           else
1153              case "$(dd if=$p bs=1 count=6 skip=4086 2>/dev/null)" in
1154                    S1SUSP|S2SUSP|pmdisk|[zZ]*)
1155                      if [ -n "$ANYSWAP" ] ; then
1156                         einfo "Using swap partition ${WHITE}${p}${NORMAL} [bootoption anyswap found]."
1157                         swapon $p 2>>$DEBUG ; eend $?
1158                      else
1159                         ewarn "Suspend signature on ${WHITE}${p}${NORMAL} found, not using as swap. (Force usage via boot option: anyswap)"
1160                      fi
1161                      ;;
1162                    *)
1163                      if [[ "$p" == LABEL* ]] ; then
1164                         p=$(blkid -t $p | awk -F: '{print $1}')
1165                      fi
1166                      if grep -q $p /proc/swaps ; then
1167                         ewarn "Not using swap partition ${WHITE}${p}${NORMAL} as it is already in use." ; eend 0
1168                      else
1169                         if [ -b "$p" ] ; then
1170                         einfo "Using swap partition ${WHITE}${p}${NORMAL}."
1171                         swapon $p 2>>$DEBUG ; eend $?
1172                         else
1173                         ewarn "$p is not a valid block device - not using it therefore." ; eend 0
1174                         fi
1175                      fi
1176                      ;;
1177              esac # dd-check
1178           fi # -n "$NOSWAP
1179           eoutdent
1180           continue
1181           ;;
1182         esac # it's a swap partition?
1183
1184         # mount read-only
1185         MOUNTOPTS="ro"
1186         case "$f" in
1187           vfat|msdos|ntfs) MOUNTOPTS="$MOUNTOPTS,uid=${fstabuser},gid=${fstabuser}" ;;
1188           ext2|ext3|reiserfs|jfs|reiser4|xfs) MOUNTOPTS="$MOUNTOPTS,noatime" ;;
1189           *) continue ;;
1190           # *) NONEFOUND='1'; continue ;;
1191         esac
1192
1193         # use a swapfile
1194         if [ -z "$NOSWAP" ] ; then
1195            mount -o "$MOUNTOPTS" -t $f $p $m 2>>$DEBUG && MOUNTED=1 || continue
1196            # Activate swapfile, if exists
1197            SWAPFILE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ss][Ww][Pp] 2>/dev/null)"
1198         fi
1199         if [ -z "$NOSWAP" -a -n "$SWAPFILE" -a -f "$SWAPFILE" ]; then
1200            mount -o remount,rw $m && MOUNTED=1
1201            if swapon "$SWAPFILE" 2>>$DEBUG ; then
1202               eindent
1203                 einfo "Using GRML swapfile ${WHITE}${SWAPFILE}${NORMAL}."
1204               eoutdent
1205               fnew="$SWAPFILE swap swap defaults 0 0"
1206               grep -q "$fnew" "/etc/fstab" || echo "$fnew" >> /etc/fstab
1207               GRML_SWP="$GRML_SWP $SWAPFILE"
1208               eend 0
1209            fi
1210            mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
1211         fi
1212
1213         # use a image as home
1214         IMAGE="$(/bin/ls -1d $m/[Gg][Rr][Mm][Ll].[Ii][Mm][Gg] 2>/dev/null)"
1215         if [ -z "$GRML_IMG" -a -n "$IMAGE" -a -f "$IMAGE" ]; then
1216            if [ -n "$HOMEDIR" ]; then
1217               if [ "$HOMEDIR" != "scan" -a "$HOMEDIR" != "$IMAGE" -a "$HOMEDIR" != "${IMAGE%/*.*}" ]; then
1218                  continue
1219               fi
1220            fi
1221            if type -a grml-image >/dev/null 2>&1 && grml-image "$IMAGE" </dev/console >/dev/console 2>&1; then
1222               GRML_IMG="$IMAGE"
1223               mount -o remount,ro $m 2>>$DEBUG && MOUNTED=1
1224            fi
1225         fi
1226         eend 0
1227
1228         # Umount, if not in use
1229         [ -n "$MOUNTED" ] && umount -r $m 2>/dev/null
1230
1231       done <<EOT
1232       $(cat /etc/fstab)
1233 EOT
1234    fi # -n $partitions
1235 fi # -z $INSTALLED
1236 }
1237 # }}}
1238
1239 # {{{ Mouse
1240 config_mouse(){
1241 if [ -n "$MOUSE_DEVICE" ] ; then
1242   einfo "Detecting mouse: ${MOUSE_FULLNAME} at ${MOUSE_DEVICE}" ; eend $?
1243 fi
1244 }
1245 # }}}
1246
1247 # {{{ IPv6 configuration
1248 # Load IPv6 kernel module and print IP adresses
1249 config_ipv6(){
1250 if checkbootparam 'ipv6'; then
1251   einfo "Enabling IPv6 as requested on boot commandline (sleeping for 2 seconds)"
1252   modprobe ipv6
1253   # we probably need some time until stateless autoconfiguration has happened
1254   sleep 2
1255   NETDEVICES="$(awk -F: '/eth.:|tr.:|wlan.:/{print $1}' /proc/net/dev 2>>$DEBUG)"
1256   for DEVICE in `echo "$NETDEVICES"`; do
1257     eindent
1258       einfo "$DEVICE:"
1259       ADDRESSES="$(ifconfig $DEVICE | awk '/.*inet6 addr:.*/{print $3}')"
1260       COUNT="$(ifconfig $DEVICE | awk '/.*inet6 addr:.*/{ sum += 1};END {print sum }')"
1261       eindent
1262         for ADDR in `echo "$ADDRESSES"` ; do
1263             einfo "$ADDR"
1264         done
1265         if [ "$COUNT" -eq "0" ] ; then
1266            einfo "(none)" ; eend 1
1267         fi
1268       eoutdent
1269     eoutdent
1270   done
1271   eend 0
1272 fi
1273 }
1274 # }}}
1275
1276 # {{{ Fat-Client-Version: DHCP Broadcast for IP address
1277 config_dhcp(){
1278 if checkbootparam 'nodhcp'; then
1279   ewarn "Skipping DHCP broadcast/network detection as requested on boot commandline." ; eend 0
1280 else
1281   NETDEVICES="$(awk -F: '/eth.:|tr.:|wlan.:/{print $1}' /proc/net/dev 2>>$DEBUG)"
1282   rm -rf /etc/network/status ; mkdir -p /etc/network/status
1283   for DEVICE in `echo "$NETDEVICES"` ; do
1284     einfo "Network device ${WHITE}${DEVICE}${NORMAL} detected, DHCP broadcasting for IP. (Backgrounding)"
1285     trap 2 3 11
1286     ifconfig $DEVICE up >>$DEBUG 2>&1
1287     ( pump -i $DEVICE --script=/usr/lib/grml-autoconfig/pump-runparts >>$DEBUG 2>&1 && echo finished_running_pump > /etc/network/status/$DEVICE ) &
1288     trap "" 2 3 11
1289     sleep 1
1290     eend 0
1291   done
1292   if [ -n "$INSTALLED" ] ; then
1293      ewarn 'If you want to disable automatic DHCP requests set CONFIG_DHCP=no in /etc/grml/autoconfig.'
1294      eend 0
1295   fi
1296 fi
1297 }
1298 # }}}
1299
1300 # {{{ helper functions
1301 findfile(){
1302 FOUND=""
1303 # search all partitions for a file in the root directory
1304 for i in /mnt/[sh]d[a-z] /mnt/[sh]d[a-z][1-9] /mnt/[sh]d[a-z][1-9]?*; do
1305 # See if it's already mounted
1306   [ -f "$i/$1" ] &&  { echo "$i/$1"; return 0; }
1307   if [ -d "$i" ] && mount -r "$i" 2>>$DEBUG; then
1308     [ -f "$i/$1" ] && FOUND="$i/$1"
1309     umount -l "$i" 2>>$DEBUG
1310     [ -n "$FOUND" ] && { echo "$FOUND"; return 0; }
1311   fi
1312 done
1313 return 2
1314 }
1315
1316 fstype(){
1317 case "$(file -s $1)" in
1318   *[Ff][Aa][Tt]*|*[Xx]86*) echo "vfat"; return 0;;
1319   *[Rr][Ee][Ii][Ss][Ee][Rr]*)  echo "reiserfs"; return 0;;
1320   *[Xx][Ff][Ss]*)  echo "xfs"; return 0;;
1321   *[Ee][Xx][Tt]3*) echo "ext3"; return 0;;
1322   *[Ee][Xx][Tt]2*) echo "ext2"; return 0;;
1323   *data*)          echo "invalid"; return 0;;
1324   *) echo "auto"; return 0;;
1325 esac
1326 }
1327
1328 # Try to mount this filesystem read-only, without or with encryption
1329 trymount(){
1330 # Check if already mounted
1331 case "$(cat /proc/mounts)" in *\ $2\ *) return 0;; esac
1332 # Apparently, mount-aes DOES autodetect AES loopback files.
1333 [ -b "$1" ] && { mount -t auto -o ro "$1" "$2" 2>>$DEBUG; RC="$?"; }
1334 # We need to mount crypto-loop files with initial rw support
1335 [ -f "$1" ] && { mount -t auto -o loop,rw "$1" "$2" 2>>$DEBUG; RC="$?"; }
1336 # Mount succeeded?
1337 [ "$RC" = "0" ] && return 0
1338 echo ""
1339 einfo "Filesystem not autodetected, trying to mount $1 with AES256 encryption."
1340 a="y"
1341 while [ "$a" != "n" -a "$a" != "N" ]; do
1342 # We need to mount crypto-loop files with initial rw support
1343  mount -t auto -o loop,rw,encryption=AES256 "$1" "$2" && return 0
1344  echo -n "${RED}Mount failed, retry? [Y/n] ${NORMAL}"
1345  # Problem with ioctl() from getpasswd()?
1346  # read a
1347  read a
1348 done
1349 return 1
1350 }
1351 # }}}
1352
1353 # {{{ CPU-detection
1354 config_cpu(){
1355 if checkbootparam 'nocpu'; then
1356   ewarn "Skipping CPU detection as requested on boot commandline." ; eend 0
1357 else
1358   # check module dependencies
1359   cpufreq_check() {
1360    if ! [ -e /lib/modules/${KERNEL}/kernel/arch/x86/kernel/cpu/cpufreq ] ; then
1361       if [ -e /lib64 ] ; then
1362          [ -e /lib/modules/${KERNEL}/kernel/arch/x86_64/kernel/cpufreq ] || return 1
1363       else
1364          [ -e /lib/modules/${KERNEL}/kernel/arch/i386/kernel/cpu/cpufreq -o ! -e /lib/modules/${KERNEL}/kernel/drivers/cpufreq ] || return 1
1365       fi
1366    fi
1367   }
1368
1369   if [[ `grep -c processor /proc/cpuinfo` -gt 1 ]] ; then
1370      einfo "Detecting CPU:"
1371      CPU=$(awk -F: '/^processor/{printf "       Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG)
1372      echo $CPU | sed 's/ \{1,\}/ /g'
1373      eend 0
1374   else
1375      einfo "Detecting CPU: `awk -F: '/^processor/{printf " Processor"$2" is"};/^model name/{printf $2};/^vendor_id/{printf vendor};/^cpu MHz/{printf " %dMHz",int($2)};/^cache size/{printf ","$2" Cache"};/^$/{print ""}' /proc/cpuinfo 2>>$DEBUG` " ; eend 0
1376   fi
1377
1378   # Disclaimer: sorry for the tons of if/then/else... but this makes sure we use:
1379   # * it only if we have the according kernel modules available
1380   # * cpufreq not inside Virtual Box
1381   # * current version of /etc/init.d/loadcpufreq from Debian (to stay in sync)
1382   #   -> parse output of the initscript and output it according to our look'n'feel
1383   # * our own cpufreq-detect.sh if /etc/init.d/loadcpufreq isn't present
1384   if ! cpufreq_check ; then
1385     ewarn "Skipping cpufreq setup as module dependencies are not fulfilled." ; eend 1
1386   else
1387      # Virtual Box supports ACPI and laptop-detect would return with '0', so check for it:
1388      if [ -r /proc/acpi/battery/BAT0/info ] ; then
1389         if grep -q 'OEM info:                innotek' /proc/acpi/battery/BAT0/info ; then
1390            einfo 'Virtual Box detected, skipping cpufreq setup.' ; eend 0
1391            return 0
1392         fi
1393      fi
1394      einfo "Trying to set up cpu frequency scaling:"
1395      eindent
1396      if [ -x /etc/init.d/loadcpufreq ] ; then
1397         SKIP_CPU_GOVERNOR=''
1398         LOADCPUFREQ=$(mktemp)
1399         /etc/init.d/loadcpufreq start >"$LOADCPUFREQ" 2>&1 ; RC=$?
1400         if grep -q FATAL "$LOADCPUFREQ" ; then
1401            eindent
1402              SKIP_CPU_GOVERNOR=1
1403              oldIFS="$IFS"
1404              IFS="
1405 "
1406               for line in $(grep FATAL "$LOADCPUFREQ" | sed 's/.*FATAL: //; s/ (.*)//') ; do
1407                   eerror "$line" ; eend $RC
1408               done
1409               IFS="$oldIFS"
1410            eoutdent
1411          elif grep -q done "$LOADCPUFREQ" ; then
1412            MODULE=$(grep done "$LOADCPUFREQ" | sed 's/.*done (\(.*\))./\1/')
1413            if [ -n "$MODULE" -a "$MODULE" != none ]; then
1414               einfo "Loading cpufreq kernel module $MODULE" ; eend 0
1415            else
1416               ewarn "Could not find an appropriate kernel module for cpu frequency scaling." ; eend 1
1417            fi
1418         fi
1419         rm -f $LOADCPUFREQ
1420      elif [ -r /usr/bin/cpufreq-detect.sh ] ; then
1421         . /usr/bin/cpufreq-detect.sh
1422         if [ -n "$MODULE" -a "$MODULE" != none ]; then
1423            einfo "Loading modules ${MODULE}"
1424            modprobe "$MODULE" 1>>$DEBUG || modprobe "$MODULE_FALLBACK" 1>>$DEBUG
1425            RC=$?
1426            if [[ $RC == 0 ]]; then
1427               eend 0
1428            else
1429               SKIP_CPU_GOVERNOR=1
1430               eend $1
1431            fi
1432         else
1433            ewarn "Could not detect an appropriate CPU for use with cpu frequency scaling - skipping." && eend 1
1434         fi # $MODULE
1435      fi # loadcpufreq
1436
1437      if [ -z "$SKIP_CPU_GOVERNOR" ] ; then
1438         einfo "Loading cpufreq_ondemand, setting ondemand governor"
1439         if modprobe cpufreq_ondemand ; RC=$? ; then
1440            for file in $(find /sys/devices/system/cpu/ -name scaling_governor 2>/dev/null) ; do
1441                echo ondemand > $file
1442            done
1443         fi
1444         eend $RC
1445      fi # cpu-governor
1446
1447      eoutdent
1448
1449   fi # cpufreq_check
1450 fi # checkbootparam nocpu
1451 }
1452 # }}}
1453
1454 # {{{ autostart of ssh
1455 config_ssh(){
1456 if checkbootparam 'ssh' ; then
1457    SSH_PASSWD=''
1458    SSH_PASSWD="$(getbootparam 'ssh' 2>>$DEBUG)"
1459    einfo "Bootoption ssh found, trying to set password for user grml."
1460    eindent
1461    if [ -z "$SSH_PASSWD" ] ; then
1462       if [ -x /usr/bin/apg ] ; then
1463          SSH_PASSWD="$(apg -M NL -a 0 -m 8 -x 12 -n 1)"
1464       elif [ -x /usr/bin/gpw ] ; then
1465          SSH_PASSWD="$(gpw 1)"
1466       elif [ -x /usr/bin/pwgen ] ; then
1467          SSH_PASSWD="$(pwgen -1 8)"
1468       elif [ -x /usr/bin/hexdump ] ; then
1469          SSH_PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
1470       elif [ -n "$RANDOM" ] ; then
1471          SSH_PASSWD="grml${RANDOM}"
1472       else
1473          SSH_PASSWD=''
1474          eerror "Empty passphrase and neither pwgen nor hexdump nor \$RANDOM found. Skipping."
1475          eend 1
1476       fi
1477
1478       if [ -n "$SSH_PASSWD" ] ; then
1479          ewarn "No given password for ssh found. Using random password: $SSH_PASSWD" ; eend 0
1480       fi
1481    fi
1482    eoutdent
1483
1484    # finally check if we have a password we can use:
1485    if [ -n "$SSH_PASSWD" ] ; then
1486       # chpasswd sucks, seriously.
1487       if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
1488         echo "grml:$SSH_PASSWD" | chpasswd -m
1489       else
1490         echo "grml:$SSH_PASSWD" | chpasswd
1491       fi
1492    fi
1493
1494    einfo 'Starting secure shell server in background.'
1495    /etc/init.d/rmnologin start 1>>$DEBUG 2>>$DEBUG
1496    /etc/init.d/ssh start 1>>$DEBUG 2>>$DEBUG &
1497    eend $?
1498
1499    eindent
1500    ewarn 'Warning: please change the password for user grml as soon as possible!'
1501    eoutdent
1502 fi
1503 }
1504 # }}}
1505
1506 # {{{ autostart of x11vnc
1507 config_vnc(){
1508
1509 USER=grml # TODO: make it dynamically configurable
1510 if checkbootparam 'vnc' ; then
1511    VNC_PASSWD=''
1512    VNC_PASSWD="$(getbootparam 'vnc' 2>>$DEBUG)"
1513    einfo "Bootoption vnc found, trying to set password for user $USER."
1514    eindent
1515    if [ -z "$VNC_PASSWD" ] ; then
1516       if [ -x /usr/bin/apg ] ; then
1517          VNC_PASSWD="$(apg -M NL -a 0 -m 8 -x 12 -n 1)"
1518       elif [ -x /usr/bin/gpw ] ; then
1519          VNC_PASSWD="$(gpw 1)"
1520       elif [ -x /usr/bin/pwgen ] ; then
1521          VNC_PASSWD="$(pwgen -1 8)"
1522       elif [ -x /usr/bin/hexdump ] ; then
1523          VNC_PASSWD="$(dd if=/dev/urandom bs=14 count=1 2>/dev/null | hexdump | awk '{print $3 $4}')"
1524       elif [ -n "$RANDOM" ] ; then
1525          VNC_PASSWD="${USER}${RANDOM}"
1526       else
1527          VNC_PASSWD=''
1528          eerror "Empty passphrase and neither pwgen nor hexdump nor \$RANDOM found. Skipping."
1529          eend 1
1530       fi
1531
1532       if [ -n "$VNC_PASSWD" ] ; then
1533          ewarn "No given password for vnc found. Using random password: $VNC_PASSWD" ; eend 0
1534       fi
1535    fi
1536    eoutdent
1537
1538    # finally check if we have a password we can use:
1539    if [ -n "$VNC_PASSWD" ] ; then
1540
1541       VNCDIR="/home/${USER}/.vnc"
1542       [ -d "$VNCDIR" ] || mkdir "$VNCDIR"
1543
1544       if [ ! -x /usr/bin/x11vnc ] ; then
1545          eerror "Error: x11vnc not found - can not set up vnc. Please make sure to install the x11vnc package."
1546          eend 1
1547       else
1548          /usr/bin/x11vnc -storepasswd "$VNC_PASSWD" "$VNCDIR"/passwd ; eend $?
1549          /bin/chown -R "$USER": "$VNCDIR"
1550       fi
1551    fi
1552 fi
1553 }
1554 # }}}
1555
1556 # {{{ set password for user grml
1557 config_passwd(){
1558 if checkbootparam 'passwd' >>$DEBUG 2>&1; then
1559   einfo "Bootoption passwd found."
1560   PASSWD="$(getbootparam 'passwd' 2>>$DEBUG)"
1561   if [ -n "$PASSWD" ] ; then
1562     echo "grml:$PASSWD" | chpasswd -m ; eend $?
1563   else
1564     eerror "No given password for ssh found. Autostart of SSH will not work." ; eend 1
1565   fi
1566   eindent
1567     ewarn "Warning: please change the password for user grml set via bootparameter as soon as possible!"
1568   eoutdent
1569 fi
1570 }
1571 # }}}
1572
1573 # {{{ Check for persistent homedir option and eventually mount /home from there, or use a loopback file.
1574 config_homedir(){
1575 if checkbootparam 'home' ; then
1576    HOMEDIR="$(getbootparam 'home')"
1577    MYHOMEDEVICE=""
1578    MYHOMEMOUNTPOINT=""
1579    MYHOMEDIR=""
1580    if [ -n "$HOMEDIR" ]; then
1581       einfo "Bootoption home detected." && eend 0
1582       case "$HOMEDIR" in
1583         /dev/*)
1584         MYHOMEDEVICE="${HOMEDIR##/dev/}"
1585         MYHOMEDEVICE="/dev/${MYHOMEDEVICE%%/*}"
1586         MYHOMEMOUNTPOINT="/mnt/${MYHOMEDEVICE##/dev/}"
1587         MYHOMEDIR="/mnt/${HOMEDIR##/dev/}"
1588       ;;
1589         /mnt/*)
1590         MYHOMEDEVICE="${HOMEDIR##/mnt/}"
1591         MYHOMEDEVICE="/dev/${MYHOMEDEVICE%%/*}"
1592         MYHOMEMOUNTPOINT="/mnt/${MYHOMEDEVICE##/dev/}"
1593         MYHOMEDIR="$HOMEDIR"
1594       ;;
1595         [Aa][Uu][Tt][Oo]|[Ss][Cc][Aa][Nn]|[Ff][Ii][Nn][Dd])
1596         MYHOMEDIR="$(findfile grml.img)"
1597         MYHOMEDEVICE="${MYHOMEDIR##/mnt/}"
1598         MYHOMEDEVICE="/dev/${MYHOMEDEVICE%%/*}"
1599         MYHOMEMOUNTPOINT="/mnt/${MYHOMEDEVICE##/dev/}"
1600       ;;
1601       *)
1602         eerror "Invalid home= option '$HOMEDIR' specified (must start with /dev/ or /mnt/ or 'scan')." ; eend 1
1603         eerror "Option ignored." ; eend 1
1604       ;;
1605       esac
1606    fi # -n $HOMEDIR
1607
1608    if [ -n "$MYHOMEDIR" ]; then
1609       if trymount "$MYHOMEDEVICE" "$MYHOMEMOUNTPOINT"; then
1610          [ -f "$MYHOMEMOUNTPOINT/grml.img" ] && MYHOMEDIR="$MYHOMEMOUNTPOINT/grml.img"
1611          while read device mountpoint fs relax; do
1612            case "$mountpoint" in *$MYHOMEMOUNTPOINT*)
1613              case "$fs" in
1614                *[Nn][Tt][Ff][Ss]*)
1615                  umount "$MYHOMEMOUNTPOINT"; eerror "Error: will not mount NTFS filesystem on $MYHOMEDEVICE read/write!" ; eend 1
1616                  break
1617                  ;;
1618                *[Ff][Aa][Tt]*)
1619                  # Note: This currently won't work with encrypted partitions
1620                  umount "$MYHOMEMOUNTPOINT"; mount -t vfat -o rw,uid=grml,gid=grml,umask=002 "$MYHOMEDEVICE" "$MYHOMEMOUNTPOINT"
1621                  if [ ! -f "$MYHOMEDIR" ]; then
1622                     ewarn "WARNING: FAT32 is not a good filesystem option for /home/grml (missing socket/symlink support)."
1623                     ewarn "WARNING: Better use an ext2 loopback file on this device, and boot with home=$MYHOMEDEVICE/grml.img."
1624                  fi
1625                  ;;
1626              esac
1627
1628              if mount -o remount,rw "$MYHOMEMOUNTPOINT"; then
1629                 einfo "Mounting ${WHITE}$MYHOMEDIR${NORMAL} as ${WHITE}/home/grml${NORMAL}."
1630                 if [ -f "$MYHOMEDIR" ]; then
1631                    # It's a loopback file, mount it over the /home/grml directory
1632                    trymount "$MYHOMEDIR" /home/grml
1633                    RC="$?"
1634                    [ "$RC" = "0" ] && ERROR="$(mount -o remount,rw /home/grml 2>&1)"
1635                    RC="$?"
1636                 else
1637                    # Do a --bind mount
1638                    ERROR="$(mount --bind "$MYHOMEDIR" /home/grml 2>&1)"
1639                    RC="$?"
1640                 fi # -f $MYHOMEDIR
1641
1642                 [ "$RC" = "0" ] && eend 0 || ( eerror "${ERROR}" ; eend 1 )
1643
1644              fi #  mount -o remount,rw,...
1645            break
1646            ;;
1647            esac # case "$mountpoint" in *$MYHOMEMOUNTPOINT*)
1648          done <<EOT
1649          $(cat /proc/mounts)
1650 EOT
1651      fi # if trymount ...
1652    fi # -n $MYHOMEDIR
1653 fi # checkbootparam home
1654 }
1655 # }}}
1656
1657 # {{{ Sound
1658
1659 config_mixer(){
1660 if ! [ -x /usr/bin/amixer ] ; then
1661   eerror "amixer binary not available. Can not set sound volumes therefore." ; eend 1
1662 else
1663
1664   if ! [ -r /proc/asound/cards ] ; then
1665      ewarn "No soundcard present, skipping mixer settings therefore." ; eend 0
1666      return
1667   fi
1668
1669   if checkbootparam 'vol' ; then
1670     VOL="$(getbootparam 'vol' 2>>$DEBUG)"
1671     if [ -z "$VOL" ] ; then
1672       eerror "Bootoption vol found but no volume level/parameter given. Using defaults." ; eend 1
1673       VOL='75' # default
1674     fi
1675   else
1676     VOL='75' # default
1677   fi
1678
1679   if checkbootparam 'nosound' ; then
1680     einfo "Muting sound devices on request."
1681
1682     fix_ibm_sound 0
1683     # mute the master, this should be sufficient
1684     ERROR=$(amixer -q set Master mute)
1685     RC=$?
1686
1687     if [ -n "$ERROR" ] ; then
1688        eindent
1689        eerror "Problem muting sound devices: $ERROR"
1690        eoutdent
1691     fi
1692     eend $RC
1693   elif [ -z "$INSTALLED" ]; then
1694       einfo "Setting mixer volumes to level ${WHITE}${VOL}${NORMAL}."
1695
1696       fix_ibm_sound ${VOL}
1697
1698       # by default assume '0' as volume for microphone:
1699       if checkbootparam 'micvol' ; then
1700          MICVOL="$(getbootparam 'micvol' 2>>$DEBUG)"
1701       else
1702          MICVOL=0
1703       fi
1704
1705       # finally set the volumes:
1706       RC=0
1707       for CONTROL in Master PCM ; do
1708          amixer -q set ${CONTROL} ${VOL}%
1709          if [ $? -ne 0 ] ; then RC=$? ; fi
1710       done
1711       # dont know how to set microphone volume for all soundcards with amixer,
1712       # so use aumix instead :/
1713       if [ ${MICVOL} -ne 0 -a -x /usr/bin/aumix ] ; then
1714          aumix -m $MICVOL &>/dev/null
1715          if [ $? -ne 0 ] ; then RC=$? ; fi
1716       fi
1717
1718       eend $RC
1719   fi
1720
1721 fi
1722 }
1723
1724 # on some IBM notebooks the front control has to be toggled
1725 fix_ibm_sound() {
1726  if [ -z $1 ] ; then
1727     return
1728  fi
1729
1730  VOL=${1}
1731
1732  if [ -x /usr/bin/amixer ] ; then
1733     if amixer -q get Front 1>/dev/null 2>>$DEBUG ; then
1734        amixer -q set Front unmute &>/dev/null
1735        amixer -q set Front ${VOL}% &>/dev/null
1736     fi
1737  fi
1738 }
1739 # }}}
1740
1741 # {{{ modem detection
1742 config_modem(){
1743 if checkbootparam 'nomodem'; then
1744   ewarn "Skipping check for AC97 modem controller as requested on boot commandline." ; eend 0
1745 else
1746   if [ -x /etc/init.d/sl-modem-daemon ] ; then
1747      if lspci | grep Intel | grep -q "AC'97 Modem Controller" ; then
1748         einfo "AC97 modem controller detected. Start it running 'Start sl-modem-daemon'."
1749         eend 0
1750      fi
1751   fi
1752 fi
1753 }
1754 # }}}
1755
1756 # {{{ keyboard add-ons
1757 config_setkeycodes(){
1758 if checkbootparam 'setkeycodes' ; then
1759  einfo "Setting keycodes as requested via bootparameter 'setkeycodes'."
1760   # MS MM keyboard add-on
1761   # fix
1762   setkeycodes e001 126 &>/dev/null
1763   setkeycodes e059 127 &>/dev/null
1764   # fn keys
1765   setkeycodes e03b 59 &>/dev/null
1766   setkeycodes e008 60 &>/dev/null
1767   setkeycodes e007 61 &>/dev/null
1768   setkeycodes e03e 62 &>/dev/null
1769   setkeycodes e03f 63 &>/dev/null
1770   setkeycodes e040 64 &>/dev/null
1771   setkeycodes e041 65 &>/dev/null
1772   setkeycodes e042 66 &>/dev/null
1773   setkeycodes e043 67 &>/dev/null
1774   setkeycodes e023 68 &>/dev/null
1775   setkeycodes e057 87 &>/dev/null
1776   setkeycodes e058 88 &>/dev/null
1777   # hp keycodes
1778   setkeycodes e00a 89 e008 90 &>/dev/null
1779  eend 0
1780 fi
1781 }
1782 # }}}
1783
1784 # {{{ wondershaper
1785 config_wondershaper(){
1786  if checkbootparam 'wondershaper' ; then
1787     WONDER="$(getbootparam 'wondershaper' 2>>$DEBUG)"
1788     CMD=wondershaper
1789     DEVICE=""
1790     DOWNSTREAM=""
1791     UPSTREAM=""
1792     if [ -n "$WONDER" ]; then
1793       # Extra options
1794       DEVICE="${WONDER%%,*}"
1795       R="${WONDER#*,}"
1796       if [ -n "$R" -a "$R" != "$WONDER" ]; then
1797         WONDER="$R"
1798         DOWNSTREAM="${WONDER%%,*}"
1799         R="${WONDER#*,}"
1800         if [ -n "$R" -a "$R" != "$WONDER" ]; then
1801           WONDER="$R"
1802           UPSTREAM="${WONDER%%,*}"
1803           R="${WONDER#*,}"
1804         fi
1805       fi
1806     fi
1807     [ -n "$DEVICE" ]     && CMD="$CMD $DEVICE"
1808     [ -n "$DOWNSTREAM" ] && CMD="$CMD $DOWNSTREAM"
1809     [ -n "$UPSTREAM" ]   && CMD="$CMD $UPSTREAM"
1810     einfo "Starting wondershaper (${CMD}) in background."
1811     ( sh -c $CMD & ) && eend 0
1812  fi
1813 }
1814 # }}}
1815
1816 # {{{ syslog-ng
1817 config_syslog(){
1818  if checkbootparam 'nosyslog'; then
1819     ewarn "Not starting syslog daemon as requested on boot commandline." ; eend 0
1820  else
1821     SYSLOGD=''
1822     [ -x /etc/init.d/syslog-ng ] && SYSLOGD='syslog-ng'
1823     [ -x /etc/init.d/rsyslog   ] && SYSLOGD='rsyslog'
1824     [ -x /etc/init.d/dsyslog   ] && SYSLOGD='dsyslog'
1825     [ -x /etc/init.d/sysklogd  ] && SYSLOGD='sysklogd'
1826     [ -x /etc/init.d/inetutils-syslogd ] && SYSLOGD='inetutils-syslogd'
1827
1828     if [ -z "$SYSLOGD" ] ; then
1829        eerror "No syslog daemon found." ; eend 1
1830     else
1831        einfo "Starting $SYSLOGD in background."
1832        /etc/init.d/$SYSLOGD start 1>>$DEBUG &
1833        eend 0
1834     fi
1835  fi
1836 }
1837 # }}}
1838
1839 # {{{ gpm
1840 config_gpm(){
1841  if checkbootparam 'nogpm'; then
1842   ewarn "Not starting GPM as requested on boot commandline." ; eend 0
1843  else
1844    if ! [ -r /dev/input/mice ] ; then
1845       eerror "No mouse found - not starting GPM." ; eend 1
1846    else
1847       einfo "Starting gpm in background."
1848       /etc/init.d/gpm start 1>>$DEBUG &
1849       # ( while [ ! -e /dev/psaux ]; do sleep 5; done; /etc/init.d/gpm start 1>>$DEBUG ) &
1850       eend 0
1851    fi
1852  fi
1853 }
1854 # }}}
1855
1856 # {{{ services
1857 config_services(){
1858  if checkbootparam 'services' ; then
1859     SERVICE="$(getbootparam 'services' 2>>$DEBUG)"
1860     SERVICELIST=$(echo "$SERVICE" | sed 's/,/\\n/g')
1861     SERVICENL=$(echo "$SERVICE" | sed 's/,/ /g')
1862     einfo "Starting service(s) ${SERVICENL} in background."
1863     for service in $(echo -e $SERVICELIST) ; do
1864        /etc/init.d/${service} start 1>>$DEBUG &
1865     done
1866     [ "$?" == "0" ] ; eend $?
1867  fi
1868 }
1869 # }}}
1870
1871 # {{{ remote files
1872 get_remote_file() {
1873   [ "$#" -eq 2 ] || ( echo "Error: wrong parameter for get_remote_file()" ; return 1 )
1874   SOURCE=$(eval echo "$1")
1875   TARGET="$2"
1876   getconfig() {
1877   wget --timeout=10 --dns-timeout=10  --connect-timeout=10 --tries=1 \
1878        --read-timeout=10 ${SOURCE} -O ${TARGET} && return 0 || return 1
1879   }
1880   einfo "Trying to get ${WHITE}${TARGET}${NORMAL}"
1881   counter=10
1882   while ! getconfig && [[ "$counter" != 0 ]] ; do
1883     echo -n "Sleeping for 1 second and trying to get config again... "
1884     counter=$(( counter-1 ))
1885     echo "$counter tries left" ; sleep 1
1886   done
1887   if [ -s "$TARGET" ] ; then
1888     einfo "Downloading was successfull." ; eend 0
1889     einfo "md5sum of ${WHITE}${TARGET}${NORMAL}: "
1890     md5sum ${TARGET} ; eend 0
1891     return 0;
1892   else
1893     einfo "Sorry, could not fetch ${SOURCE}" ; eend 1
1894     return 1;
1895  fi
1896 }
1897 # }}}
1898
1899 # {{{ config files
1900 config_netconfig(){
1901  if checkbootparam 'netconfig' ; then
1902   CONFIG="$(getbootparam 'netconfig' 2>>$DEBUG)"
1903   CONFIGFILE='/tmp/netconfig.grml'
1904
1905   if get_remote_file ${CONFIG} ${CONFIGFILE} ; then
1906     cd / && einfo "Unpacking ${WHITE}${CONFIGFILE}${NORMAL}:" && /usr/bin/unp $CONFIGFILE $EXTRACTOPTIONS ; eend $?
1907   fi
1908
1909  fi
1910 }
1911 # }}}
1912
1913 # {{{ remote scripts
1914 config_netscript() {
1915  if checkbootparam 'netscript' ; then
1916   CONFIG="$(getbootparam 'netscript' 2>>$DEBUG)"
1917   SCRIPTFILE='/tmp/netscript.grml'
1918
1919   if get_remote_file ${CONFIG} ${SCRIPTFILE} ; then
1920     chmod +x ${SCRIPTFILE}
1921     einfo "Running ${WHITE}${SCRIPTFILE}${NORMAL}:" && ${SCRIPTFILE} ; eend $?
1922   fi
1923
1924  fi
1925 }
1926 # }}}
1927
1928 # {{{ blindsound
1929 config_blindsound(){
1930  if checkbootparam 'blind' ; then
1931     beep
1932     flitewrapper "welcome to the gremel system"
1933  fi
1934 }
1935 # }}}
1936
1937 # {{{ welcome sound
1938 config_welcome(){
1939  if checkbootparam 'welcome' ; then
1940     flitewrapper "welcome to the gremel system"
1941  fi
1942 }
1943 # }}}
1944
1945 # {{{ fix/workaround for unionfs
1946 fix_unionfs(){
1947   if [ -z "$INSTALLED" ]; then
1948    touch /var/cache/apt/*cache.bin
1949   fi
1950 }
1951 # }}}
1952
1953 # {{{ create all /mnt-directories
1954 create_mnt_dirs(){
1955   ewarn "create_mnt_dirs is deprecated as grml-rebuildfstab does all we need."
1956   ewarn "Please set CONFIG_CREATE_MNT_DIRS='no' in /etc/grml/autoconfig" ; eend 0
1957 }
1958 # }}}
1959
1960 # {{{ start X window system via grml-x
1961 config_x_startup(){
1962 # make sure we start X only if startx is used *before* a nostartx option
1963 # so it's possible to disable automatic X startup using nostart
1964 if checkbootparam 'startx' && ! echo "$CMDLINE" | grep -q 'startx.*nostartx' ; then
1965  if [ -x $(which X) ] ; then
1966   if [ -z "$INSTALLED" ] ; then
1967    WINDOWMANAGER="$(getbootparam 'startx' 2>>$DEBUG)"
1968    if [ -z "$WINDOWMANAGER" ] ; then
1969      einfo "No window manager specified. Taking ${WHITE}wm-ng${NORMAL} as default." && eend 0
1970      WINDOWMANAGER="wm-ng"
1971    else
1972      einfo "Window manager ${WHITE}${WINDOWMANAGER}${NORMAL} found as bootoption." && eend 0
1973    fi
1974    einfo "Changing to runlevel 5 for starting grml-x ${WINDOWMANAGER}. Just exit X windows system to get full featured consoles."
1975    config_userfstab || fstabuser='grml'
1976  cat>|/etc/init.d/xstartup<<EOF
1977 #!/bin/sh
1978 # su - $fstabuser -c 'grml-x "$WINDOWMANAGER"'
1979 sudo -u $fstabuser -i /usr/bin/grml-x $WINDOWMANAGER 1>>$DEBUG
1980 EOF
1981    chmod 755 /etc/init.d/xstartup
1982
1983    # adjust inittab for xstartup
1984    if grep -q '^6:' /etc/inittab ; then
1985       sed -i 's|^6:.*|6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /bin/zsh"|' /etc/inittab
1986    else # just append tty6 to inittab if no definition is present:
1987       echo '6:2345:respawn:/bin/zsh --login -c "/etc/init.d/xstartup ; /bin/zsh"' >> /etc/inittab
1988    fi
1989
1990    /sbin/telinit q ; eend $?
1991
1992    if grep -q '^allowed_users=' /etc/X11/Xwrapper.config ; then
1993       sed -i 's/^allowed_users=.*/allowed_users=anybody/' /etc/X11/Xwrapper.config
1994    else
1995       echo 'allowed_users=anybody' >> /etc/X11/Xwrapper.config
1996    fi
1997
1998   else
1999     eerror "We are not running in live mode - startx will not work, skipping it."
2000     eerror " -> Please use something like xdm, gdm or kdm for starting X on a harddisk system!" ; eend 1
2001   fi
2002  else
2003    eerror "/usr/X11R6/bin/X is not present on this grml flavour."
2004    eerror "  -> Boot parameter startx does not work therefore." ; eend 1
2005  fi
2006 fi
2007 }
2008 # }}}
2009
2010 # {{{ configuration framework
2011 config_extract(){
2012 if checkbootparam 'extract' ; then
2013  EXTRACT="$(getbootparam 'extract' 2>>$DEBUG)"
2014  EXTRACTOPTIONS="-- -x $EXTRACT"
2015 fi
2016 }
2017
2018 config_finddcsdir() {
2019 #  - If no GRMLCFG partition is found and noautoconfig is _not_ given
2020 #    on the command line, nothing is changed and the dcs files are
2021 #    searched within the .iso, $dcs-dir is set to the root directory
2022 #    within the .iso
2023 #  - If a GRMLCFG partition is found, $dcs-dir is set to the root of
2024 #    the GRMLCFG partition unless noautoconfig is set. If noautoconfig is
2025 #    set, $dcs-dir is set to the root directory within the .iso.
2026 #  - If myconfig=foo is set on the command line, $dcs-dir is set to
2027 #    foo, even if a GRMLCFG partition is present.
2028 DCSDIR=""
2029 DCSMP="/mnt/grml"
2030 if checkbootparam 'noautoconfig' || checkbootparam 'forensic' ; then
2031   ewarn "Skipping running automount of device(s) labeled GRMLCFG as requested." ; eend 0
2032 else
2033   if [ -z "$INSTALLED" ] ; then
2034     if checkbootparam 'myconfig' ; then
2035       DCSDEVICE="$(getbootparam 'myconfig' 2>>$DEBUG)"
2036       if [ -z "$DCSDEVICE" ]; then
2037         eerror "Error: No device for bootoption myconfig provided." ; eend 1
2038       fi # [ -z "$DCSDEVICE" ]
2039     elif checkvalue $CONFIG_MYCONFIG; then # checkbootparam myconfig
2040       einfo "Searching for device(s) labeled with GRMLCFG. (Disable this via boot option: noautoconfig)" ; eend 0
2041       eindent
2042       # We do need the following fix so floppy disk is available to blkid in any case :-/
2043       if [ -r /dev/fd0 ] ; then
2044         einfo "Floppy device detected. Trying to access floppy disk."
2045         if timeout 4 dd if=/dev/fd0 of=/dev/null bs=512 count=1 1>>$DEBUG 2>&1 ; then
2046            blkid /dev/fd0 1>>$DEBUG 2>&1
2047         fi
2048       fi
2049       DCSDEVICE=$(blkid -t LABEL=GRMLCFG | head -1 | awk -F: '{print $1}')
2050       if [ -n "$DCSDEVICE" ]; then
2051         DCSMP="/mnt/grmlcfg"
2052       fi
2053       eoutdent
2054     fi
2055
2056     # if not specified/present then assume default:
2057     if [ -z "$DCSDEVICE" ]; then
2058       DCSDIR="/live/image"
2059     else
2060       eindent
2061       einfo "debs, config, scripts are read from $DCSDEVICE." ; eend 0
2062       DCSDIR="$(< /proc/mounts awk -v DCSDEV=$DCSDEVICE '{if ($1 == DCSDEV) { print $2 }}')"
2063       if [ -n "$DCSDIR" ]; then
2064         ewarn "$DCSDEVICE already mounted on $DCSDIR"; eend 0
2065       else
2066         [ -d $DCSMP ] || mkdir $DCSMP
2067         umount $DCSMP 1>>$DEBUG 2>&1 # make sure it is not mounted
2068         mount -o ro -t auto $DCSDEVICE  $DCSMP ; RC="$?"
2069         if [[ $RC == 0 ]]; then
2070           einfo "Successfully mounted $DCSDEVICE to $DCSMP (readonly)." ; eend 0
2071         else
2072           eerror "Error: mounting $DCSDEVICE to $DCSMP (readonly) failed." ; eend 1
2073         fi
2074         DCSDIR="$DCSMP"
2075       fi
2076       eoutdent
2077     fi
2078   fi
2079 fi
2080
2081 if [ -n "$DCSDIR" -a "$DCSDIR" != "/live/image" ] ; then
2082   einfo "Debs, config, scripts (if present) will be read from $DCSDIR." ; eend 0
2083 elif checkbootparam 'debs' || checkbootparam 'config' || checkbootparam 'scripts'; then
2084   einfo "Debs, config, scripts will be read from the live image directly." ; eend 0
2085 fi
2086 }
2087
2088
2089 config_partconf() {
2090 if checkbootparam 'partconf' ; then
2091  MOUNTDEVICE="$(getbootparam 'partconf' 2>>$DEBUG)"
2092  if [ -n "$MOUNTDEVICE" ]; then
2093    [ -d /mnt/grml ] || mkdir /mnt/grml
2094    mount -o ro -t auto $MOUNTDEVICE /mnt/grml ; RC="$?"
2095     if [[ $RC == 0 ]]; then
2096       einfo "Successfully mounted $MOUNTDEVICE to /mnt/grml (readonly)." ; eend 0
2097       einfo "Copying files from $MOUNTDEVICE over grml system."
2098       for file in `cat /etc/grml/partconf` ; do
2099         [ -d /mnt/grml/$file ] && cp -a /mnt/grml/${file}* ${file} && echo "copied: $file"
2100         [ -f /mnt/grml/$file ] && cp -a /mnt/grml/${file}  ${file} && echo "copied: $file"
2101       done && eend 0
2102     else
2103       einfo "Could not mount $MOUNTDEVICE to /mnt/grml - sorry." ; eend 1
2104     fi # mount $MOUNTDEVICE
2105    grep -q '/mnt/grml' /proc/mounts && umount /mnt/grml
2106  else
2107    einfo "Sorry, no device for bootoption partconf provided. Skipping." ; eend 1
2108  fi # [ -n "$MOUNTDEVICE" ]
2109 fi
2110 }
2111 # }}}
2112
2113 # {{{ /cdrom/.*-options
2114 config_debs(){
2115 if checkbootparam 'debs' ; then
2116    DEBS="$(getbootparam 'debs' 2>>$DEBUG)"
2117    if ! echo $DEBS | grep -q '/'; then
2118      # backwards compatibility: if no path is given get debs from debs/
2119      DEBS="debs/$DEBS"
2120    fi
2121    einfo "Tring to install debian package(s) ${DEBS}"
2122    DEBS="$(eval echo ${DCSDIR}/$DEBS)"
2123    dpkg -i $DEBS ; eend $?
2124 fi
2125 }
2126
2127 config_scripts(){
2128 if checkbootparam 'scripts' || [ "$DCSMP" = "/mnt/grmlcfg" ]; then
2129    SCRIPTS="$(getbootparam 'scripts' 2>>$DEBUG)"
2130    if [ -d ${DCSDIR}/scripts ] && [ -z "$SCRIPTS" ]; then
2131      SCRIPTS="$(cd ${DCSDIR}/scripts; /bin/ls -1d [Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)"
2132    fi
2133    if ! echo $SCRIPTS | grep -q '/'; then
2134      # backwards compatibility: if no path is given get scripts from scripts/
2135      SCRIPTS="scripts/$SCRIPTS"
2136    fi
2137    if [ "$DCSMP" = "/mnt/grmlcfg" ]; then
2138      # we are executing from a GRMLCFG labeled fs
2139      # kick everything we have done before and start over
2140      SCRIPTS="$(cd ${DCSDIR}; /bin/ls -1d [Gg][Rr][Mm][Ll].[Ss][Hh] 2>>$DEBUG)"
2141    fi
2142    if [ -n "$SCRIPTS" ]; then
2143      SCRIPTS="${DCSDIR}/$SCRIPTS"
2144      if [ "$DCSMP" = "/mnt/grmlcfg" ]; then
2145        einfo "Trying to execute ${SCRIPTS}"
2146        sh -c $SCRIPTS
2147      elif [ -d "$SCRIPTS" ]; then
2148        einfo "Bootparameter scripts found. Trying to execute from directory ${SCRIPTS}:"
2149        run-parts $SCRIPTS
2150      else
2151        einfo "Bootparameter scripts found. Trying to execute ${SCRIPTS}:"
2152        sh -c $SCRIPTS
2153      fi
2154    fi
2155 fi
2156 }
2157
2158 config_config(){
2159 if checkbootparam 'config' || [ "$DCSMP" = "/mnt/grmlcfg" ]; then
2160   CONFIG="$(getbootparam 'config' 2>>$DEBUG)"
2161   if [ -z "$CONFIG" ]; then
2162     CONFIG="$(cd ${DCSDIR}; ls -1d [Cc][Oo][Nn][Ff][Ii][Gg].[Tt][Bb][Zz] 2>>$DEBUG)"
2163   fi
2164   if [ -n "$CONFIG" ]; then
2165     if [ -d "${DCSDIR}/${CONFIG}" ] ; then
2166       einfo "Taking configuration from directory ${DCSDIR}/${CONFIG}"
2167
2168       cp -a ${DCSDIR}/${CONFIG}/* /
2169     elif [ -f "${DCSDIR}/${CONFIG}" ]; then
2170       einfo "Extracting configuration from file ${DCSDIR}/${CONFIG}"
2171
2172       cd /
2173       unp ${DCSDIR}/${CONFIG} $EXTRACTOPTIONS ; eend $?
2174     else
2175       ewarn "Sorry, could not find configuration file or directory ${DCSDIR}/${FILENAME}." ; eend 1
2176     fi
2177   fi
2178 fi
2179 # umount $DCSMP if it was mounted by finddcsdir
2180 # this doesn't really belong here
2181 grep -q '$DCSMP' /proc/mounts && umount $DCSMP
2182 }
2183 # }}}
2184
2185 # {{{ mypath
2186 config_mypath(){
2187 if checkbootparam 'mypath' ; then
2188    MY_PATH="$(getbootparam 'mypath' 2>>$DEBUG)"
2189    einfo "Bootparameter mypath found, adding ${MY_PATH} to /etc/grml/my_path"
2190    touch /etc/grml/my_path
2191    chmod 644 /etc/grml/my_path
2192    # make sure the directories exist:
2193    eindent
2194    for i in $(echo $MY_PATH | sed 's/:/\n/g') ; do
2195        if ! [ -d "$i" ] ; then
2196           einfo "Creating directory $i"
2197           mkdir -p "$i" ; eend $?
2198        fi
2199    done
2200    grep -q "${MY_PATH}" /etc/grml/my_path || echo "${MY_PATH}" >> /etc/grml/my_path ; eend $?
2201    eoutdent
2202 fi
2203 }
2204 # }}}
2205
2206 # {{{ distcc
2207 config_distcc(){
2208 if checkbootparam 'distcc' ; then
2209  OPTIONS="$(getbootparam 'distcc' 2>>$DEBUG)"
2210  if [ -n "$OPTIONS" ]; then
2211     NET=""
2212     INTERFACE=""
2213     if [ -n "$OPTIONS" ]; then
2214       NET="${OPTIONS%%,*}"
2215       R="${OPTIONS#*,}"
2216       if [ -n "$R" -a "$R" != "$OPTIONS" ]; then
2217         OPTIONS="$R"
2218         INTERFACE="${OPTIONS%%,*}"
2219         R="${OPTIONS#*,}"
2220       fi
2221     fi
2222  fi
2223  CONFIG=/etc/default/distcc
2224  sed -i "s#^STARTDISTCC=.*#STARTDISTCC=YES#"  $CONFIG
2225  sed -i "s#^ALLOWEDNETS=.*#ALLOWEDNETS=$NET#" $CONFIG
2226
2227  if [ -n "$INTERFACE" ] ; then
2228    IP=$(LANG=C ifconfig $INTERFACE | gawk -F: /"inet addr"/'{print $2}' | gawk '{print $1}')
2229
2230    counter=10
2231    while [ -z "$IP" ] && [[ "$counter" != 0 ]] ; do
2232      counter=$(( counter-1 ))
2233      ewarn "No ip address for $INTERFACE found. Sleeping for 3 seconds. $counter tries left."
2234      sleep 3
2235      IP=$(LANG=C ifconfig $INTERFACE | gawk -F: /"inet addr"/'{print $2}' | gawk '{print $1}')
2236    done
2237  fi
2238
2239  if [ -n "$IP" ] ; then
2240    sed -i "s#^LISTENER=.*#LISTENER=$IP#"      $CONFIG
2241
2242    einfo "Bootoption distcc found. Preparing setup for distcc daemon."
2243    eindent
2244     id distccd >/dev/null 2>&1 || \
2245     (
2246       einfo "Creating distcc user" ; \
2247       adduser --quiet --system --ingroup nogroup --home / --no-create-home distccd ; eend $?
2248     )
2249
2250     einfo "Starting distcc for network ${NET}, listening on ${IP}."
2251    /etc/init.d/distcc start 1>/dev/null ; eend $?
2252    eoutdent
2253  else
2254    eerror "No ip address for $INTERFACE found. distcc can not be used without it." ; eend 1
2255  fi
2256 fi
2257
2258 if checkbootparam 'gcc'; then
2259  GCC="$(getbootparam 'gcc' 2>>$DEBUG)"
2260  eindent
2261  einfo "Pointing /usr/bin/gcc to /usr/bin/gcc-${GCC}."
2262  eoutdent
2263  rm -f /usr/bin/gcc
2264  ln -s /usr/bin/gcc-${GCC} /usr/bin/gcc ; eend $?
2265 fi
2266
2267 if checkbootparam 'gpp'; then
2268  GPP="$(getbootparam 'gpp' 2>>$DEBUG)"
2269  eindent
2270   einfo "Pointing /usr/bin/g++ to /usr/bin/g++-${GPP}."
2271   if [ -x /usr/bin/g++-${GPP} ] ; then
2272      rm -f /usr/bin/g++
2273      ln -s /usr/bin/g++-${GPP} /usr/bin/g++ ; eend $?
2274   fi
2275   einfo "Pointing /usr/bin/cpp to /usr/bin/cpp-${GPP}."
2276   if [ -x /usr/bin/cpp-${GPP} ] ; then
2277      rm -f /usr/bin/cpp
2278      ln -s /usr/bin/cpp-${GPP} /usr/bin/cpp ; eend $?
2279   fi
2280  eoutdent
2281 fi
2282
2283 }
2284 # }}}
2285
2286 # {{{ load modules
2287 # Notice: use it only on live-cd system, if running from harddisk please
2288 # add modules to /etc/modules and activate /etc/init.d/module-init-tools
2289 # in /etc/runlevel.conf
2290 config_modules(){
2291 MODULES_FILE=/etc/grml/modules
2292 if checkbootparam 'nomodules' ; then
2293   ewarn "Skipping loading of modules defined in ${MODULES_FILE} as requested." ; eend 0
2294 elif [ -z "$INSTALLED" ]; then
2295  if [ -r $MODULES_FILE ] ; then
2296   einfo "Loading modules specified in ${MODULES_FILE}:"
2297   eindent
2298   grep '^[^#]' $MODULES_FILE | \
2299   while read module args; do
2300     [ "$module" ] || continue
2301       einfo "${module}"
2302       modprobe $module $args ; eend $?
2303   done
2304   eoutdent
2305  else
2306   ewarn "File $MODULES_FILE does not exist. Skipping loading of specific modules." ; eend 1
2307  fi
2308 fi
2309 }
2310 # }}}
2311
2312 # {{{ 915resolution
2313 config_915resolution(){
2314 if checkbootparam '915resolution' ; then
2315  OPTIONS="$(getbootparam '915resolution' 2>>$DEBUG)"
2316   if [ -x /usr/sbin/915resolution ]; then
2317     CMD=915resolution
2318     MODE=""
2319     XRESO=""
2320     YRESO=""
2321     if [ -n "$OPTIONS" ]; then
2322       # Extra options
2323       MODE="${OPTIONS%%,*}"
2324       R="${OPTIONS#*,}"
2325       if [ -n "$R" -a "$R" != "$OPTIONS" ]; then
2326         OPTIONS="$R"
2327         XRESO="${OPTIONS%%,*}"
2328         R="${OPTIONS#*,}"
2329         if [ -n "$R" -a "$R" != "$OPTIONS" ]; then
2330           OPTIONS="$R"
2331           YRESO="${OPTIONS%%,*}"
2332           R="${OPTIONS#*,}"
2333         fi
2334       fi
2335     fi
2336     einfo "Running 915resolution with options ${MODE} ${XRESO} ${YRESO}."
2337     [ -n "$MODE" ] && [ -n "$XRESO"  ] && [ -n "$YRESO" ]  && ( sh -c "$CMD $MODE $XRESO $YRESO" & )
2338     eend 0
2339   fi
2340 fi
2341 }
2342 # }}}
2343
2344 # {{{ SW-RAID
2345 config_swraid(){
2346   [ -n "$INSTALLED" ] && return 0
2347
2348   # notice: checkbootparam "forensic" is just for users who don't know how to really use the bootoption
2349   if checkbootparam 'noraid'   || checkbootparam 'noswraid' || \
2350      checkbootparam 'forensic' || checkbootparam 'raid=noautodetect' ; then
2351      ewarn "Skipping SW-RAID code as requested on boot commandline." ; eend 0
2352   else
2353     if ! [ -x /sbin/mdadm ] ; then
2354        eerror "mdadm not available, can not execute it." ; eend 1
2355     else
2356
2357        # if ! egrep -qv '^(MAILADDR.*|#.*|)$' /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
2358        # find out whether we have a valid configuration file already
2359        if ! grep -q ARRAY /etc/mdadm/mdadm.conf 2>>$DEBUG ; then
2360           einfo "Creating /etc/mdadm/mdadm.conf for use with mdadm."
2361           [ -r /etc/mdadm/mdadm.conf ] && mv /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf.old
2362           MDADM_MAILADDR__='root' /usr/share/mdadm/mkconf > /etc/mdadm/mdadm.conf ; eend $?
2363         else
2364           ewarn "/etc/mdadm/mdadm.conf looks like a configured mdadm setup, will not touch it." ; eend 0
2365        fi
2366
2367        if ! checkbootparam 'swraid' ; then
2368           eindent
2369           einfo "Just run 'Start mdadm-raid' to assemble md arrays or boot using 'swraid' as bootoption for autostart."
2370           eoutdent
2371        else
2372           einfo "Bootoption swraid found. Searching for software RAID arrays:"
2373           eindent
2374            IFSOLD=${IFS:-}
2375            IFS='
2376 '
2377            for line in $(mdadm --assemble --scan --auto=yes --symlink=no 2>&1) ; do
2378                case $line in
2379                  *'No arrays found'*)
2380                    ewarn "$line" ; eend 0
2381                    ;;
2382                  *)
2383                    einfo "$line" ; eend 0
2384                    ;;
2385                esac
2386            done
2387            IFS=$IFSOLD
2388          eoutdent
2389
2390          if [ -r /proc/mdstat ] ; then
2391             eindent
2392             MDSTAT=$(grep '^md[0-9]' /proc/mdstat)
2393             if [ -z "$MDSTAT" ] ; then
2394                ewarn "No active arrays found" ; eend 0
2395             else
2396                IFSOLD=${IFS:-}
2397                IFS='
2398 '
2399                for line in $(grep '^md[0-9]' /proc/mdstat) ; do
2400                    einfo "active arrays: $line" ; eend 0
2401                done
2402                IFS=$IFSOLD
2403             fi
2404             eoutdent
2405          fi # /proc/mdstat
2406        fi # bootoption swraid
2407
2408      fi # is /sbin/mdadm executable?
2409   fi # check for bootoptions
2410 }
2411 # }}}
2412
2413 # {{{ dmraid
2414 config_dmraid(){
2415   [ -n "$INSTALLED" ] && return 0
2416
2417   if checkbootparam 'nodmraid' ; then
2418     ewarn "Skipping dmraid code as requested on boot commandline." ; eend 0
2419     return 0
2420   fi
2421
2422   if ! [ -x /sbin/dmraid ] ; then
2423     eerror "dmraid not available, can not execute it." ; eend 1
2424     return
2425   fi
2426
2427   dmraid_wrapper() {
2428     # usage: dmraid_wrapper <dmraid_option>
2429     [ -n "$1" ] || return 1
2430
2431     IFSOLD=${IFS:-}
2432     IFS='
2433 '
2434     eindent
2435
2436     for line in $(dmraid $1 ; echo errcode:$?); do
2437       case $line in
2438         *'no raid disks'*)
2439           einfo "No active dmraid devices found" ; eend 0
2440           break
2441           ;;
2442         errcode:0)
2443           eend 0;
2444           ;;
2445         errcode:1)
2446           eend 1
2447           ;;
2448         *)
2449           einfo "$line"
2450           ;;
2451       esac
2452     done
2453
2454     eoutdent
2455     IFS=$IFSOLD
2456   }
2457
2458   if checkbootparam 'dmraid' ; then
2459     local ACTION="$(getbootparam 'dmraid' 2>>$DEBUG)"
2460     if [ "$ACTION" = "off" ] ; then
2461       # Deactivates all active software RAID sets:
2462       einfo "Deactivating present dmraid sets (as requested via dmraid=off):"
2463       dmraid_wrapper -an
2464     else
2465       # Activate all software RAID sets discovered:
2466       einfo "Activating present dmraid sets (as requested via dmraid):"
2467       dmraid_wrapper -ay
2468     fi
2469
2470     return
2471   fi
2472
2473   # by default (no special bootoptions) discover all software RAID devices:
2474   einfo "Searching for any present dmraid sets:"
2475   dmraid_wrapper -r
2476 }
2477 # }}}
2478
2479 # {{{ LVM (Logical Volumes)
2480 config_lvm(){
2481   [ -n "$INSTALLED" ] && return 0
2482
2483   if checkbootparam 'nolvm' ; then
2484      ewarn "Skipping LVM code as requested on boot commandline." ; eend 0
2485   else
2486     # Debian etch provides /etc/init.d/lvm only, newer suites provide /etc/init.d/lvm2
2487     if ! [ -x /sbin/lvm -a -x /sbin/lvdisplay ] || ! [ -x /etc/init.d/lvm2 -o -x /etc/init.d/lvm ] ; then
2488        eerror "LVM not available, can not execute it." ; eend 1
2489     else
2490        if lvdisplay 2>&1 | grep -v 'No volume groups found' 1>/dev/null 2>&1 ; then
2491           einfo "You seem to have logical volumes (LVM) on your system."
2492           eindent
2493           einfo "Just run 'Start lvm2' to activate them or boot using 'lvm' as bootoption for autostart."
2494           eend 0
2495           if checkbootparam 'lvm' ; then
2496              einfo "Bootoption LVM found. Searching for logical volumes:"
2497              /etc/init.d/lvm2 start ; eend $?
2498           fi
2499           eoutdent
2500        fi
2501     fi # check for lvm binary
2502   fi # check for bootoption nolvm
2503 }
2504 # }}}
2505
2506 # {{{ debnet: setup network based on an existing one found on a partition
2507 config_debnet(){
2508 if checkbootparam 'debnet' ; then
2509  iszsh && setopt shwordsplit
2510  DEVICES="$(< /proc/partitions tail -n +3 | awk '{print "/dev/"$4}' | tr "\n" " ")"
2511  DEVICES="$DEVICES $(ls /dev/mapper/*)"
2512  FOUND_DEBNET=""
2513
2514  einfo "Bootoption 'debnet' found. Searching for Debian network configuration: "
2515  eindent
2516  if ! mount | grep '/mnt ' 1>/dev/null 2>&1 ; then
2517     for i in $DEVICES; do
2518      if mount -o ro -t auto "$i" /mnt >/dev/null 2>&1; then
2519          einfo "Scanning on $i"
2520        if [ -f /mnt/etc/network/interfaces ]; then
2521          einfo "/etc/network/interfaces found on ${i}" ; eend 0
2522          FOUND_DEBNET="$i"
2523          break
2524        fi
2525        umount /mnt
2526      fi
2527     done
2528
2529    if [ -n "$FOUND_DEBNET" ]; then
2530      einfo "Stopping network."
2531        pump -k 1>/dev/null 2>&1
2532        /etc/init.d/networking stop 1>/dev/null 2>&1 ; eend $?
2533      einfo "Copying Debian network configuration from $FOUND_DEBNET to running system."
2534        rm -rf /etc/network/run
2535        cp -a /mnt/etc/network /etc
2536        rm -rf /etc/network/run
2537        mkdir /etc/network/run
2538        umount /mnt ; eend $?
2539      einfo "Starting network."
2540        invoke-rc.d networking start ; eend $?
2541    else
2542      eerror "/etc/network/interfaces not found." ; eend 1
2543    fi
2544    eoutdent
2545  else
2546   eerror "Error: /mnt already mounted." ; eend 1
2547  fi
2548 fi
2549 }
2550 # }}}
2551
2552 # {{{ check for broken ipw3945 driver which causes problems (especially on hd install)
2553 config_ipw3945() {
2554   if grep -q ipw3945 /proc/modules ; then
2555      if ! iwconfig 2>/dev/null| grep -qe 'IEEE 802' -qe 'unassociated' ; then
2556         ewarn "Broken ipw3945 network interface found, reloading module."
2557         rmmod ipw3945
2558         modprobe ipw3945
2559         eend $?
2560      fi
2561   fi
2562 }
2563 # }}}
2564
2565 # {{{ disable console blanking
2566 config_blanking(){
2567 if checkbootparam 'noblank' ; then
2568   einfo "Bootoption noblank found. Disabling monitor blanking."
2569   setterm -blank 0 ; eend $?
2570 fi
2571 }
2572 # }}}
2573
2574 # {{{ tohd= bootoption
2575 config_tohd()
2576 {
2577   if checkbootparam 'tohd' ; then
2578      local TARGET="$(getbootparam 'tohd' 2>>$DEBUG)"
2579      if [ -z "$TARGET" ] ; then
2580         eerror "Error: tohd specified without any partition, can not continue." ; eend 1
2581         eerror "Please use something like tohd=/dev/sda9." ; eend 1
2582         return 1
2583      fi
2584
2585      if ! [ -b "$TARGET" ] ; then
2586         eerror "Error: $TARGET is not a valid block device, sorry." ; eend 1
2587         return 1
2588      fi
2589
2590      if grep -q $TARGET /proc/mounts ; then
2591         eerror "$TARGET already mounted, skipping execution of tohd therefore."
2592         eend 1
2593         return 1
2594      fi
2595
2596      local MOUNTDIR=$(mktemp -d)
2597
2598      if mount -o rw "$TARGET" "$MOUNTDIR" ; then
2599         einfo "Copyring live system to $TARGET - this might take a while"
2600         rsync -a --progress /live/image/live $MOUNTDIR
2601         sync
2602         umount "$MOUNTDIR"
2603         eend $?
2604         einfo "Booting with \"grml bootfrom=$TARGET\" should work now." ; eend 0
2605      else
2606         eerror "Error when trying to mount $TARGET, sorry."; eend 1
2607         return 1
2608      fi
2609
2610      rmdir "$MOUNTDIR"
2611   fi
2612 }
2613 # }}}
2614
2615 # {{{ grml2hd: automatic installation
2616 config_grml2hd(){
2617
2618 if checkbootparam "BOOT_IMAGE=grml2hd" ; then
2619
2620 if checkbootparam 'user' ; then
2621    NEWUSER=''
2622    NEWUSER="$(getbootparam 'user' 2>>$DEBUG)"
2623    sed -i "s/^NEWUSER=.*/NEWUSER=$NEWUSER/" /etc/grml2hd/config || export GRML2HD_FAIL=1
2624 fi
2625
2626 if checkbootparam 'filesystem' ; then
2627    FILESYSTEM=''
2628    FILESYSTEM="$(getbootparam 'filesystem' 2>>$DEBUG)"
2629    sed -i "s/^FILESYSTEM=.*/FILESYSTEM=$FILESYSTEM/" /etc/grml2hd/config || export GRML2HD_FAIL=1
2630 fi
2631
2632 if checkbootparam 'partition' ; then
2633    PARTITION=''
2634    PARTITION="$(getbootparam 'partition' 2>>$DEBUG)"
2635    # notice: the following checks whether the given partition is available, if not the skip
2636    # execution of grml2hd as it might result in data loss...
2637    if [ -r $PARTITION ] ; then
2638       sed -i "s#^PARTITION=.*#PARTITION=$PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
2639    else
2640       ewarn "Partition $PARTITION does not exist. Skipping execution of grml2hd therefore." ; eend 1
2641    fi
2642 fi
2643
2644 if checkbootparam 'mbr' ; then
2645    BOOT_PARTITION=''
2646    BOOT_PARTITION="$(getbootparam 'mbr' 2>>$DEBUG)"
2647    sed -i "s#^BOOT_PARTITION=.*#BOOT_PARTITION=$BOOT_PARTITION#" /etc/grml2hd/config || export GRML2HD_FAIL=1
2648 fi
2649
2650 cat>|/usr/bin/grml2hd_noninteractive<<EOF
2651 #!/bin/sh
2652 GRML2HD_NONINTERACTIVE='yes' grml2hd
2653 EOF
2654
2655 chmod 755 /usr/bin/grml2hd_noninteractive
2656 einfo "Bootoption grml2hd found. Running automatic installation via grml2hd using /etc/grml2hd/config." && eend 0
2657 if [ -z "$GRML2HD_FAIL" ] ; then
2658    screen /usr/bin/grml2hd_noninteractive ; einfo "Invoking a shell, just exit to continue booting..." ; /bin/zsh
2659 else
2660    ewarn "There was an error adjusting /etc/grml2hd/config. Skipping execution of grml2hd for security reasons." ; eend 1
2661 fi
2662
2663 fi # if checkbootparam "BOOT_IMAGE=grml2hd ...
2664 }
2665 # }}}
2666
2667 # {{{ debootstrap: automatic installation
2668 config_debootstrap(){
2669
2670 if checkbootparam "BOOT_IMAGE=debian2hd" ; then
2671
2672 einfo "Bootoption debian2hd found. Setting up environment for automatic installation via grml-debootstrap." ; eend 0
2673
2674 if ! [ -x /usr/sbin/grml-debootstrap ] ; then
2675    eindent
2676    eerror "Bootoption debian2hd found, but grml-debootstrap is not available." ; eend 1
2677    eoutdent
2678    exit 1
2679 fi
2680
2681 if checkbootparam 'target' ; then
2682   TARGET=''
2683   TARGET="$(getbootparam 'target' 2>>$DEBUG)"
2684   # notice: the following checks whether the given partition is available, if not the skip
2685   # execution of grml-debootstrap as it might result in data loss...
2686   if ! [ -r "$TARGET" ] ; then
2687      eerror "Target $TARGET does not exist. Skipping execution of grml-debootstrap therefore." ; eend 1
2688   fi
2689 else
2690   eindent
2691   eerror "No bootoption named target found, can not continue execution of grml-debootstrap." ; eend 1
2692   eoutdent
2693   exit 1
2694 fi
2695
2696 if checkbootparam 'grub' ; then
2697   GRUB=''
2698   GRUB="$(getbootparam 'grub' 2>>$DEBUG)"
2699 fi
2700
2701 if checkbootparam 'groot' ; then
2702   GROOT=''
2703   GROOT="$(getbootparam 'groot' 2>>$DEBUG)"
2704 fi
2705
2706 if checkbootparam 'release' ; then
2707   RELEASE=''
2708   RELEASE="$(getbootparam 'release' 2>>$DEBUG)"
2709 fi
2710
2711 if checkbootparam 'mirror' ; then
2712   MIRROR=''
2713   MIRROR="$(getbootparam 'mirror' 2>>$DEBUG)"
2714 fi
2715
2716 if checkbootparam 'boot_append' ; then
2717   BOOT_APPEND=''
2718   BOOT_APPEND="$(getbootparam 'boot_append' 2>>$DEBUG)"
2719 fi
2720
2721 if checkbootparam 'password' ; then
2722   PASSWORD=''
2723   PASSWORD="$(getbootparam 'password' 2>>$DEBUG)"
2724 fi
2725
2726 # now check which options are available
2727 if [ -n "TARGET" ] ; then
2728    TARGETCMD="--target $TARGET"
2729 else
2730    TARGETCMD=''
2731    eindent
2732    eerror "Target not set via bootoption. Skipping execution of grml-debootstrap therefore."; eend 1
2733    eoutdent
2734    exit 1
2735 fi
2736 [ -n "$GRUB" ]     && GRUBCMD="--grub $GRUB"               || GRUBCMD=''
2737 [ -n "$GROOT" ]    && GROOTCMD="--groot $GROOT"            || GROOTCMD=''
2738 [ -n "$RELEASE" ]  && RELEASECMD="--release $RELEASE"      || RELEASECMD=''
2739 [ -n "$MIRROR" ]   && MIRRORCMD="--mirror $MIRROR"         || MIRRORCMD=''
2740 [ -n "$PASSWORD" ] && PASSWORDCMD="--password $PASSWORD"   || PASSWORDCMD=''
2741 [ -n "$BOOT_APPEND" ] && BOOT_APPEND="--boot_append $BOOT_APPEND" || BOOT_APPEND=''
2742
2743 # and finally write script and execute it
2744 cat>|/usr/bin/grml-debootstrap_noninteractive<<EOF
2745 #!/bin/sh
2746 AUTOINSTALL='yes' grml-debootstrap $TARGETCMD $GRUBCMD $GROOTCMD $RELEASECMD $MIRRORCMD $PASSWORDCMD $BOOT_APPEND
2747 EOF
2748
2749 chmod 750  /usr/bin/grml-debootstrap_noninteractive
2750
2751 screen /usr/bin/grml-debootstrap_noninteractive
2752 einfo "Invoking a shell, just exit to continue booting..."
2753 /bin/zsh
2754
2755 fi # checkbootparam "BOOT_IMAGE=debian2hd
2756 }
2757 # }}}
2758
2759 # {{{ Support customization
2760 config_distri(){
2761 if checkbootparam 'distri'; then
2762   DISTRI="$(getbootparam 'distri' 2>>$DEBUG)"
2763   if [ -r "${LIVECD_PATH}"/desktop/"$DISTRI".jpg ] ; then
2764      [ -n "$BOOTDEBUG" ] && einfo "Debug: bootoption distri found and file ${LIVECD_PATH}/desktop/${DISTRI} present" && eend 0
2765      # make sure the desktop.jpg file is not a symlink, so copying does not file then
2766      [ -L /usr/share/grml/desktop.jpg ] && rm /usr/share/grml/desktop.jpg
2767      cp "${LIVECD_PATH}"/desktop/"$DISTRI".jpg /usr/share/grml/desktop.jpg
2768   fi
2769 fi
2770 }
2771 # }}}
2772
2773 ### {{{ backwards compatible stuff
2774 config_environment(){
2775   ewarn "config_environment is deprecated. Please set CONFIG_ENVIRONMENT in /etc/grml/autoconfig to 'no'." ; eend 0
2776 }
2777 config_keyboard(){
2778   ewarn "config_keyboard is deprecated. Please set CONFIG_KEYBOARD in /etc/grml/autoconfig to 'no'." ; eend 0
2779 }
2780 # }}}
2781
2782 ## END OF FILE #################################################################
2783 # vim:foldmethod=marker expandtab ai ft=zsh shiftwidth=3