2 # Filename: grml-bootstrap
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
10 set -e # exit on any error
15 MNTPOINT="/mnt/debootstrap.$$"
17 # inside the chroot system locales might not be available, so use minimum:
21 # make sure interactive mode is only executed when
22 # using an empty configuration file or option --interactive
26 # source core functions {{{
27 . /etc/grml/lsb-functions
28 . /etc/grml/script-functions
33 echo "$PN - wrapper around debootstrap for installing Debian
39 -m, --mirror <URL> Mirror which should be used for apt-get/aptitude.
40 -i, --iso <mnt> Mountpoint where a Debian ISO is mounted to, for use
41 instead of fetching packages from a mirror.
42 -r, --release <name> Release of new Debian system (default: stable).
43 -t, --target <target> Target partition (/dev/...) or directory.
44 -p, --mntpoint <mnt> Mountpoint used for mounting the target system.
45 --debopt <params> Extra parameters passed to the debootstrap.
46 --interactive Use interactive mode (frontend).
47 --nodebootstrap Skip debootstrap, only do configuration to the target.
48 --groot <device> Root device for usage in grub, corresponds with
49 \$TARGET in grub syntax, like hd0,0 for /dev/sda1.
50 --grub <device> Target for grub installation. Use grub syntax for
51 specifying, like hd0 for /dev/sda.
53 Configuration options:
55 -c, --config <file> Use specified configuration file, defaults to
56 /etc/debootstrap/config
57 -d, --confdir <path> Place of config files for debootstrap, defaults
59 --packages <file> Install packages defined in specified list file.
60 --debconf <file> Pre-seed packages using specified pre-seed db file.
61 --keep_src_list Do not overwrite user provided apt sources.list.
62 --hostname <name> Hostname of Debian system.
63 --password <pwd> Use specified password as password for user root.
64 --bootappend <line> Add specified appendline to kernel whilst booting.
65 --chroot-scripts <d> Execute chroot scripts from specified directory.
66 --scripts <dir> Execute scripts from specified directory.
70 -v, --verbose Increase verbosity.
71 -h, --help Print this usage information and exit.
72 -V, --version Show summary of options and exit.
74 Usage examples can be found in the grml-debootstrap manpage.
75 Send bugreports to the grml-team: bugs (at) grml.org || http://grml.org/bugs/
79 if [ "$1" = '-h' ] || [ "$1" = '-help' ] ; then
81 echo 'Please notice that this script requires root permissions!'
86 # make sure we have what we need {{{
87 check4progs debootstrap dialog || exit 1
91 # source configuration file {{{
92 if [ -r /etc/debootstrap/config ] ; then
93 if [ -n "$CONFIGFILE" ] ; then
94 einfo "Using config file $CONFIGFILE."
95 if ! . "$CONFIGFILE" ; then
96 eerror "Error reading config file $CONFIGFILE" ; eend 1 ; exit 1
99 . /etc/debootstrap/config
104 # cmdline handling {{{
105 # source external command line parameter-processing script
106 if [ -r /usr/share/grml-debootstrap/functions/cmdlineopts.clp ] ; then
107 . /usr/share/grml-debootstrap/functions/cmdlineopts.clp
108 elif [ -r ./cmdlineopts.clp ] ; then
111 echo "Error: cmdline function file not found, exiting.">&2
115 # == business-logic of command line parameter-processing
117 # source configuration file in <confdir> if supplied. {{{
118 [ "$_opt_confdir" ] && {
119 CONFFILES=$_opt_confdir
120 einfo "Using config files under $CONFFILES/."
121 if ! [ -r "$CONFFILES/config" ] ; then
122 eerror "Error: config file $CONFFILES/config not found."; eend 1; exit 1
124 if ! . "$CONFFILES/config" ; then
125 eerror "Error reading config file $CONFFILES/config" ; eend 1 ; exit 1
127 # restore the command line parameter value
128 CONFFILES=$_opt_confdir
132 [ "$_opt_mirror" ] && MIRROR=$_opt_mirror
133 [ "$_opt_iso" ] && ISO=$_opt_iso
134 [ "$_opt_release" ] && RELEASE=$_opt_release
135 [ "$_opt_target" ] && TARGET=$_opt_target
136 [ "$_opt_mntpoint" ] && MNTPOINT=$_opt_mntpoint
137 [ "$_opt_debopt" ] && DEBOOTSTRAP_OPT=$_opt_debopt
138 [ "$_opt_interactive" ] && INTERACTIVE=1
139 [ "$_opt_config" ] && CONFIGFILE=$_opt_config
140 [ "$_opt_packages_set" ] && PACKAGES='yes'
141 [ "$_opt_debconf_set" ] && DEBCONF='yes'
142 [ "$_opt_scripts_set" ] && SCRIPTS='yes'
143 [ "$_opt_chroot_scripts_set" ] && CHROOT_SCRIPTS='yes'
144 [ "$_opt_keep_src_list" ] && KEEP_SRC_LIST='yes'
145 [ "$_opt_hostname" ] && HOSTNAME=$_opt_hostname
146 [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password
147 [ "$_opt_bootappend" ] && BOOT_APPEND=$_opt_bootappend
148 [ "$_opt_groot" ] && GROOT=$_opt_groot
149 [ "$_opt_grub" ] && GRUB=$_opt_grub
150 [ "$_opt_verbose" ] && VERBOSE="-v"
152 [ "$_opt_help" ] && {
158 [ "$_opt_version" ] && {
159 einfo "$PN - version $VERSION"
160 einfo "Send bug reports to bugs@grml.org or http://grml.org/bugs/"
169 dialog --title "$PN" --yesno "Welcome to the interactive configuration of ${PN}.
170 Do you want to continue installing Debian using this frontend?" 0 0
177 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
179 grep -v 'Extended$' | \
180 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
182 if [ -z "$AVAILABLE_PARTITIONS" ] ; then
183 dialog --title "$PN" --trim \
184 --msgbox "Sorry, no partitions found. Please configure your
185 harddisks (see /proc/partitions) using a tool like fdisk,
186 cfdisk, gpart, gparted,..." 0 0
190 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
191 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet])"
194 TARGET=$(dialog --title "$PN" --single-quoted --stdout \
195 --menu "Please select the target partition:" 0 0 0 \
200 # ask for bootmanager {{{
201 prompt_for_bootmanager()
204 for device in sda hda; do
205 if [ /dev/$device != ${TARGET%[0-9]} ]; then
206 grep -q $device /proc/partitions && \
207 ADDITIONAL_PARAMS=:$device:"install bootmanager grub into MBR of /dev/${device}"
210 ADDITIONAL_PARAMS=${ADDITIONAL_PARAMS#:}
214 if echo $TARGET | grep -q "/dev/md" ; then
215 MBRPART="all disks of Software RAID $TARGET"
217 MBRPART="MBR of ${TARGET%[0-9]}"
220 GETMBR=$(dialog --stdout --title "$PN" --default-item mbr \
221 --menu "Where do you want to install the bootmanager grub?" 0 0 0 \
222 mbr "install bootmanager into $MBRPART" \
223 partition "install bootmanager into partition $TARGET" \
224 nowhere "do not install bootmanager at all" \
225 ${ADDITIONAL_PARAMS})
226 [ $? -eq 0 ] || bailout 3
231 # /dev/md0: has to be installed in MBR of /dev/md0 and not in /dev/md:
232 if echo $TARGET | grep -q "*md*" ; then
233 BOOT_PARTITION="${TARGET}"
235 BOOT_PARTITION="${TARGET%[0-9]}"
239 BOOT_PARTITION="$TARGET"
242 BOOT_PARTITION="/dev/hda"
245 BOOT_PARTITION="/dev/sda"
254 # ask for Debian release {{{
257 [ -n "$RELEASE" ] && DEFAULT_RELEASE="$RELEASE" || DEFAULT_RELEASE='lenny'
258 RELEASE="$(dialog --stdout --title "${PN}" --default-item $DEFAULT_RELEASE --menu \
259 "Please enter the Debian release you would like to use for installation:" \
261 etch Debian/old-stable \
262 lenny Debian/stable \
263 squeeze Debian/testing \
264 sid Debian/unstable)"
268 # ask for hostname {{{
269 prompt_for_hostname()
271 HOSTNAME="$(dialog --stdout --title "${PN}" --inputbox \
272 "Please enter the hostname you would like to use for installation:" \
277 # ask for password {{{
278 prompt_for_password()
282 while [ "$ROOTPW1" != "$ROOTPW2" ]; do
283 ROOTPW1=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
284 "Please enter the password for the root account:" 10 60)
285 ROOTPW2=$(dialog --insecure --stdout --title "${PN}" --passwordbox \
286 "Please enter the password for the root account again for \
287 confirmation:" 10 60)
289 if [ "$ROOTPW1" != "$ROOTPW2" ]; then
290 $(dialog --stdout --title "${PN}" --ok-label \
291 "Retry" --msgbox "Passwords do not match!" 10 60)
294 ROOTPASSWORD="$ROOTPW1"
298 # ask for Debian mirror {{{
301 MIRROR="$(dialog --stdout --title "${PN}" --inputbox \
302 "Please enter Debian mirror you would like to use for installing packages." \
307 # get grub's syntax for /dev/ice {{{
308 # usage example: 'grubdevice /dev/sda2' returns 'hd0,1'
310 if [ -z "$1" ] ; then
311 echo "Usage: grubdevice <device>">&2
316 device_map=/boot/grub/device.map
319 if ! [ -f "$device_map" ] ; then
320 echo 'quit' | grub --device-map="$device_map" 1>/dev/null 2>&1
323 # based on code from d-i's trunk/packages/arch/i386/grub-installer/grub-installer:
324 tmp_disk=`echo "$device" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
325 -e 's%\(fd[0-9]*\)$%\1%' \
326 -e 's%/part[0-9]*$%/disc%' \
327 -e 's%\(c[0-7]d[0-9]*\).*$%\1%'`
328 tmp_part=`echo "$device" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
329 -e 's%.*/fd[0-9]*$%%' \
330 -e 's%.*/floppy/[0-9]*$%%' \
331 -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
332 -e 's%.*c[0-7]d[0-9]*p*%%'`
333 tmp_drive=$(grep -v '^#' $device_map | grep "$tmp_disk *$" | sed 's%.*\([hf]d[0-9][a-g0-9,]*\).*%\1%')
336 /dev/[sh]d[a-z]) # we expect something like 'hd0'
339 *) # we expect something like 'hd0,0'
340 echo "$tmp_drive" | sed "s%$%,`expr $tmp_part - 1`%" # FIXME => md0
346 # software raid setup {{{
347 config_swraid_setup()
351 # Currently we support only raid1:
354 #RAIDLEVEL=$(dialog --stdout --title "$PN" --default-item raid1 \
355 # --menu "Which RAID level do you want to use?" 0 0 0 \
356 # raid1 "Software RAID level 1" \
357 # raid5 "Software RAID level 5")
358 #[ $? -eq 0 ] || bailout 20
360 MD_LIST=$(for i in $(seq 0 9) ; do
361 awk '{print $4}' /proc/partitions | grep -q md$i || \
362 echo "/dev/md$i /dev/md$i"
365 TARGET=$(dialog --stdout --title "$PN" --default-item /dev/md0 \
366 --menu "Which device do you want to use for ${RAIDLEVEL}?
368 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 \
370 [ $? -eq 0 ] || bailout 20
372 AVAILABLE_PARTITIONS=$(LANG=C fdisk -l 2>/dev/null | \
374 grep -v 'Extended$' | \
375 gawk -v num=0 -v ORS=' ' '/^\/dev\// {print $1}')
376 [ -n "$AVAILABLE_PARTITIONS" ] || echo "FIXME: no partitions available?"
377 PARTITION_LIST=$(for i in $(echo $AVAILABLE_PARTITIONS) ; do
378 echo "$i $(vol_id --type $i 2>/dev/null || echo [no_filesystem_yet]) off"
381 dialog --title "$PN" --separate-output \
382 --checklist "Please select the partitions you would like to use for your $RAIDLEVEL on ${TARGET}:" 0 0 0 \
383 $PARTITION_LIST 2>$TMPFILE
385 SELECTED_PARTITIONS="$(cat $TMPFILE)"
388 for i in $(cat $TMPFILE) ; do
389 NUM_PARTITIONS=$((${NUM_PARTITIONS}+1))
394 # TODO: better error handling?
395 yes | mdadm --create "${TARGET}" --level="${RAIDLEVEL}" \
396 --raid-devices="${NUM_PARTITIONS}" ${SELECTED_PARTITIONS} 1>/dev/null 2>$ERRORFILE
400 if [ "$RC" = 0 ] ; then
401 dialog --title "$PN" --msgbox \
402 "Creating $TARGET was successful." 0 0
403 rm -f "$TMPFILE" "$ERRORFILE"
405 dialog --title "$PN" --msgbox \
406 "There was an error setting up $TARGET:
411 rm -f "$TMPFILE" "$ERRORFILE"
419 if dialog --stdout --title "$PN" \
420 --defaultno --yesno "Do you want to configure Software RAID?
422 Please notice that only RAID level 1 is supported by ${PN} currently. Configuration will take place using mdadm." 0 0 ; then
428 # make sure the user is aware of the used configuration {{{
431 if [ -n "$AUTOINSTALL" ] ; then
432 if checkforrun ; then
433 eerror "Exiting as requested" ; eend 0
436 elif [ -n "$INTERACTIVE" ] ; then
438 INFOTEXT="Please recheck configuration before execution:
440 [ -n "$TARGET" ] && INFOTEXT="$INFOTEXT
442 [ -n "$GRUB" ] && INFOTEXT="$INFOTEXT
444 [ -n "$RELEASE" ] && INFOTEXT="$INFOTEXT
445 Using release: $RELEASE"
446 [ -n "$HOSTNAME" ] && INFOTEXT="$INFOTEXT
447 Using hostname $HOSTNAME"
448 [ -n "$MIRROR" ] && INFOTEXT="$INFOTEXT
449 Using mirror: $MIRROR"
453 Is this ok for you? Notice: selecting 'No' will exit ${PN}."
455 dialog --title "$PN" --no-collapse \
456 --yesno "$INFOTEXT" 0 0
458 else # if not running automatic installation display configuration and prompt for execution:
459 einfo "$PN - Please recheck configuration before execution:"
461 echo " Target: $TARGET"
462 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount point: $MNTPOINT" ;; esac
463 [ -n "$GRUB" ] && echo " Install grub: $GRUB" || echo " Install grub: no"
464 [ -n "$RELEASE" ] && echo " Using release: $RELEASE"
465 [ -n "$MIRROR" ] && echo " Using mirror: $MIRROR"
466 [ -n "$ISO" ] && echo " Using iso: $ISO"
467 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
469 einfon "Is this ok for you? [y/N] "
471 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
472 eerror "Exiting as requested." ; eend 1
479 # interactive mode {{{
486 # do not prompt for partition dialog if swraid has been configured already
487 [ -n "$TARGET" ] || prompt_for_target
489 prompt_for_bootmanager
497 # use first disk of sw-raid for grub by default, install grub on
498 # all involved disks later on
499 if echo "$TARGET" | grep -q '/dev/md' ; then
500 if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
501 # use hdX and not hdX,Y for $GRUB
502 TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}') # use first disk only
503 GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})" # like: hd0
504 GROOT="$(grubdevice ${TMPDEVICE})" # like: hd0,0
505 echo "debug: GRUB = $GRUB - GROOT = $GROOT" >/tmp/debug # FIXME
508 [ -n "$BOOT_PARTITION" ] && GRUB="$(grubdevice $BOOT_PARTITION)"
509 [ -n "$TARGET" ] && GROOT="$(grubdevice $TARGET)"
517 # run interactive mode if we didn't get the according configuration yet
518 if [ -z "$TARGET" -o -n "$INTERACTIVE" ] ; then
519 # only target might be unset, so make sure the INTERACTIVE flag is set as well
525 # finally make sure at least $TARGET is set [the partition for the new system] {{{
526 if [ -n "$TARGET" ] ; then
527 SHORT_TARGET="${TARGET##*/}"
529 eerror "Please adjust $CONFFILES/config or..."
530 eerror "... use the interactive version for configuration before running ${0}" ; eend 1
536 if [ -z "$STAGES" ] ; then
537 STAGES="/var/cache/grml-debootstrap/stages_${SHORT_TARGET}"
538 [ -d "$STAGES" ] || mkdir -p "$STAGES"
541 if [ -r "$STAGES"/grml-debootstrap ] ; then
542 if grep -q done $STAGES/grml-debootstrap ; then
543 eerror "Error: grml-debootstrap has been executed already, won't continue therefore."
544 eerror "If you want to re-execute grml-debootstrap just manually remove ${STAGES}" ; eend 1
549 # partition handling {{{
558 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
570 # architecture setup {{{
571 if [ -n "$ARCH" ] ; then
572 ARCHCMD="--arch $ARCH"
573 ARCHINFO=" (${ARCH})"
575 ARCH="$(dpkg --print-architecture)"
576 ARCHCMD="--arch $ARCH"
577 ARCHINFO=" (${ARCH})"
581 # make sure we have the right syntax when using an iso image {{{
582 if [ -n "$ISO" ] ; then
595 # helper functions {{{
596 # we want to exit smoothly and clean:
598 # make sure $TARGET is not mounted when exiting grml-debootstrap
599 if [ -n "$MNTPOINT" ] ; then
600 if grep -q $MNTPOINT /proc/mounts ; then
601 # make sure nothing is left inside chroot so we can unmount it
602 [ -x "$MNTPOINT"/etc/init.d/ssh ] && "$MNTPOINT"/etc/init.d/ssh stop
603 [ -x "$MNTPOINT"/etc/init.d/mdadm ] && "$MNTPOINT"/etc/init.d/mdadm stop
604 # ugly, but make sure we really don't leav anything
605 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /sys 1>/dev/null 2>&1
606 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount -a 1>/dev/null 2>&1
607 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
608 [ -x "$MNTPOINT"/bin/umount ] && chroot "$MNTPOINT" umount /proc 1>/dev/null 2>&1
609 [ -d "$MNTPOINT/$ISODIR" ] && umount "$MNTPOINT/$ISODIR" 1>/dev/null 2>&1
610 einfo "Unmounting $MNTPOINT" ; umount "$MNTPOINT" ; eend $?
612 if [ -n "$STAGES" ] ; then
613 echo -n "Removing stages directory ${STAGES}: "
614 rm -rf "$STAGES" && echo done
617 # remove directory only if we used the default with process id inside the name
618 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
619 einfo "Removing directory ${MNTPOINT}" ; rmdir $MNTPOINT ; eend $?
624 [ -n "$1" ] && EXIT="$1" || EXIT="1"
625 [ -n "$3" ] && einfo "Notice: just remove $STAGES/$3 to reexecute the stage"
629 trap bailout HUP INT QUIT TERM
631 # we want to execute all the functions only once, simple check for it:
633 if [ -n "$2" ] ; then
634 echo "$2" > "${STAGES}/${1}"
636 elif grep -q done "${STAGES}/${1}" 2>/dev/null ; then
637 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
639 ewarn "To reexecute it clean up the according directory inside $STAGES" ; eend 0
646 # user should recheck his configuration {{{
647 # support full automatic installation:
649 dialog --timeout 10 --title "$PN" \
650 --yesno "Do you want to stop at this stage?
652 Notice: you are running ${PN} in non-interactive mode.
653 ${PN} will install Debian ${RELEASE} on ${TARGET}.
654 Last chance to quit. Timeout of 10 seconds running....
656 Do you want to stop now?" 0 0 2>/dev/null
659 # create filesystem {{{
661 if [ -n "$MKFS" ] ; then
662 einfo "Running $MKFS on $TARGET"
664 TARGET_UUID="$(vol_id -u $TARGET 2>/dev/null || echo '')"
670 # modify filesystem settings {{{
672 if [ -n "$TUNE2FS" ] ; then
673 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
680 # mount the new partition or if it's a directory do nothing at all {{{
682 if [ -n "$DIRECTORY" ] ; then
683 einfo "Running grml-debootstrap on a directory, nothing to mount."
685 if grep -q $TARGET /proc/mounts ; then
686 eerror "$TARGET already mounted, exiting."
688 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
689 einfo "Mounting $TARGET to $MNTPOINT"
690 mount -o rw,suid,dev $TARGET $MNTPOINT
694 if [ -n "$ISODIR" ] ; then
695 einfo "Mounting Debian image loopback to $MNTPOINT/$ISODIR."
696 mkdir -p "$MNTPOINT/$ISODIR"
697 mount --bind "$ISODIR" "$MNTPOINT/$ISODIR"
703 # install main chroot {{{
704 debootstrap_system() {
705 if ! grep -q $MNTPOINT /proc/mounts ; then
708 if [ "$_opt_nodebootstrap" ]; then
709 einfo "Skipping debootstrap as requested."
712 if grep -q $MNTPOINT /proc/mounts || [ -n "$DIRECTORY" ] ; then
713 einfo "Running $DEBOOTSTRAP $DEBOOTSTRAP_OPT for release ${RELEASE}${ARCHINFO} using ${MIRROR}${ISO}"
714 [ -n "$MIRROR" ] && $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $MIRROR || \
715 $DEBOOTSTRAP $ARCHCMD $DEBOOTSTRAP_OPT $RELEASE $MNTPOINT $ISO
718 eerror "Error: $MNTPOINT not mounted, can not continue."
724 # prepare chroot via chroot-script {{{
726 einfo "Preparing chroot system"
728 # provide variables to chroot system
729 CHROOT_VARIABLES="/var/cache/grml-debootstrap/variables_${SHORT_TARGET}"
730 touch $CHROOT_VARIABLES
731 chmod 600 $CHROOT_VARIABLES # make sure nobody except root can read it
732 echo "# Configuration of ${PN}" > $CHROOT_VARIABLES
733 [ -n "$ARCH" ] && echo "ARCH=$ARCH" >> $CHROOT_VARIABLES
734 [ -n "$GROOT" ] && echo "GROOT=$GROOT" >> $CHROOT_VARIABLES
735 [ -n "$GRUB" ] && echo "GRUB=$GRUB" >> $CHROOT_VARIABLES
736 [ -n "$HOSTNAME" ] && echo "HOSTNAME=$HOSTNAME" >> $CHROOT_VARIABLES
737 [ -n "$ISODIR" ] && echo "ISODIR=$ISO" >> $CHROOT_VARIABLES
738 [ -n "$ISO" ] && echo "ISO=$ISO" >> $CHROOT_VARIABLES
739 [ -n "$MIRROR" ] && echo "MIRROR=$MIRROR" >> $CHROOT_VARIABLES
740 [ -n "$KEEP_SRC_LIST" ] && echo "KEEP_SRC_LIST=$KEEP_SRC_LIST" >> $CHROOT_VARIABLES
741 [ -n "$PACKAGES" ] && echo "PACKAGES=$PACKAGES" >> $CHROOT_VARIABLES
742 [ -n "$ROOTPASSWORD" ] && echo "ROOTPASSWORD=$ROOTPASSWORD" >> $CHROOT_VARIABLES
743 [ -n "$TARGET" ] && echo "TARGET=$TARGET" >> $CHROOT_VARIABLES
744 [ -n "$TARGET_UUID" ] && echo "TARGET_UUID=$TARGET_UUID" >> $CHROOT_VARIABLES
746 cp $VERBOSE $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
747 chmod 755 $MNTPOINT/bin/chroot-script
748 mkdir $MNTPOINT/etc/debootstrap/
750 # make sure we have our files for later use via chroot-script
751 cp $VERBOSE $CONFFILES/config $MNTPOINT/etc/debootstrap/
752 # make sure we adjust the configuration variables accordingly:
753 sed -i "s#RELEASE=.*#RELEASE=\"$RELEASE\"#" $MNTPOINT/etc/debootstrap/config
754 sed -i "s#TARGET=.*#TARGET=\"$TARGET\"#" $MNTPOINT/etc/debootstrap/config
755 sed -i "s#GRUB=.*#GRUB=\"$GRUB\"#" $MNTPOINT/etc/debootstrap/config
756 sed -i "s#GROOT=.*#GROOT=\"$GROOT\"#" $MNTPOINT/etc/debootstrap/config
759 cp $VERBOSE ${_opt_packages:-$CONFFILES/packages} \
760 $MNTPOINT/etc/debootstrap/packages
762 # debconf preseeding:
763 _opt_debconf=${_opt_debconf:-$CONFFILES/debconf-selections}
764 [ -f $_opt_debconf -a "$DEBCONF" = 'yes' ] && \
765 cp $VERBOSE $_opt_debconf $MNTPOINT/etc/debootstrap/debconf-selections
767 # copy scripts that should be executed inside the chroot:
768 _opt_chroot_scripts=${_opt_chroot_scripts:-$CONFFILES/chroot-scripts/}
769 [ -d $_opt_chroot_scripts -a "$CHROOT_SCRIPTS" = 'yes' ] && {
770 mkdir -p $MNTPOINT/etc/debootstrap/chroot-scripts
771 cp -a $VERBOSE $_opt_chroot_scripts/* $MNTPOINT/etc/debootstrap/chroot-scripts/
774 # notice: do NOT use $CHROOT_VARIABLES inside chroot but statically file instead!
775 cp $VERBOSE $CHROOT_VARIABLES $MNTPOINT/etc/debootstrap/variables
777 cp $VERBOSE -a -L $CONFFILES/extrapackages/ $MNTPOINT/etc/debootstrap/
779 # make sure we can access network [relevant for cdebootstrap]
780 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp $VERBOSE /etc/resolv.conf $MNTPOINT/etc/resolv.conf
782 # provide system's /etc/hosts to the target:
783 if ! [ -f "$MNTPOINT/etc/hosts" ] ; then
784 cp $VERBOSE /etc/hosts $MNTPOINT/etc/hosts
787 # setup default locales
788 [ -n "$LOCALES" ] && cp $VERBOSE $CONFFILES/locale.gen $MNTPOINT/etc/locale.gen
790 # MAKEDEV is just a forking bomb crap, let's do it on our own instead :)
791 ( cd $MNTPOINT/dev && tar zxf /etc/debootstrap/devices.tar.gz )
793 # copy any existing files to chroot
794 [ -d $CONFFILES/bin ] && cp $VERBOSE -a -L $CONFFILES/bin/* $MNTPOINT/bin/
795 [ -d $CONFFILES/boot ] && cp $VERBOSE -a -L $CONFFILES/boot/* $MNTPOINT/boot/
796 [ -d $CONFFILES/etc ] && cp $VERBOSE -a -L $CONFFILES/etc/* $MNTPOINT/etc/
797 [ -d $CONFFILES/sbin ] && cp $VERBOSE -a -L $CONFFILES/sbin/* $MNTPOINT/sbin/
798 [ -d $CONFFILES/share ] && cp $VERBOSE -a -L $CONFFILES/share/* $MNTPOINT/share/
799 [ -d $CONFFILES/usr ] && cp $VERBOSE -a -L $CONFFILES/usr/* $MNTPOINT/usr/
800 [ -d $CONFFILES/var ] && cp $VERBOSE -a -L $CONFFILES/var/* $MNTPOINT/var/
802 # copy local network setup to chroot
803 if [ -r /etc/network/interfaces -a ! -r "${MNTPOINT}"/etc/network/interfaces ] ; then
804 [ -d $MNTPOINT/etc/network ] || mkdir $MNTPOINT/etc/network
805 cp $VERBOSE /etc/network/interfaces $MNTPOINT/etc/network/interfaces
812 # execute all scripts in /etc/debootstrap/scripts/ {{{
814 # make sure we have $MNTPOINT available for our scripts
816 if [ -d "$_opt_scripts" ] || [ "$SCRIPTS" = 'yes' ] ; then
817 [ -d "$_opt_scripts" ] && scripts="$_opt_scripts" || scripts="$CONFFILES/scripts/"
818 for script in ${scripts}/* ; do
819 if [ -x "$script" ] ; then
820 einfo "Executing script $script"
828 # execute chroot-script {{{
830 if ! [ -r "$MNTPOINT/bin/chroot-script" ] ; then
833 if [ -x "$MNTPOINT/bin/chroot-script" ] ; then
834 einfo "Executing chroot-script now"
835 chroot "$MNTPOINT" /bin/chroot-script
838 eerror "Fatal: $MNTPOINT/bin/chroot-script could not be found."
844 # install booloader grub {{{
846 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
847 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
848 elif [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
849 for device in $SELECTED_PARTITIONS ; do
850 # TMPDEVICE=$(echo ${SELECTED_PARTITIONS} | awk '{print $1}')
851 # GRUB="$(grubdevice ${TMPDEVICE})"
852 # GRUB="$(grubdevice ${TMPDEVICE%%[0-9]})"
853 # GRUB=$(grubdevice $device)
854 GRUB="$(grubdevice ${device%%[0-9]})"
855 einfo "Installing grub on ${GRUB}:"
856 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
857 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
861 einfo "Installing grub on ${GRUB}:"
862 [ -x /usr/sbin/grub-install ] && GRUBINSTALL="/usr/sbin/grub-install --no-floppy" || GRUBINSTALL="/sbin/grub-install --no-floppy"
863 $GRUBINSTALL --root-directory="$MNTPOINT" "(${GRUB})"
869 # unmount $MNTPOINRT {{{
871 if [ -n "$ISODIR" ] ; then
872 if grep -q "$ISODIR" /proc/mounts ; then
873 einfo "Unmount $MNTPOINT/$ISODIR"
874 umount "$MNTPOINT/$ISODIR"
878 if grep -q "$MNTPOINT" /proc/mounts ; then
879 if [ -n "$PARTITION" ] ; then
880 einfo "Unmount $MNTPOINT"
888 # execute filesystem check {{{
890 if [ "$FSCK" = 'yes' ] ; then
891 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
892 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
899 # now execute all the functions {{{
900 for i in mkfs tunefs mount_target debootstrap_system preparechroot \
901 chrootscript execute_scripts grub_install umount_chroot \
903 if stage "${i}" ; then
904 $i && ( stage "${i}" done && rm -f "${STAGES}/${i}" ) || bailout 2 "i"
910 einfo "Removing ${CHROOT_VARIABLES}" ; rm "$CHROOT_VARIABLES" ; eend $?
911 einfo "Removing ${STAGES}" ; rmdir "$STAGES" ; eend $?
913 # Remove temporary mountpoint again
914 if echo "$MNTPOINT" | grep -q '/mnt/debootstrap\.' ; then
915 einfo "Removing directory ${MNTPOINT}" ; rmdir "$MNTPOINT" ; eend $?
919 # end dialog of autoinstallation {{{
920 if [ -n "$AUTOINSTALL" ] ; then
921 dialog --title "$PN" --msgbox \
922 "Finished execution of ${PN}. Enjoy your Debian system." 0 0
924 einfo "Finished execution of ${PN}. Enjoy your Debian system." ; eend 0
928 ## END OF FILE #################################################################
929 # vim: ai tw=100 expandtab foldmethod=marker shiftwidth=3