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