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 # Latest change: Fre Nov 10 00:50:55 CET 2006 [mika]
8 ################################################################################
9 # http://www.debian.org/releases/stable/i386/apcs04.html.en
11 set -e # exit on any error
13 . /etc/grml/lsb-functions
14 . /etc/grml/script-functions
20 einfo "$0 - wrapper around debootstrap for installing plain Debian via grml"
21 einfo "Configure via /etc/debootstrap/config and invoke $0 afterwards."
26 einfo "$0 version $VERSION"
27 einfo "Send bug reports to Michael Prokop <mika@grml.org>."
33 check4progs debootstrap || exit 1
36 # without config file it won't work
37 if [ -r /etc/debootstrap/config ] ; then
38 . /etc/debootstrap/config
40 echo "/etc/debootstrap/config could not be read, exiting."
44 # make sure at least $TARGET is set [the partition for the new system]
45 if [ -z "$TARGET" ] ; then
46 eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
51 # make sure $TARGET is not mounted when exiting grml-debootstrap
52 if [ -n "$TARGET" ] ; then
53 if grep -q $TARGET /proc/mounts ; then
54 echo "Unmounting $TARGET"
58 [ -n "$1" ] && EXIT="$1" || EXIT="1"
64 # user should recheck his configuration
65 einfo "$0 - Please recheck configuration before execution:"
67 Target partition: $TARGET
68 Mount-point: $MNTPOINT
69 Install grub to: $GROOT / $GRUB [if empty grub will not be installed]
71 Important! Continuing will delete all data from ${TARGET}!
73 einfon "Is this ok for you? [y/N] "
76 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
77 eerror "Exiting as requested." ; eend 1
81 if [ -n "$MKFS" ] ; then
82 einfo "Running $MKFS on $TARGET"
87 if [ -n "$TUNE2FS" ] ; then
88 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
93 # now mount the new partition
94 if grep -q $TARGET /proc/mounts ; then
95 eerror "$TARGET already mounted, exiting."
97 [ -n "$MNTPOINT" ] || MNTPOINT='/mnt/test'
98 einfo "Mounting $TARGET to $MNTPOINT"
99 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
100 mount -o rw,suid,dev $TARGET $MNTPOINT
104 # get main packages from a debian-mirror
105 if [ -n "$ARCH" ] ; then
106 ARCHCMD="--arch $ARCH"
107 ARCHINFO=" (${ARCH})"
109 einfo "Running $DEBOOTSTRAP for release ${RELEASE}${ARCHINFO} using mirror $MIRROR"
110 $DEBOOTSTRAP $ARCHCMD $RELEASE $MNTPOINT $MIRROR
113 einfo "Preparing chroot system"
114 cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
115 chmod 755 $MNTPOINT/bin/chroot-script
116 mkdir $MNTPOINT/etc/debootstrap/
118 # make sure we have our files for later use via chroot-script
119 cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
120 cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
122 # make sure we can access network [relevant for cdebootstrap]
123 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp /etc/resolv.conf $MNTPOINT/etc/resolv.conf
125 # setup default locales
126 [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen
128 # copy any existing existing files to chroot
129 [ -d /etc/debootstrap/boot ] && cp -a /etc/debootstrap/boot/* $MNTPOINT/boot/
130 [ -d /etc/debootstrap/etc ] && cp -a /etc/debootstrap/etc/* $MNTPOINT/etc/
131 [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
132 [ -d /etc/debootstrap/usr ] && cp -a /etc/debootstrap/usr/* $MNTPOINT/usr/
133 [ -d /etc/debootstrap/var ] && cp -a /etc/debootstrap/var/* $MNTPOINT/var/
136 einfo "Executing chroot-script now"
137 chroot $MNTPOINT /bin/chroot-script
140 # einfo "Removing chroot-script"
141 # rm -f $MNTPOINT/bin/chroot-script
142 # rm -rf $MNTPOINT/etc/debootstrap/
145 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
146 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
148 einfo "Installing grub on ${GRUB}:"
149 grub-install --root-directory="$MNTPOINT" "(${GRUB})"
153 einfo "Unmount $MNTPOINT"
157 if [ "$FSCK" = 'yes' ] ; then
158 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
159 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
164 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
166 ## END OF FILE #################################################################