111e8e80409863885ae27be8535d54b4fe1f10ef
[grml-debootstrap.git] / grml-debootstrap
1 #!/bin/bash
2 # Filename:      grml-debootstrap
3 # Purpose:       wrapper around debootstrap for installing plain Debian via Grml
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 # http://www.debian.org/releases/stable/i386/index.html.en
9
10 set -e # exit on any error
11
12 # variables {{{
13 PN="$(basename $0)"
14 VERSION="$(dpkg --list $PN 2>/dev/null| awk '/^i/ {print $3}')"
15 VERSION="${VERSION:-unknown}"
16 MNTPOINT="/mnt/debootstrap.$$"
17
18 # defaults
19 VMSIZE="2G"
20
21 # inside the chroot system locales might not be available, so use minimum:
22 export LANG=C
23 export LC_ALL=C
24
25 # make sure interactive mode is only executed when
26 # using an empty configuration file or option --interactive
27 INTERACTIVE=''
28 # }}}
29
30 # source core functions {{{
31 . /etc/grml/lsb-functions
32 . /etc/grml/script-functions
33 # }}}
34
35 # help text {{{
36 usage() {
37   echo "$PN - wrapper around debootstrap for installing Debian
38
39 Usage: $PN [options]
40
41 Bootstrap options:
42
43   -m, --mirror <URL>     Mirror which should be used for apt-get/aptitude.
44   -i, --iso <mnt>        Mountpoint where a Debian ISO is mounted to, for use
45                          instead of fetching packages from a mirror.
46   -r, --release <name>   Release of new Debian system (default: squeeze).
47   -t, --target <target>  Target partition (/dev/...) or directory where the
48                          system should be installed to.
49   -p, --mntpoint <mnt>   Mountpoint used for mounting the target system,
50                          has no effect if -t is given and represents a directory.
51       --debopt <params>  Extra parameters passed to the debootstrap command.
52       --interactive      Use interactive mode (frontend).
53       --nodebootstrap    Skip debootstrap, only do configuration to the target.
54       --grub <device>    Target for grub installation. Usage example: /dev/sda
55       --arch <arch>      Architecture to use. Currently only i386 is supported.
56       --filesystem <fs>  Filesystem that should be used when target is a partition
57                          or Virtual Machine (see --vmfile).
58       --insecure         Do not download and check Release file signatures.
59
60 Options for Virtual Machine deployment:
61
62       --vmfile           Set up a Virtual Machine instead of installing to
63                          a partition or directory, to be combined with --target,
64                          like: --vmfile --target /mnt/sda1/qemu.img
65       --vmsize <size>    Use specified size for size of VM file (default: 2G).
66                          Syntax as supported by qemu-img, like: --vmsize 3G
67
68 Configuration options:
69
70   -c, --config <file>      Use specified configuration file, defaults to
71                              /etc/debootstrap/config
72   -d, --confdir <path>     Place of config files for debootstrap, defaults
73                              to /etc/debootstrap
74       --packages <file>    Install packages defined in specified list file.
75       --nopackages         Skip installation of packages defined in
76                              /etc/debootstrap/packages
77       --debconf <file>     Pre-seed packages using specified pre-seed db file.
78       --keep_src_list      Do not overwrite user provided apt sources.list.
79       --hostname <name>    Hostname of Debian system.
80       --password <pwd>     Use specified password as password for user root.
81       --bootappend <line>  Add specified appendline to kernel whilst booting.
82       --chroot-scripts <d> Execute chroot scripts from specified directory.
83       --pre-scripts <dir>  Execute scripts from specified directory (before chroot-scripts).
84       --scripts <dir>      Execute scripts from specified directory (after chroot-scripts).
85
86 Other options:
87
88   -v, --verbose            Increase verbosity.
89   -h, --help               Print this usage information and exit.
90   -V, --version            Show summary of options and exit.
91
92 Usage examples can be found in the grml-debootstrap manpage.
93 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
94 "
95 }
96
97 if [ "$1" = '-h' ] || [ "$1" = '-help' ] || [ "$1" = "--help" ] ; then
98    usage
99    echo 'Please notice that this script requires root permissions!'
100    exit 0
101 fi
102 # }}}
103
104 # make sure we have what we need {{{
105 check4progs debootstrap dialog || exit 1
106 # }}}
107
108 # source main configuration file {{{
109 if [ -r /etc/debootstrap/config ] ; then
110   . /etc/debootstrap/config
111 fi
112 # }}}
113
114 # cmdline handling {{{
115 # source external command line parameter-processing script
116 if [ -r ./cmdlineopts.clp ] ; then
117    . ./cmdlineopts.clp
118 elif [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
119    . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
120 else
121    echo "Error: cmdline function file not found, exiting.">&2
122    exit 1
123 fi
124
125 # == business-logic of command line parameter-processing
126
127 # source configuration file in <confdir> if supplied. {{{
128 [ "$_opt_confdir" ] && {
129   CONFFILES=$_opt_confdir
130   einfo "Using config files under $CONFFILES/."
131   if ! [ -r "$CONFFILES/config" ] ; then
132     eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
133   fi
134   if ! . "$CONFFILES/config" ; then
135     eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
136   fi
137   # restore the command line parameter value
138   CONFFILES=$_opt_confdir
139 }
140 # }}}
141
142 [ "$_opt_mirror" ]              && MIRROR=$_opt_mirror
143 [ "$_opt_iso" ]                 && ISO=$_opt_iso
144 [ "$_opt_release" ]             && RELEASE=$_opt_release
145 [ "$_opt_target" ]              && TARGET=$_opt_target
146 [ "$_opt_vmfile" ]              && VIRTUAL=1
147 [ "$_opt_vmsize" ]              && VMSIZE=$_opt_vmsize
148 [ "$_opt_mntpoint" ]            && MNTPOINT=$_opt_mntpoint
149 [ "$_opt_debopt" ]              && DEBOOTSTRAP_OPT=$_opt_debopt
150 [ "$_opt_interactive" ]         && INTERACTIVE=1
151 [ "$_opt_config" ]              && CONFIGFILE=$_opt_config
152 [ "$_opt_filesystem" ]          && MKFS="mkfs.$_opt_filesystem"
153 [ "$_opt_packages_set" ]        && PACKAGES='yes'
154 [ "$_opt_nopackages" ]          && PACKAGES=''
155 [ "$_opt_debconf_set" ]         && DEBCONF='yes'
156 [ "$_opt_scripts_set" ]         && SCRIPTS='yes'
157 [ "$_opt_pre_scripts_set" ]     && PRE_SCRIPTS='yes'
158 [ "$_opt_chroot_scripts_set" ]  && CHROOT_SCRIPTS='yes'
159 [ "$_opt_keep_src_list" ]       && KEEP_SRC_LIST='yes'
160 [ "$_opt_hostname" ]            && HOSTNAME=$_opt_hostname
161 [ "$_opt_password" ]            && ROOTPASSWORD=$_opt_password
162 [ "$_opt_bootappend" ]          && BOOT_APPEND=$_opt_bootappend
163 [ "$_opt_grub" ]                && GRUB=$_opt_grub
164 [ "$_opt_arch" ]                && ARCH=$_opt_arch
165 [ "$_opt_insecure" ]            && SECURE='false'
166 [ "$_opt_verbose" ]             && VERBOSE="-v"
167
168 [ "$_opt_help" ] && {
169   usage ; eend 0
170   eend 0
171   exit 0
172 }
173
174 [ "$_opt_version" ] && {
175   einfo "$PN - version $VERSION"
176   einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
177   eend 0
178   exit 0
179 }
180 # }}}
181
182 # check for root permissions {{{
183 if ! check4root ; then
184    echo "For usage instructions please execute '$PN --help'."
185    exit 1
186 fi
187 # }}}
188
189 # make sure we have what we need {{{
190 if [ -n "$VIRTUAL" ] ; then
191   check4progs kpartx mksh qemu-img || exit 1
192 fi
193 # }}}
194
195 # source specified configuration file {{{
196 if [ -n "$CONFIGFILE" ] ; then
197    einfo "Reading specified config file $CONFIGFILE."
198    if ! . "$CONFIGFILE" ; then
199       eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
200    fi
201 fi
202 # }}}
203
204 # backwards compability checks {{{
205 if [ -n "$GROOT" ] ; then
206    echo "Error: you seem to have \$GROOT configured." >&2
207    echo "This variable is no longer supported, please visit the" >&2
208    echo "grml-debootstrap documentation for details." >&2
209    exit 1
210 fi
211
212 if echo "$GRUB" | grep -q '^hd' ; then
213    echo "Error: this syntax for the grub configuration variable is no longer supported." >&2
214    echo "Please do not use hd... any longer but /dev/sdX instead." >&2
215    exit 1
216 fi
217 # }}}
218
219 # welcome screen {{{
220 welcome_dialog()
221 {
222    dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
223 Do you want to continue installing Debian using this frontend?" 0 0
224 }
225 # }}}
226
227 # ask for target {{{
228 prompt_for_target()
229 {
230   AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
231                sed 's/*//' | \
232                grep -v 'Extended$' | \
233                gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}'; ls /dev/md* 2>/dev/null || true);
234
235   if [ -z "$AVAILABLE_PARTITIONS" ] ; then
236      dialog --title "$PN" --trim \
237      --msgbox "Sorry, no partitions found. Please configure your
238      harddisks (see /proc/partitions) using a tool like fdisk,
239      cfdisk, gpart, gparted,..." 0 0
240      exit 0
241   fi
242
243   PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
244                        echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet])"
245                    done)
246
247   TARGET=$(dialog --title "$PN" --single-quoted --stdout \
248          --menu "Please select the target partition:" 0 0 0 \
249          $PARTITION_LIST)
250 }
251 # }}}
252
253 # ask for bootmanager {{{
254 prompt_for_bootmanager()
255 {
256   ADDITIONAL_PARAMS=""
257
258   if echo "$TARGET" | grep -q "/dev/md" ; then
259      MBRPART="all disks of Software RAID $TARGET"
260   else
261      # figure out whole disk device
262      found=
263      for device in /dev/disk/by-id/*
264      do
265         [ $(readlink -f $device) = ${TARGET} ] || continue
266         found=1
267         break
268      done
269      [ -n "$found" ] && MBRDISK=$(echo ${device}|sed -e 's/-part[0-9][0-9]*$//')
270      if [ -e "$MBRDISK" ]; then
271         MBRDISK=$(readlink -f $MBRDISK)
272      else
273         # fall back to old behaviour
274         MBRDISK=$(echo ${TARGET} | sed -e 's/[0-9][0-9]*$//')
275      fi
276
277      MBRPART="MBR of $MBRDISK"
278   fi
279
280   for device in cciss/c0d0 sda hda; do
281     if [ /dev/$device != ${MBRDISK} ]; then
282       grep -q $device /proc/partitions && \
283       ADDITIONAL_PARAMS="$ADDITIONAL_PARAMS:$device:install bootmanager grub into MBR of /dev/$device"
284     fi
285   done
286   ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
287
288   OIFS="$IFS"; IFS=:
289
290   GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
291           --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
292             mbr       "install bootmanager into $MBRPART" \
293             nowhere   "do not install bootmanager at all" \
294           ${ADDITIONAL_PARAMS})
295   [ $? -eq 0 ] || bailout 3
296   IFS="$OIFS"
297
298   case "$GETMBR" in
299     mbr)
300       # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
301       if echo "$TARGET" | grep -q "/dev/md" ; then
302          # using sw-raid:
303          if [ -n "$SELECTED_PARTITIONS" ] ; then
304             GRUB=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
305          else
306             GRUB="$TARGET"
307          fi
308       else
309         GRUB="$MBRDISK"
310       fi
311       ;;
312     hda)
313       GRUB="/dev/hda"
314       ;;
315     sda)
316       GRUB="/dev/sda"
317       ;;
318     nowhere)
319       GRUB=''
320       ;;
321   esac
322 }
323 # }}}
324
325 # ask for Debian release {{{
326 prompt_for_release()
327 {
328   [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='squeeze'
329   RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
330             "Please enter the Debian release you would like to use for installation:" \
331             0 50 4 \
332             lenny    Debian/old-stable \
333             squeeze  Debian/stable \
334             wheezy   Debian/testing \
335             sid      Debian/unstable)"
336 }
337 # }}}
338
339 # ask for hostname {{{
340 prompt_for_hostname()
341 {
342   HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
343             "Please enter the hostname you would like to use for installation:" \
344             0 0 $HOSTNAME)"
345 }
346 # }}}
347
348 # ask for password {{{
349 prompt_for_password()
350 {
351      ROOTPW1='PW1'
352      ROOTPW2='PW2'
353      while [ "$ROOTPW1" != "$ROOTPW2" ]; do
354        ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
355        "Please enter the password for the root account:" 10 60)
356        ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
357        "Please enter the password for the root account again for \
358        confirmation:" 10 60)
359
360        if [ "$ROOTPW1" != "$ROOTPW2" ]; then
361          $(dialog --stdout --title "${PN}" --ok-label \
362          "Retry" --msgbox "Passwords do not match!" 10 60)
363        fi
364      done
365      ROOTPASSWORD="$ROOTPW1"
366 }
367 # }}}
368
369 # ask for Debian mirror {{{
370 prompt_for_mirror()
371 {
372   [ -n "$ISO" ] && DEFAULT_MIRROR='local' || DEFAULT_MIRROR='net'
373
374   CHOOSE_MIRROR=$(dialog --stdout --title "$PN" --default-item $DEFAULT_MIRROR \
375           --menu "Where do you want to install from?" 0 0 0 \
376             net   "install via network (downloading from mirror)" \
377             local "install from local directory/mirror"
378           )
379
380   if [ "$CHOOSE_MIRROR" = 'net' ] ; then
381      [ -n "$MIRROR" ] || MIRROR='http://cdn.debian.net/debian'
382      MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
383                "Please enter Debian mirror you would like to use for installing packages." \
384                0 0 $MIRROR)"
385   else # CHOOSE_MIRROR == local
386      [ -n "$ISO" ] || ISO='/mnt/mirror'
387      ISO="$(dialog --stdout --title "${PN}" --inputbox \
388                "Please enter directory name you would like to use for installing packages." \
389                0 0 $ISO)"
390   fi
391 }
392 # }}}
393
394 # software raid setup {{{
395 config_swraid_setup()
396 {
397 TMPFILE=$(mktemp)
398
399 # Currently we support only raid1:
400 RAIDLEVEL='raid1'
401
402 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
403 #                   --menu "Which RAID level do you want to use?" 0 0 0 \
404 #                     raid1 "Software RAID level 1" \
405 #                     raid5 "Software RAID level 5")
406 #[ $? -eq 0 ] || bailout 20
407
408 MD_LIST=$(for i in $(seq 0 9) ; do
409             awk '{print $4}' /proc/partitions | grep -q md$i || \
410             echo "/dev/md$i /dev/md$i"
411           done)
412
413 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
414 --menu "Which device do you want to use for ${RAIDLEVEL}?
415
416 Notice: activated devices will not be listed for security reasons. Anyway, please make sure the selected device is not in use already!" 0 0 0 \
417 $MD_LIST)
418 [ $? -eq 0 ] || bailout 20
419
420 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
421              sed 's/*//' | \
422              grep -v 'Extended$' | \
423              gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
424 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
425 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
426                      echo "$i $(blkid -s TYPE -o value $i 2>/dev/null || echo [no_filesystem_yet]) off"
427                  done)
428
429 dialog --title "$PN" --separate-output \
430        --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
431        $PARTITION_LIST 2>$TMPFILE
432 RETVAL=$?
433 SELECTED_PARTITIONS="$(cat $TMPFILE)"
434
435 NUM_PARTITIONS=0
436 for i in $(cat $TMPFILE) ; do
437    NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
438 done
439
440 # force metadata version 0.90 for lenny so old grub can boot from this array.
441 METADATA_VERSION=""
442 if [ $RELEASE = "lenny" ]; then
443    METADATA_VERSION="-e0"
444 fi
445
446 ERRORFILE=$(mktemp)
447 set +e
448 # TODO: better error handling?
449 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
450       --raid-devices="${NUM_PARTITIONS}" ${METADATA_VERSION} ${SELECTED_PARTITIONS} >/dev/null 2>$ERRORFILE
451 RC=$?
452 set -e
453
454 if [ "$RC" = 0 ] ; then
455    dialog --title "$PN" --msgbox \
456    "Creating $TARGET was successful." 0 0
457    rm -f "$TMPFILE" "$ERRORFILE"
458 else
459    dialog --title "$PN" --msgbox \
460    "There was an error setting up $TARGET:
461
462 $(cat $ERRORFILE)
463
464 Exiting." 0 0
465    rm -f "$TMPFILE" "$ERRORFILE"
466    exit 1
467 fi
468
469 }
470
471 prompt_for_swraid()
472 {
473 if dialog --stdout --title "$PN" \
474           --defaultno --yesno "Do you want to configure Software RAID?
475
476 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
477   config_swraid_setup
478 fi
479 }
480 # }}}
481
482 # user should recheck his configuration {{{
483 # support full automatic installation:
484 checkforrun() {
485    dialog --timeout 10 --title "$PN" \
486           --yesno "Do you want to stop at this stage?
487
488 Notice: you are running ${PN} in non-interactive mode.
489 ${PN} will install Debian ${RELEASE} on ${TARGET}.
490 Last chance to quit. Timeout of 10 seconds running....
491
492 Do you want to stop now?" 0 0 2>/dev/null
493 }
494
495 # make sure the user is aware of the used configuration {{{
496 checkconfiguration()
497 {
498 if [ -n "$AUTOINSTALL" ] ; then
499    if checkforrun ; then
500       eerror "Exiting as requested" ; eend 0
501       exit 1
502    fi
503 elif [ -n "$INTERACTIVE" ] ; then
504
505    INFOTEXT="Please recheck configuration before execution:
506    "
507    [ -n "$TARGET" ]  && INFOTEXT="$INFOTEXT
508    Target:          $TARGET"
509    [ -n "$GRUB" ]    && INFOTEXT="$INFOTEXT
510    Install grub:    $GRUB"
511    [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
512    Using release:   $RELEASE"
513    [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
514    Using hostname   $HOSTNAME"
515    [ -n "$MIRROR" ]  && INFOTEXT="$INFOTEXT
516    Using mirror:    $MIRROR"
517    [ -n "$ISO" ]  && INFOTEXT="$INFOTEXT
518    Using ISO:       $ISO"
519
520    INFOTEXT="$INFOTEXT
521
522 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
523
524    dialog --title "$PN" --no-collapse \
525           --yesno "$INFOTEXT" 0 0
526
527 else # if not running automatic installation display configuration and prompt for execution:
528    einfo "$PN - Please recheck configuration before execution:"
529    echo
530    echo "   Target:          $TARGET"
531
532    # do not display if MNTPOINT is the default one
533    case "$MNTPOINT" in /mnt/debootstrap*) ;; *) echo "   Mount point:     $MNTPOINT" ;; esac
534
535    if [ -n "$VIRTUAL" ] ; then
536       echo "   Install grub:    yes"
537    else
538      [ -n "$GRUB" ]     && echo "   Install grub:    $GRUB" || echo "   Install grub:    no"
539    fi
540
541    [ -n "$RELEASE" ]  && echo "   Using release:   $RELEASE"
542    [ -n "$MIRROR" ]   && echo "   Using mirror:    $MIRROR"
543    [ -n "$HOSTNAME" ] && echo "   Using hostname:  $HOSTNAME"
544    [ -n "$ISO" ]      && echo "   Using ISO:       $ISO"
545    if [ -n "$VIRTUAL" ] ; then
546       echo "   Deploying as Virtual Machine."
547       [ -n "$VMSIZE" ] && echo "   Using Virtual Disk file with size of ${VMSIZE}."
548    fi
549
550    echo
551    echo "   Important! Continuing will delete all data from ${TARGET}!"
552
553    echo
554    einfon "Is this ok for you? [y/N] "
555    read a
556    if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
557       eerror "Exiting as requested." ; eend 1
558       exit 1
559    fi
560 fi
561 }
562 # }}}
563
564 # interactive mode {{{
565 interactive_mode()
566 {
567   welcome_dialog
568
569   prompt_for_release
570
571   prompt_for_swraid
572
573   prompt_for_target
574
575   prompt_for_bootmanager
576
577   prompt_for_hostname
578
579   prompt_for_password
580
581   prompt_for_mirror
582 }
583
584 # run interactive mode if we didn't get the according configuration yet
585 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
586    # only target might be unset, so make sure the INTERACTIVE flag is set as well
587    INTERACTIVE=1
588    interactive_mode
589 fi
590 # }}}
591
592 checkconfiguration
593
594 # finally make sure at least $TARGET is set [the partition for the new system] {{{
595 if [ -n "$TARGET" ] ; then
596    SHORT_TARGET="${TARGET##*/}"
597 else
598    eerror "Please adjust $CONFFILES/config or..."
599    eerror "... use the interactive version for configuration before running ${0}" ; eend 1
600    exit 1
601 fi
602 # }}}
603
604 # stages setup {{{
605 if [ -z "$STAGES" ] ; then
606    STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
607    [ -d "$STAGES" ] || mkdir -p "$STAGES"
608 fi
609
610 if [ -r "$STAGES"/grml-debootstrap ] ; then
611    if grep -q done $STAGES/grml-debootstrap ; then
612       eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
613       eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
614    fi
615 fi
616 # }}}
617
618 # partition handling {{{
619 PARTITION=''
620 DIRECTORY=''
621
622 set_target_directory(){
623     # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
624     DIRECTORY=1
625     MNTPOINT="$TARGET"
626     MKFS=''
627     TUNE2FS=''
628     FSCK=''
629     GRUB=''
630     # make sure we normalise the path to an absolute directory name so something like:
631     #  mkdir -p foo/a bar/a; (cd foo; grml-debootstrap -t a)&; (cd bar; grml-debootstrap -t a)&; wait
632     # works
633     TARGET="$(readlink -f $TARGET)"
634 }
635
636 if [ -b "$TARGET" ] || [ -n "$VIRTUAL" ] ; then
637     PARTITION=1
638 else
639     set_target_directory
640 fi
641 # }}}
642
643 # architecture setup {{{
644 if [ -n "$ARCH" ] ; then
645    ARCHCMD="--arch $ARCH"
646    ARCHINFO=" (${ARCH})"
647 else
648    ARCH="$(dpkg --print-architecture)"
649    ARCHCMD="--arch $ARCH"
650    ARCHINFO=" (${ARCH})"
651 fi
652 # }}}
653
654 # keyring setupt {{{
655 KEYRING=""
656 if [ "$SECURE" = 'yes' ] ; then
657    if [ -e '/etc/apt/trusted.gpg' ] ; then
658       KEYRING="--keyring /etc/apt/trusted.gpg"
659    else
660       eerror "Could not find /etc/apt/trusted.gpg."
661    fi
662 else
663    ewarn "Not checking Release signatures!"
664 fi
665 # }}}
666
667 # make sure we have the right syntax when using an iso image {{{
668 if [ -n "$ISO" ] ; then
669    case $ISO in
670       file*) # do nothing
671       ;;
672       *)
673       ISO=file:$1
674       ;;
675    esac
676 fi
677 ISODIR=${ISO##file:}
678 ISODIR=${ISODIR%%/}
679 # }}}
680
681 # helper functions {{{
682 # we want to exit smoothly and clean:
683 bailout(){
684   # make sure $TARGET is not mounted when exiting grml-debootstrap
685   if [ -n "$MNTPOINT" ] ; then
686      if grep -q $MNTPOINT /proc/mounts ; then
687         # make sure nothing is left inside chroot so we can unmount it
688         [ -x "$MNTPOINT"/etc/init.d/ssh   ] && "$MNTPOINT"/etc/init.d/ssh stop
689         [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
690         # ugly, but make sure we really don't leave anything (/proc /proc is intended)
691         for ARG in /sys /proc /proc ; do
692           [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount $ARG >/dev/null 2>&1 || true
693         done
694         umount "$MNTPOINT"/dev >/dev/null 2>&1 || true
695
696         [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" >/dev/null 2>&1 || true
697
698         if [ -n "$DIRECTORY" ] ; then
699           einfo "Not unmounting $MNTPOINT as you requested me to install into a directory of your own choice." ; eend 0
700         else
701           einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
702         fi
703
704         if [ -n "$STAGES" ] ; then
705            echo -n "Removing stages directory ${STAGES}: "
706            rm -rf "$STAGES" && echo done
707         fi
708
709         # remove directory only if we used the default with process id inside the name
710         if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
711            einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
712         fi
713      fi
714   fi
715
716   if [ -n "${ORIG_TARGET}" ] ; then
717     einfo "Removing loopback mount of file ${ORIG_TARGET}."
718     kpartx -d "${ORIG_TARGET}" ; eend $?
719   fi
720
721   [ -n "$1" ] && EXIT="$1" || EXIT="1"
722   [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
723
724   exit "$EXIT"
725 }
726 trap bailout HUP INT QUIT TERM
727
728 # we want to execute all the functions only once, simple check for it:
729 stage() {
730   if [ -n "$2" ] ; then
731      echo "$2" > "${STAGES}/${1}"
732      return 0
733   elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
734      ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
735      eindent
736        ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
737      eoutdent
738      return 1
739   fi
740 }
741 # }}}
742
743 # create filesystem {{{
744 mkfs() {
745   if [ -n "$DIRECTORY" ] ; then
746      einfo "Running grml-debootstrap on a directory, skipping mkfs stage."
747   else
748     if grep -q "$TARGET" /proc/mounts ; then
749       eerror "$TARGET already mounted, exiting to avoid possible damage. (Manually unmount $TARGET)" ; eend 1
750       exit 1
751     fi
752
753     if [ -n "$MKFS" ] ; then
754        einfo "Running $MKFS on $TARGET"
755        $MKFS $TARGET ; RC=$?
756
757        # make sure /dev/disk/by-uuid/... is up2date, otherwise grub
758        # will fail to detect the uuid in the chroot
759        if echo "$TARGET" | grep -q "/dev/md" ; then
760          blockdev --rereadpt "${TARGET}"
761        elif ! [ -n "$VIRTUAL" ] ; then
762          blockdev --rereadpt "${TARGET%%[0-9]*}"
763        fi
764        # give the system 2 seconds, otherwise we might run into
765        # race conditions :-/
766        sleep 2
767
768        eval $(blkid -o udev $TARGET 2>/dev/null)
769        [ -n "$ID_FS_UUID" ] && TARGET_UUID="$ID_FS_UUID" || TARGET_UUID=""
770
771        eend $RC
772     fi
773
774   fi
775 }
776 # }}}
777
778 # modify filesystem settings {{{
779 tunefs() {
780   if [ -n "$TUNE2FS" ] && echo "$MKFS" | grep -q "mkfs.ext" ; then
781      einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
782      $TUNE2FS $TARGET
783      eend $?
784   fi
785 }
786 # }}}
787
788 # mount the new partition or if it's a directory do nothing at all {{{
789 mount_target() {
790   if [ -n "$DIRECTORY" ] ; then
791      einfo "Running grml-debootstrap on a directory, nothing to mount."
792   else
793      if grep -q $TARGET /proc/mounts ; then
794         ewarn "$TARGET already mounted, continuing anyway." ; eend 0
795      else
796        if ! [ -d "${MNTPOINT}" ] ; then
797           [ -n "$VIRTUAL" ] || mkdir -p "${MNTPOINT}"
798        fi
799        einfo "Mounting $TARGET to $MNTPOINT"
800        mkdir -p "$MNTPOINT"
801        mount -o rw,suid,dev $TARGET $MNTPOINT
802        eend $?
803      fi
804   fi
805   if [ -n "$ISODIR" ] ; then
806      einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
807      mkdir -p "$MNTPOINT/$ISODIR"
808      mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
809      eend $?
810   fi
811 }
812 # }}}
813
814 # prepare VM image for usage with debootstrap {{{
815 prepare_vm() {
816   if [ -z "$VIRTUAL" ] ; then
817      return 0 # be quite by intention
818   fi
819
820   if [ -b "$TARGET" ] ; then
821      eerror "Error: specified virtual disk target ($TARGET) is an existing block device."
822      eend 1
823      exit 1
824   fi
825
826   ORIG_TARGET="$TARGET" # store for later reuse
827
828   qemu-img create -f raw "${TARGET}" "${VMSIZE}"
829   echo 4 66 | mksh /usr/share/grml-debootstrap/bootgrub.mksh -A | dd of="$TARGET" conv=notrunc
830   dd if=/dev/zero bs=1 conv=notrunc count=64 seek=446 of="$TARGET"
831   parted -s "${TARGET}" 'mkpart primary ext3 2M -1'
832
833   DEVINFO=$(kpartx -av $TARGET) # 'add map loop1p1 (253:0): 0 6289408 linear /dev/loop1 2048'
834   if [ -z "${DEVINFO}" ] ; then
835     echo  Error setting up loopback device >&2
836     exit 1
837   fi
838
839   # hopefully this always works as expected
840   LOOP=$(echo ${DEVINFO} | sed 's/.* linear //; s/ [[:digit:]]*//') # '/dev/loop1'
841   BLOCKDEV=$(echo "${DEVINFO}" | sed -e 's/.* (\(.*:.*\)).*/\1/')   # '253:0'
842   LOOP_PART="$(echo ${DEVINFO##add map } | sed 's/ .*//')" # '/dev/loop1p1'
843   export TARGET="/dev/mapper/$LOOP_PART" # '/dev/mapper/loop1p1'
844
845   blockdev --rereadpt "${LOOP}"
846
847   if [ -z "$TARGET" ] ; then
848      echo "Error: target could not be set to according /dev/mapper/* device." >&2
849      exit 1
850   fi
851 }
852 # }}}
853
854 # make VM image bootable and unmount it {{{
855 finalize_vm() {
856   if [ -z "${VIRTUAL}" ] ; then
857      return 0
858   fi
859
860   if ! mount "${TARGET}" "${MNTPOINT}" ; then
861     eerror "Error: Mounting ${TARGET} failed, can not continue." ; eend 1
862     exit 1
863   fi
864
865   einfo "Installing Grub as bootloader."
866   mount -t proc none "${MNTPOINT}"/proc
867   mount -t sysfs none "${MNTPOINT}"/sys
868   mount --bind /dev "${MNTPOINT}"/dev
869
870   mkdir -p "${MNTPOINT}/boot/grub"
871   if ! [ -d "${MNTPOINT}"/usr/lib/grub/i386-pc/ ] ; then
872      eerror "Error: grub not installed inside Virtual Machine. Can not install bootloader." ; eend 1
873      exit 1
874   fi
875
876   cp "${MNTPOINT}"/usr/lib/grub/i386-pc/* "${MNTPOINT}/boot/grub/"
877   chroot "${MNTPOINT}" grub-mkimage -O i386-pc -p "(hd0,msdos1)/boot/grub" -o /tmp/core.img biosdisk part_msdos ext2
878   dd if="${MNTPOINT}/tmp/core.img" of="${ORIG_TARGET}" conv=notrunc seek=4
879   rm -f "${MNTPOINT}/tmp/core.img"
880
881   einfo "Updating grub configuration file."
882   chroot "${MNTPOINT}" update-grub
883
884   umount "${MNTPOINT}"/proc
885   umount "${MNTPOINT}"/sys
886   umount "${MNTPOINT}"/dev
887
888   einfo "Adjusting grub.cfg for successful boot sequence."
889   # ugly but needed to boot grub acordingly
890   sed -i "s;set root=.*;set root='(hd0,msdos1)';" "${MNTPOINT}"/boot/grub/grub.cfg
891   sed -i "s; root=/dev/.*; root=/dev/sda1;" "${MNTPOINT}"/boot/grub/grub.cfg
892
893   umount "${MNTPOINT}"
894   kpartx -d "${ORIG_TARGET}" >/dev/null
895 }
896 # }}}
897
898 # install main chroot {{{
899 debootstrap_system() {
900   if [ "$_opt_nodebootstrap" ]; then
901      einfo "Skipping debootstrap as requested."
902      return
903   fi
904
905   if grep -q "$MNTPOINT" /proc/mounts || [ -n "$DIRECTORY" ] ; then
906      einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
907      if [ -n "$MIRROR" ] ; then
908         einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR"
909         $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR
910      else
911         einfo "Executing: $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO"
912         $DEBOOTSTRAP $ARCHCMD $KEYRING $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
913      fi
914      eend $?
915   else
916      eerror "Error: $MNTPOINT not mounted, can not continue."
917      eend 1
918   fi
919 }
920 # }}}
921
922 # prepare chroot via chroot-script {{{
923 preparechroot() {
924   einfo "Preparing chroot system"
925
926   # provide variables to chroot system
927   CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
928   touch $CHROOT_VARIABLES
929   chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
930   echo "# Configuration of ${PN}"                              > $CHROOT_VARIABLES
931   [ -n "$ARCH" ]          && echo "ARCH=$ARCH"                 >> $CHROOT_VARIABLES
932   [ -n "$GRUB" ]          && echo "GRUB=$GRUB"                 >> $CHROOT_VARIABLES
933   [ -n "$HOSTNAME" ]      && echo "HOSTNAME=$HOSTNAME"         >> $CHROOT_VARIABLES
934   [ -n "$INSTALL_NOTES" ] && echo "INSTALL_NOTES=$INSTALL_NOTES" >> $CHROOT_VARIABLES
935   [ -n "$ISODIR" ]        && echo "ISODIR=$ISO"                >> $CHROOT_VARIABLES
936   [ -n "$ISO" ]           && echo "ISO=$ISO"                   >> $CHROOT_VARIABLES
937   [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
938   [ -n "$MIRROR" ]        && echo "MIRROR=$MIRROR"             >> $CHROOT_VARIABLES
939   [ -n "$PACKAGES" ]      && echo "PACKAGES=$PACKAGES"         >> $CHROOT_VARIABLES
940   [ -n "$RM_APTCACHE" ]   && echo "RM_APTCACHE=$RM_APTCACHE"   >> $CHROOT_VARIABLES
941   [ -n "$ROOTPASSWORD" ]  && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
942   [ -n "$SELECTED_PARTITIONS" ] && echo "SELECTED_PARTITIONS=$SELECTED_PARTITIONS" >> $CHROOT_VARIABLES
943   [ -n "$TARGET" ]        && echo "TARGET=$TARGET"             >> $CHROOT_VARIABLES
944   [ -n "$TARGET_UUID" ]   && echo "TARGET_UUID=$TARGET_UUID"   >> $CHROOT_VARIABLES
945
946   cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
947   chmod 755 $MNTPOINT/bin/chroot-script
948   [ -d "$MNTPOINT"/etc/debootstrap/ ] || mkdir "$MNTPOINT"/etc/debootstrap/
949
950   # make sure we have our files for later use via chroot-script
951   cp $VERBOSE $CONFFILES/config    $MNTPOINT/etc/debootstrap/
952   # make sure we adjust the configuration variables accordingly:
953   sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
954   sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#"    $MNTPOINT/etc/debootstrap/config
955   sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#"          $MNTPOINT/etc/debootstrap/config
956
957   # install notes:
958   if [ -n "$INSTALL_NOTES" ] ; then
959      [ -r "$INSTALL_NOTES" ] && cp "$INSTALL_NOTES" $MNTPOINT/etc/debootstrap/
960   fi
961
962   # package selection:
963   cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
964     $MNTPOINT/etc/debootstrap/packages
965
966   # debconf preseeding:
967   _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
968   [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
969     cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
970
971   # copy scripts that should be executed inside the chroot:
972   _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
973   [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
974     mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
975     cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
976   }
977
978   # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
979   cp $VERBOSE $CHROOT_VARIABLES  $MNTPOINT/etc/debootstrap/variables
980
981   cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
982
983   # make sure we can access network [relevant for cdebootstrap]
984   [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
985
986   # provide system's /etc/hosts to the target:
987   if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
988      cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
989   fi
990
991   # setup default locales
992   [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen  $MNTPOINT/etc/locale.gen
993
994   # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
995   ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
996
997   # copy any existing files to chroot
998   [ -d $CONFFILES/bin   ] && cp $VERBOSE -a -L $CONFFILES/bin/*   $MNTPOINT/bin/
999   [ -d $CONFFILES/boot  ] && cp $VERBOSE -a -L $CONFFILES/boot/*  $MNTPOINT/boot/
1000   [ -d $CONFFILES/etc   ] && cp $VERBOSE -a -L $CONFFILES/etc/*   $MNTPOINT/etc/
1001   [ -d $CONFFILES/sbin  ] && cp $VERBOSE -a -L $CONFFILES/sbin/*  $MNTPOINT/sbin/
1002   [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
1003   [ -d $CONFFILES/usr   ] && cp $VERBOSE -a -L $CONFFILES/usr/*   $MNTPOINT/usr/
1004   [ -d $CONFFILES/var   ] && cp $VERBOSE -a -L $CONFFILES/var/*   $MNTPOINT/var/
1005
1006   # copy local network setup to chroot
1007   if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
1008      [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
1009      cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
1010   fi
1011
1012   # install config file providing some example entries
1013   if [ -r /etc/network/interfaces.examples -a ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then
1014      cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples"
1015   fi
1016
1017   eend 0
1018 }
1019 # }}}
1020
1021 # execute all scripts in /etc/debootstrap/pre-scripts/ {{{
1022 execute_pre_scripts() {
1023    # make sure we have $MNTPOINT available for our scripts
1024    export MNTPOINT
1025    if [ -d "$_opt_pre_scripts" ] || [ "$PRE_SCRIPTS" = 'yes' ] ; then
1026       [ -d "$_opt_pre_scripts" ] && pre_scripts="$_opt_pre_scripts" || pre_scripts="$CONFFILES/pre-scripts/"
1027       for script in ${pre_scripts}/* ; do
1028          if [ -x "$script" ] ; then
1029             einfo "Executing pre-script $script"
1030             $script ; eend $?
1031          fi
1032       done
1033    fi
1034 }
1035 # }}}
1036
1037 # execute all scripts in /etc/debootstrap/scripts/ {{{
1038 execute_scripts() {
1039    # make sure we have $MNTPOINT available for our scripts
1040    export MNTPOINT
1041    if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
1042       [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
1043       for script in ${scripts}/* ; do
1044          if [ -x "$script" ] ; then
1045             einfo "Executing script $script"
1046             $script ; eend $?
1047          fi
1048       done
1049    fi
1050 }
1051 # }}}
1052
1053 # execute chroot-script {{{
1054 chrootscript() {
1055   if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
1056      mount_target
1057   fi
1058
1059   if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
1060      einfo "Executing chroot-script now"
1061      mount --bind /dev "$MNTPOINT"/dev
1062      chroot "$MNTPOINT" /bin/chroot-script ; RC=$?
1063      umount "$MNTPOINT"/dev
1064      eend $RC
1065   else
1066      eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
1067      eend 1
1068   fi
1069 }
1070 # }}}
1071
1072 # unmount $MNTPOINT {{{
1073 umount_chroot() {
1074
1075   # display installation notes:
1076   if [ -n "$INSTALL_NOTES" ] ; then
1077      [ -r "${MNTPOINT}/${INSTALL_NOTES}" ] && cat "${MNTPOINT}/${INSTALL_NOTES}"
1078   fi
1079
1080   if [ -n "$ISODIR" ] ; then
1081      if grep -q "$ISODIR" /proc/mounts ; then
1082         einfo "Unmount $MNTPOINT/$ISODIR"
1083         umount "$MNTPOINT/$ISODIR"
1084         eend $?
1085      fi
1086   fi
1087
1088   if grep -q "$MNTPOINT" /proc/mounts ; then
1089      if [ -n "$PARTITION" ] ; then
1090         einfo "Unmount $MNTPOINT"
1091         umount $MNTPOINT
1092         eend $?
1093      fi
1094   fi
1095 }
1096 # }}}
1097
1098 # execute filesystem check {{{
1099 fscktool() {
1100   if [ "$FSCK" = 'yes' ] ; then
1101      [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
1102      einfo "Checking filesystem on $TARGET using $FSCKTOOL"
1103      $FSCKTOOL $TARGET
1104      eend $?
1105   fi
1106 }
1107 # }}}
1108
1109 # now execute all the functions {{{
1110 for i in prepare_vm mkfs tunefs mount_target debootstrap_system \
1111          preparechroot execute_pre_scripts chrootscript execute_scripts \
1112          umount_chroot finalize_vm fscktool ; do
1113     if stage "${i}" ; then
1114        $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
1115     fi
1116 done
1117 # }}}
1118
1119 # finalize {{{
1120 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
1121 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
1122
1123 # Remove temporary mountpoint again
1124 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
1125    einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
1126 fi
1127 # }}}
1128
1129 # end dialog of autoinstallation {{{
1130 if [ -n "$AUTOINSTALL" ] ; then
1131    if dialog --title "${PN}" --pause "Finished execution of ${PN}.
1132 Automatically rebooting in 10 seconds.
1133
1134 Choose Cancel to skip rebooting." 10 60 10 ; then
1135      noeject noprompt reboot
1136   fi
1137 else
1138    einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
1139 fi
1140 # }}}
1141
1142 ## END OF FILE #################################################################
1143 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3