Release new version 0.88
[grml-debootstrap.git] / chroot-script
1 #!/bin/bash
2 # Filename:      /etc/debootstrap/chroot-script
3 # Purpose:       script executed in chroot when installing Debian via grml-debootstrap
4 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports:   see https://grml.org/bugs/
6 # License:       This file is licensed under the GPL v2.
7 ################################################################################
8 # GRML_CHROOT_SCRIPT_MARKER - do not remove this line unless you want to keep
9 # this script as /bin/chroot-script on your new installed system
10 ################################################################################
11
12 # error_handler {{{
13 if [ "$REPORT_TRAP_ERR" = "yes" ] || [ "$FAIL_TRAP_ERR" = "yes" ]; then
14    set -E
15    set -o pipefail
16    trap "error_handler" ERR
17 fi
18 # }}}
19
20 # shellcheck disable=SC1091
21 . /etc/debootstrap/config    || exit 1
22 # shellcheck disable=SC1091
23 . /etc/debootstrap/variables || exit 1
24
25 [ -r /proc/1 ] || mount -t proc none /proc
26 [ -r /sys/kernel ] || mount -t sysfs none /sys
27
28 # variable checks {{{
29
30 # use aptitude only if it's available
31 if [ -x /usr/bin/aptitude ] ; then
32    APTUPDATE="aptitude update $DPKG_OPTIONS"
33    # Debian ISOs do not contain signed Release files
34    if [ -n "$ISO" ] ; then
35       APTINSTALL="aptitude -y --allow-untrusted --without-recommends install $DPKG_OPTIONS"
36       APTUPGRADE="aptitude -y --allow-untrusted safe-upgrade $DPKG_OPTIONS"
37    else
38       APTINSTALL="aptitude -y --without-recommends install $DPKG_OPTIONS"
39       APTUPGRADE="aptitude -y safe-upgrade $DPKG_OPTIONS"
40    fi
41 else
42    APTINSTALL="apt-get -y --no-install-recommends install $DPKG_OPTIONS"
43    APTUPDATE="apt-get update $DPKG_OPTIONS"
44    APTUPGRADE="apt-get -y upgrade $DPKG_OPTIONS"
45 fi
46
47 if [ -z "$STAGES" ] ; then
48    STAGES='/etc/debootstrap/stages'
49    [ -d "$STAGES" ] || mkdir -p "$STAGES"
50 fi
51 # }}}
52
53 # helper functions {{{
54 stage() {
55   if [ -n "$2" ] ; then
56      echo "$2" > "$STAGES/$1"
57      return 0
58   elif grep -q 'done' "$STAGES/$1" 2>/dev/null ; then
59      echo "   [*] Notice: stage $1 has been executed already, skipping execution therefore.">&2
60      return 1
61   fi
62   echo "   Executing stage ${1}"
63   return 0
64 }
65
66 askpass() {
67   # read -s emulation for dash. result is in $resp.
68   set -o noglob
69   [ -t 0 ] && stty -echo
70   read -r resp
71   [ -t 0 ] && stty echo
72   set +o noglob
73 }
74 # }}}
75
76 # define chroot mirror {{{
77 chrootmirror() {
78   if [ -n "$KEEP_SRC_LIST" ] ; then
79     echo "KEEP_SRC_LIST has been set, skipping chrootmirror stage."
80     return
81   fi
82
83   if [ -z "$COMPONENTS" ] ; then
84     COMPONENTS='main'
85   fi
86   echo "Using repository components $COMPONENTS"
87
88   if [ -n "$ISO" ] ; then
89     echo "Adjusting sources.list for ISO (${ISO})."
90     echo "deb $ISO $RELEASE $COMPONENTS" > /etc/apt/sources.list
91
92     if [ -n "$MIRROR" ] ; then
93       echo "Adding mirror entry (${MIRROR}) to sources.list."
94       echo "deb $MIRROR $RELEASE $COMPONENTS" >> /etc/apt/sources.list
95     fi
96   else
97     if [ -n "$MIRROR" ] ; then
98       echo "Adjusting sources.list for mirror (${MIRROR})."
99       echo "deb $MIRROR $RELEASE $COMPONENTS" > /etc/apt/sources.list
100     fi
101   fi
102
103   # LTS support
104   case "$RELEASE" in
105     squeeze)
106       if [ -n "$MIRROR" ] ; then
107         echo "Release matching $RELEASE - enabling LTS support in sources.list"
108         echo "deb $MIRROR ${RELEASE}-lts $COMPONENTS" >> /etc/apt/sources.list
109       fi
110       ;;
111   esac
112
113   # add security.debian.org:
114   case "$RELEASE" in
115     unstable|sid|lenny) ;;  # no security pool available
116     *)
117       echo "Adding security.debian.org to sources.list."
118       echo "deb http://security.debian.org ${RELEASE}/updates $COMPONENTS" >> /etc/apt/sources.list
119       ;;
120   esac
121 }
122 # }}}
123
124 # remove local chroot mirror {{{
125 remove_chrootmirror() {
126   if [ -n "$KEEP_SRC_LIST" ] ; then
127     echo "KEEP_SRC_LIST has been set, skipping remove_chrootmirror stage."
128     return
129   fi
130
131   if [ -n "$ISO" ] ; then
132     echo "Removing ISO (${ISO}) from sources.list."
133     TMP_ISO="${ISO//\//\\\/}"
134     sed -i "/deb $TMP_ISO $RELEASE $COMPONENTS/ D" /etc/apt/sources.list
135   else
136     if [ -n "$MIRROR" ] && echo "$MIRROR" | grep -q 'file:' ; then
137       echo "Removing local mirror (${MIRROR}) from sources.list."
138       TMP_MIRROR="${MIRROR//\//\\\/}"
139       sed -i "/deb $TMP_MIRROR $RELEASE $COMPONENTS/ D" /etc/apt/sources.list
140       echo "Adding fallback mirror entry (${FALLBACK_MIRROR}) to sources.list instead."
141       echo "deb $FALLBACK_MIRROR $RELEASE $COMPONENTS" >> /etc/apt/sources.list
142     fi
143   fi
144 }
145 # }}}
146
147 # set up grml repository {{{
148 grmlrepos() {
149   if [ -n "$GRMLREPOS" ] ; then
150      # user might have provided their own apt sources.list
151      if ! grep -q grml /etc/apt/sources.list.d/grml.list 2>/dev/null ; then
152         cat >> /etc/apt/sources.list.d/grml.list << EOF
153 # grml: stable repository:
154   deb     http://deb.grml.org/ grml-stable  main
155   deb-src http://deb.grml.org/ grml-stable  main
156
157 # grml: testing/development repository:
158   deb     http://deb.grml.org/ grml-testing main
159   deb-src http://deb.grml.org/ grml-testing main
160 EOF
161      fi
162
163      # shellcheck disable=SC2086
164      if apt-get update $DPKG_OPTIONS; then
165        # shellcheck disable=SC2086
166        apt-get -y --allow-unauthenticated install grml-debian-keyring $DPKG_OPTIONS
167        # shellcheck disable=SC2086
168        apt-get update $DPKG_OPTIONS
169      else
170        # make sure we have the keys available for aptitude
171        gpg --keyserver subkeys.pgp.net --recv-keys 709BCE51568573EBC160E590F61E2E7CECDEA787
172        gpg --export 709BCE51568573EBC160E590F61E2E7CECDEA787 | apt-key add - || true # not yet sure
173        # why it's necessary, sometimes we get an error even though it works [mika]
174      fi
175
176      # make sure we install packages from Grml's pool only if not available
177      # from Debian!
178      if ! grep -q grml /etc/apt/preferences 2>/dev/null ; then
179         cat >> /etc/apt/preferences << EOF
180 // debian pool (default):
181 Package: *
182 Pin: release o=Debian
183 Pin-Priority: 996
184
185 // main grml-repository:
186 Package: *
187 Pin: origin deb.grml.org
188 Pin-Priority: 991
189 EOF
190      fi
191   fi
192 }
193 # }}}
194
195 # feature to provide Debian backports repos {{{
196 backportrepos() {
197   if [ -n "$BACKPORTREPOS" ] ; then
198     cat >> /etc/apt/sources.list.d/backports.list << EOF
199 # debian backports: ${RELEASE}-backports repository:
200 deb     ${MIRROR} ${RELEASE}-backports main
201 deb-src ${MIRROR} ${RELEASE}-backports main
202 EOF
203   fi
204 }
205 # }}}
206
207 # set up kernel-img.conf {{{
208 kernelimg_conf() {
209   if ! [ -r /etc/kernel-img.conf ] ; then
210      echo "Setting up /etc/kernel-img.conf"
211      cat > /etc/kernel-img.conf << EOF
212 # Kernel Image management overrides
213 # See kernel-img.conf(5) for details
214 do_initrd = Yes
215 do_symlinks = Yes
216 EOF
217   fi
218 }
219 # }}}
220
221 # make sure services do not start up {{{
222 install_policy_rcd() {
223   if ! [ -r /usr/sbin/policy-rc.d ] ; then
224      export POLICYRCD=1
225      cat > /usr/sbin/policy-rc.d << EOF
226 #!/bin/sh
227 exit 101
228 EOF
229      chmod 775 /usr/sbin/policy-rc.d
230   fi
231 }
232 # }}}
233
234 # make sure we have an up2date system {{{
235 upgrade_system() {
236   if [ "$UPGRADE_SYSTEM" = "yes" ] ; then
237     echo "Running update + upgrade"
238     $APTUPDATE
239     DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTUPGRADE
240   else
241     echo "Not running update + upgrade as \$UPDATE_AND_UPGRADE is not set to 'yes'."
242   fi
243 }
244
245 # }}}
246 # remove now useless apt cache {{{
247 remove_apt_cache() {
248   if [ "$RM_APTCACHE" = 'yes' ] ; then
249     echo "Cleaning apt cache."
250     # shellcheck disable=SC2086
251     apt-get clean $DPKG_OPTIONS
252   else
253     echo "Not cleaning apt cache as \$RM_APTCACHE is unset."
254   fi
255 }
256 # }}}
257
258 # install additional packages {{{
259 packages() {
260   # Pre-seed the debconf database with answers. Each question will be marked
261   # as seen to prevent debconf from asking the question interactively.
262   [ -f /etc/debootstrap/debconf-selections ] && {
263     echo "Preseeding the debconf database, some lines might be skipped..."
264     debconf-set-selections < /etc/debootstrap/debconf-selections
265   }
266
267   if [ "$PACKAGES" = 'yes' ] ; then
268      if ! [ -r /etc/debootstrap/packages ] ; then
269        echo "Error: /etc/debootstrap/packages (inside chroot) not found, exiting." >&2
270        exit 1
271      else
272        $APTUPDATE
273        # shellcheck disable=SC2086,SC2046
274        DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $(grep -v '^#' /etc/debootstrap/packages) $GRMLPACKAGES
275      fi
276   fi
277 }
278 # }}}
279
280 # install extra packages {{{
281 extrapackages() {
282     if [ "$EXTRAPACKAGES" = 'yes' ] ; then
283         PACKAGELIST=$(find /etc/debootstrap/extrapackages -type f -name '*.deb')
284         if [ -n "$PACKAGELIST" ]; then
285             # shellcheck disable=SC2086
286             dpkg -i $PACKAGELIST
287             # run apt again to resolve any deps
288             DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL
289         fi
290     fi
291 }
292 # }}}
293
294 # check if the specified Debian package exists
295 package_exists() {
296   output=$(apt-cache show "$1" 2>/dev/null)
297   [ -n "$output" ]
298   return $?
299 }
300
301
302 # determine the kernel version postfix
303 get_kernel_version() {
304   # do not override $KERNEL if set via config file
305   if [ -n "$KERNEL" ] ; then
306     echo "$KERNEL"
307     return 0
308   fi
309
310   local KARCH
311
312   # shellcheck disable=SC2153
313   case "$ARCH" in
314     i386)
315       case "$RELEASE" in
316         lenny|squeeze|wheezy) KARCH='686' ;;
317         # since jessie the linux-image-686 image doesn't exist any longer
318         *) KARCH='686-pae' ;;
319       esac
320       ;;
321     amd64)
322       KARCH='amd64'
323       ;;
324     *)
325       echo "Only i386 and amd64 are currently supported" >&2
326       return 1
327   esac
328
329   for KPREFIX in "" "2.6-" ; do  # iterate through the kernel prefixes,
330                                  # currently "" and "2.6-"
331     if package_exists linux-image-${KPREFIX}${KARCH} ; then
332       echo ${KPREFIX}${KARCH}
333       return 0
334     fi
335
336   done
337 }
338
339 # install kernel packages {{{
340 kernel() {
341   if [ -n "$NOKERNEL" ] ; then
342     echo "Skipping installation of kernel packages as requested via --nokernel"
343     return 0
344   fi
345
346   $APTUPDATE
347   KVER=$(get_kernel_version)
348   if [ -n "$KVER" ] ; then
349      # note: install busybox to be able to debug initramfs
350      KERNELPACKAGES="linux-image-$KVER linux-headers-$KVER busybox firmware-linux-free"
351      # only add firmware-linux if we have non-free as a component
352      if expr "$COMPONENTS" : '.*non-free' >/dev/null ; then
353        KERNELPACKAGES="$KERNELPACKAGES firmware-linux"
354      fi
355      # shellcheck disable=SC2086
356      DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $KERNELPACKAGES
357   else
358      echo "Warning: Could not find a kernel for your system. Your system won't be able to boot itself!"
359   fi
360 }
361 # }}}
362
363 # reconfigure packages {{{
364 reconfigure() {
365   if [ -n "$RECONFIGURE" ] ; then
366      for package in $RECONFIGURE ; do
367          if dpkg --list "$package" >/dev/null 2>&1 | grep -q '^ii' ; then
368            DEBIAN_FRONTEND=$DEBIAN_FRONTEND dpkg-reconfigure "$package" || \
369            echo "Warning: $package does not exist, can not reconfigure it."
370          fi
371      done
372   fi
373 }
374 # }}}
375
376 # set password of user root {{{
377 passwords()
378 {
379   if [ -n "$NOPASSWORD" ] ; then
380     echo "Skip setting root password as requested."
381     return 0
382   fi
383
384   echo "Activating shadow passwords."
385   shadowconfig on
386
387   CHPASSWD_OPTION=
388   if chpasswd --help 2>&1 | grep -q -- '-m,' ; then
389      CHPASSWD_OPTION='-m'
390   fi
391
392   if [ -n "$ROOTPASSWORD" ] ; then
393      echo root:"$ROOTPASSWORD" | chpasswd $CHPASSWD_OPTION
394      export ROOTPASSWORD=''
395   else
396     a='1'
397     b='2'
398      echo "Setting password for user root:"
399      while [ "$a" != "$b" ] ; do
400        printf "Enter new UNIX password for user root: "
401        askpass
402        a="$resp"
403        unset resp
404        echo
405        printf "Retype new UNIX password for user root: "
406        askpass
407        b="$resp"
408        unset resp
409        echo
410        if [ "$a" != "$b" ] ; then
411          echo "Sorry, passwords do not match. Retry."
412          a='1'
413          b='2'
414        else
415          echo root:"$a" | chpasswd $CHPASSWD_OPTION
416          unset a
417          unset b
418        fi
419      done
420   fi
421 }
422 # }}}
423
424 # set up /etc/hosts {{{
425 hosts() {
426   if ! [ -f /etc/hosts ] ; then
427      cat > /etc/hosts << EOF
428 127.0.0.1       localhost
429 ::1             localhost ip6-localhost ip6-loopback
430 ff02::1         ip6-allnodes
431 ff02::2         ip6-allrouters
432 EOF
433   fi
434 }
435 # }}}
436
437 # set default locales {{{
438 default_locales() {
439   if [ -n "$DEFAULT_LOCALES" ] ; then
440     if ! [ -x /usr/sbin/update-locale ] ; then
441       echo "Warning: update-locale executable not available (no locales package installed?)"
442       echo "Ignoring request to run update-locale for $DEFAULT_LOCALES therefore"
443       return 0
444     fi
445
446     /usr/sbin/update-locale LANGUAGE="$DEFAULT_LANGUAGE" LANG="$DEFAULT_LOCALES"
447   fi
448 }
449 # }}}
450
451 # adjust timezone {{{
452 timezone() {
453   if [ -n "$TIMEZONE" ] ; then
454     echo "Adjusting /etc/localtime"
455     ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
456
457     echo "Setting /etc/timezone to $TIMEZONE"
458     printf '%s\n' "$TIMEZONE"  > /etc/timezone
459
460   fi
461 }
462 # }}}
463
464 # helper function for fstab() {{{
465 createfstab(){
466   echo "Setting up /etc/fstab"
467   if [ -n "$TARGET_UUID" ] ; then
468     echo "/dev/disk/by-uuid/${TARGET_UUID} /  auto    defaults,errors=remount-ro 0   1" > /etc/fstab
469   else
470     echo "Warning: couldn't identify target UUID for rootfs, your /etc/fstab might be incomplete."
471   fi
472
473 if [ -n "$EFI" ] ; then
474   # shellcheck disable=SC2086
475   echo "UUID=$(blkid -o value -s UUID $EFI)  /boot/efi       vfat    umask=0077      0       1" >> /etc/fstab
476 fi
477
478 cat >> /etc/fstab << EOF
479 proc           /proc        proc    defaults                      0   0
480 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto                0   0
481 # some other examples:
482 # /dev/sda2       none         swap    sw,pri=0             0   0
483 # /dev/hda1       /Grml        ext3    dev,suid,user,noauto 0  2
484 # //1.2.3.4/pub   /smb/pub     cifs    user,noauto,uid=grml,gid=grml 0 0
485 # linux:/pub      /beer        nfs     defaults             0  0
486 # tmpfs           /tmp         tmpfs   size=300M            0  0
487 # /dev/sda5       none         swap    sw                   0  0
488 EOF
489 }
490 # }}}
491
492 # generate /etc/fstab {{{
493 fstab() {
494   # set up /etc/fstab if file is not present (cdebootstrap)
495   if [ ! -f /etc/fstab  ] ; then
496      createfstab
497   fi
498
499   # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
500   if grep -q UNCONFIGURED /etc/fstab ; then
501      createfstab
502   fi
503 }
504 # }}}
505
506 # set up hostname {{{
507 hostname() {
508   if [ -n "$HOSTNAME" ] ; then
509      echo "Setting hostname to ${HOSTNAME}."
510      echo "$HOSTNAME" > /etc/hostname
511
512      # adjust postfix configuration
513      if [ -r /etc/postfix/main.cf ] ; then
514         # adjust hostname related options:
515         sed -i "s/grml/$HOSTNAME/g" /etc/postfix/main.cf
516
517         # listen on loopback interface only:
518         sed -i "s/^inet_interfaces = .*/inet_interfaces = loopback-only/" /etc/postfix/main.cf
519         grep -q inet_interfaces /etc/postfix/main.cf || echo 'inet_interfaces = loopback-only' >> /etc/postfix/main.cf
520      fi
521      if [ -r /etc/mailname ] ; then
522         # adjust /etc/mailname
523         local etc_mail_domain
524         etc_mail_domain=$(/bin/dnsdomainname 2>/dev/null || echo localdomain)
525         case "$HOSTNAME" in
526           *.*)
527             local mailname="$HOSTNAME"
528             ;;
529           *)
530             local mailname="${HOSTNAME}.${etc_mail_domain}"
531             ;;
532         esac
533         echo "Setting mailname to ${mailname}"
534         echo "$mailname" > /etc/mailname
535      fi
536   fi
537 }
538 # }}}
539
540 # generate initrd/initramfs {{{
541 initrd() {
542   # assume the first available kernel as our main kernel
543   # shellcheck disable=SC2012
544   KERNELIMG=$(ls -1 /boot/vmlinuz-* 2>/dev/null | head -1)
545   if [ -z "$KERNELIMG" ] ; then
546      echo 'No kernel image found, skipping initrd stuff.'>&2
547      return
548   fi
549
550   KERNELVER=${KERNELIMG#/boot/vmlinuz-}
551
552   # generate initrd
553   if [ -n "$INITRD" ] ; then
554      echo "Generating initrd."
555      update-initramfs -c -t -k "$KERNELVER"
556   fi
557 }
558 # }}}
559
560 efi_setup() {
561   if [ -z "$EFI" ] ; then
562     return 0
563   fi
564
565   if ! dpkg --list efibootmgr 2>/dev/null | grep -q '^ii' ; then
566     echo "Notice: efi option set but no efibootmgr package, installing it therefore."
567     DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL efibootmgr
568   fi
569
570   mkdir -p /boot/efi
571   echo "Mounting $EFI on /boot/efi"
572   mount "$EFI" /boot/efi || return 1
573
574   echo "Invoking efibootmgr"
575   efibootmgr || return 1
576 }
577
578 # grub configuration/installation {{{
579 grub_install() {
580
581   if [ -z "$GRUB" ] ; then
582     echo "Notice: \$GRUB not defined, will not install grub inside chroot at this stage."
583     return 0
584   fi
585
586   efi_setup || return 1
587
588   if [ -n "$EFI" ] ; then
589     GRUB_PACKAGE=grub-efi-amd64
590   else
591     GRUB_PACKAGE=grub-pc
592   fi
593
594   # make sure this is pre-defined so we have sane settings for automated
595   # upgrades, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=711019
596   echo "Setting ${GRUB_PACKAGE} debconf configuration for install device to $GRUB"
597   echo "${GRUB_PACKAGE} ${GRUB_PACKAGE}/install_devices multiselect $GRUB" | debconf-set-selections
598
599   if ! dpkg --list ${GRUB_PACKAGE} 2>/dev/null | grep -q '^ii' ; then
600     echo "Notice: grub option set but no ${GRUB_PACKAGE} package, installing it therefore."
601     DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL ${GRUB_PACKAGE}
602   fi
603
604   if ! [ -x "$(command -v grub-install)" ] ; then
605      echo "Error: grub-install not available. (Error while installing grub package?)" >&2
606      return 1
607   fi
608
609   if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
610      for device in $SELECTED_PARTITIONS ; do
611         GRUB="${device%%[0-9]}"
612         echo "Installing grub on ${GRUB}:"
613         grub-install --no-floppy "$GRUB"
614      done
615      rm -f /boot/grub/device.map
616   else
617      echo "Installing grub on ${GRUB}:"
618      case "$RELEASE" in
619        lenny|squeeze|wheezy)
620          grub-install --no-floppy "$(readlink -f "${GRUB}")"
621          rm -f /boot/grub/device.map
622          ;;
623        *)
624          echo "(hd0) ${GRUB}" > /boot/grub/device.map
625          grub-install "(hd0)"
626          rm /boot/grub/device.map
627          ;;
628      esac
629   fi
630
631   echo "Adjusting grub configuration for use on ${GRUB}."
632
633   # finally install grub
634   if [ -x /usr/sbin/update-grub ] ; then
635      UPDATEGRUB='/usr/sbin/update-grub'
636   elif [ -x /sbin/update-grub ] ; then
637      UPDATEGRUB='/sbin/update-grub'
638   else
639     echo "Error: update-grub not available, can not execute it." >&2
640     return 1
641   fi
642
643   mountpoint /boot/efi &>/dev/null && umount /boot/efi
644
645   $UPDATEGRUB
646 }
647 # }}}
648
649 # execute all scripts present in /etc/debootstrap/chroot-scripts/ {{{
650 custom_scripts() {
651   [ -d /etc/debootstrap/chroot-scripts/ ] || return 0
652
653   for script in /etc/debootstrap/chroot-scripts/* ; do
654       echo "Executing script $script"
655       $script && echo "done" || echo "failed"
656   done
657 }
658 # }}}
659
660 # make sure we don't have any running processes left {{{
661 services() {
662   for service in ssh mdadm mdadm-raid ; do
663     if [ -x /etc/init.d/"$service" ] ; then
664        /etc/init.d/"$service" stop || true
665     fi
666   done
667 }
668 # }}}
669
670 # unmount /proc and make sure nothing is left {{{
671 finalize() {
672   # make sure we don't leave any sensible data
673   rm -f /etc/debootstrap/variables
674
675   [ -n "$POLICYRCD" ] && rm -f /usr/sbin/policy-rc.d
676
677   umount /sys >/dev/null 2>/dev/null || true
678   umount /proc >/dev/null 2>/dev/null || true
679 }
680 # }}}
681
682 # signal handler {{{
683 signal_handler() {
684   finalize
685   [ -n "$1" ] && EXIT="$1" || EXIT="1"
686   exit "$EXIT"
687 }
688 # }}}
689
690 # set signal handler {{{
691 trap signal_handler HUP INT QUIT TERM
692 # }}}
693
694 # execute the functions {{{
695
696  # always execute install_policy_rcd
697  install_policy_rcd
698
699  for i in chrootmirror grmlrepos backportrepos kernelimg_conf \
700      kernel packages extrapackages reconfigure hosts \
701      default_locales timezone fstab hostname initrd grub_install passwords \
702      custom_scripts upgrade_system remove_apt_cache services \
703      remove_chrootmirror; do
704      if stage $i ; then
705        $i && stage $i 'done' || exit 1
706      fi
707   done
708   # always execute the finalize stage:
709   finalize
710 # }}}
711
712 # finally exit the chroot {{{
713   echo "Finished chroot installation, exiting."
714   exit 0
715 # }}}
716
717 ## END OF FILE #################################################################
718 # vim: ai tw=80 expandtab foldmethod=marker