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