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