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 17 23:00:30 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"
72 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
82 # user should recheck his configuration
83 einfo "$0 - Please recheck configuration before execution:"
85 Target partition: $TARGET
86 Mount-point: $MNTPOINT
87 Install grub to: $GROOT / $GRUB [if empty grub will not be installed]
89 Important! Continuing will delete all data from ${TARGET}!
91 einfon "Is this ok for you? [y/N] "
94 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
95 eerror "Exiting as requested." ; eend 1
99 if [ -n "$MKFS" ] ; then
100 einfo "Running $MKFS on $TARGET"
105 if [ -n "$TUNE2FS" ] ; then
106 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
112 # now mount the new partition or if it's a directory do nothing at all
113 if [ -n "$DIRECTORY" ] ; then
114 einfo "Running grml-debootstrap on a directory, nothing to mount."
116 if grep -q $TARGET /proc/mounts ; then
117 eerror "$TARGET already mounted, exiting."
119 [ -n "$MNTPOINT" ] || MNTPOINT='/mnt/test'
120 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
121 einfo "Mounting $TARGET to $MNTPOINT"
122 mount -o rw,suid,dev $TARGET $MNTPOINT
127 # get main packages from a debian-mirror
128 if [ -n "$ARCH" ] ; then
129 ARCHCMD="--arch $ARCH"
130 ARCHINFO=" (${ARCH})"
132 einfo "Running $DEBOOTSTRAP for release ${RELEASE}${ARCHINFO} using mirror $MIRROR"
133 $DEBOOTSTRAP $ARCHCMD $RELEASE $MNTPOINT $MIRROR
136 einfo "Preparing chroot system"
137 cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
138 chmod 755 $MNTPOINT/bin/chroot-script
139 mkdir $MNTPOINT/etc/debootstrap/
141 # make sure we have our files for later use via chroot-script
142 cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
143 cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
145 # make sure we can access network [relevant for cdebootstrap]
146 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp /etc/resolv.conf $MNTPOINT/etc/resolv.conf
148 # setup default locales
149 [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen
151 # copy any existing existing files to chroot
152 [ -d /etc/debootstrap/boot ] && cp -a /etc/debootstrap/boot/* $MNTPOINT/boot/
153 [ -d /etc/debootstrap/etc ] && cp -a /etc/debootstrap/etc/* $MNTPOINT/etc/
154 [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
155 [ -d /etc/debootstrap/usr ] && cp -a /etc/debootstrap/usr/* $MNTPOINT/usr/
156 [ -d /etc/debootstrap/var ] && cp -a /etc/debootstrap/var/* $MNTPOINT/var/
159 einfo "Executing chroot-script now"
160 chroot $MNTPOINT /bin/chroot-script
163 # einfo "Removing chroot-script"
164 # rm -f $MNTPOINT/bin/chroot-script
165 # rm -rf $MNTPOINT/etc/debootstrap/
168 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
169 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
171 einfo "Installing grub on ${GRUB}:"
172 grub-install --root-directory="$MNTPOINT" "(${GRUB})"
176 if [ -n "$PARTITION" ] ; then
177 einfo "Unmount $MNTPOINT"
182 if [ "$FSCK" = 'yes' ] ; then
183 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
184 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
189 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
191 ## END OF FILE #################################################################