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: Mon Apr 09 15:34:02 CEST 2007 [mika]
8 ################################################################################
9 # http://www.debian.org/releases/stable/i386/index.html.en
11 set -e # exit on any error
13 . /etc/grml/lsb-functions
14 . /etc/grml/script-functions
16 # inside the chroot system the locales might not be available, so use minimum:
24 einfo "$0 - wrapper around debootstrap for installing plain Debian via grml"
25 einfo "Adjust /etc/debootstrap/config and invoke $0 afterwards."
30 einfo "$0 version $VERSION"
31 einfo "Send bug reports to Michael Prokop <mika@grml.org>."
37 check4progs debootstrap || exit 1
40 # without config file it won't work
41 if [ -r /etc/debootstrap/config ] ; then
42 . /etc/debootstrap/config
44 echo "/etc/debootstrap/config could not be read, exiting."
48 if [ -z "$STAGES" ] ; then
49 STAGES='/etc/debootstrap/stages'
50 [ -d "$STAGES" ] || mkdir -p "$STAGES"
53 # make sure at least $TARGET is set [the partition for the new system]
54 if [ -z "$TARGET" ] ; then
55 eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
60 # make sure $TARGET is not mounted when exiting grml-debootstrap
61 if [ -n "$TARGET" ] ; then
62 if grep -q $TARGET /proc/mounts ; then
63 [ -x "$TARGET"/etc/init.d/ssh ] && "$TARGET"/etc/init.d/ssh stop
64 [ -x "$TARGET"/etc/init.d/mdadm ] && "$TARGET"/etc/init.d/mdadm stop
65 echo "Unmounting $TARGET"
69 [ -n "$1" ] && EXIT="$1" || EXIT="1"
76 eerror 'Error: stage() requires at least one argument.'
80 if [ -z "$STAGES" ] ; then
81 eerror 'Error: $STAGES not set.'
86 if [ -f "$STAGES/$1" ] ; then
87 if grep -q done "$STAGES/$1" ; then
88 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
91 echo "$2" > "$STAGES/$1"
105 # assume we are installing into a directory, don't run mkfs and grub related stuff therefore
116 # user should recheck his configuration
117 einfo "$0 - Please recheck configuration before execution:"
120 case "$MNTPOINT" in "$TARGET") ;; *) echo " Mount-point: $MNTPOINT" ;; esac
121 [ -n "$GRUB" ] && echo " Install grub to: $GROOT / $GRUB"
122 case "$MNTPOINT" in "$TARGET") ;; *) echo " Important! Continuing will delete all data from ${TARGET}!" ;; esac
124 einfon "Is this ok for you? [y/N] "
127 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
128 eerror "Exiting as requested." ; eend 1
132 if [ -n "$MKFS" ] ; then
134 einfo "Running $MKFS on $TARGET"
141 if [ -n "$TUNE2FS" ] ; then
143 einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
150 # now mount the new partition or if it's a directory do nothing at all
151 if [ -n "$DIRECTORY" ] ; then
152 einfo "Running grml-debootstrap on a directory, nothing to mount."
154 if grep -q $TARGET /proc/mounts ; then
155 eerror "$TARGET already mounted, exiting."
157 [ -n "$MNTPOINT" ] || MNTPOINT='/mnt/test'
158 [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
159 einfo "Mounting $TARGET to $MNTPOINT"
160 mount -o rw,suid,dev $TARGET $MNTPOINT
165 # get main packages from a debian-mirror
166 if [ -n "$ARCH" ] ; then
167 ARCHCMD="--arch $ARCH"
168 ARCHINFO=" (${ARCH})"
170 ARCH="$(dpkg --print-architecture)"
171 ARCHCMD="--arch $ARCH"
172 ARCHINFO=" (${ARCH})"
176 einfo "Running $DEBOOTSTRAP for release ${RELEASE}${ARCHINFO} using mirror $MIRROR"
177 $DEBOOTSTRAP $ARCHCMD $RELEASE $MNTPOINT $MIRROR
178 stage debootstrap done
182 einfo "Preparing chroot system"
183 cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
184 chmod 755 $MNTPOINT/bin/chroot-script
185 mkdir $MNTPOINT/etc/debootstrap/
187 # make sure we have our files for later use via chroot-script
188 cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
189 cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
191 # make sure we can access network [relevant for cdebootstrap]
192 [ -f "$MNTPOINT/etc/resolv.conf" ] || cp /etc/resolv.conf $MNTPOINT/etc/resolv.conf
194 # setup default locales
195 [ -n "$LOCALES" ] && cp /etc/debootstrap/locale.gen $MNTPOINT/etc/locale.gen
197 # copy any existing existing files to chroot
198 [ -d /etc/debootstrap/boot ] && cp -a /etc/debootstrap/boot/* $MNTPOINT/boot/
199 [ -d /etc/debootstrap/etc ] && cp -a /etc/debootstrap/etc/* $MNTPOINT/etc/
200 [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
201 [ -d /etc/debootstrap/usr ] && cp -a /etc/debootstrap/usr/* $MNTPOINT/usr/
202 [ -d /etc/debootstrap/var ] && cp -a /etc/debootstrap/var/* $MNTPOINT/var/
204 stage preparechroot done
207 einfo "Executing chroot-script now"
208 chroot "$MNTPOINT" /bin/chroot-script
210 stage chrootscript done
212 # einfo "Removing chroot-script"
213 # rm -f $MNTPOINT/bin/chroot-script
214 # rm -rf $MNTPOINT/etc/debootstrap/
217 if [ -z "$GRUB" -o -z "$GROOT" ] ; then
218 echo "Notice: \$GRUB or \$GROOT not defined, will not install grub therefor."
221 einfo "Installing grub on ${GRUB}:"
222 grub-install --root-directory="$MNTPOINT" "(${GRUB})"
224 stage grubinstall done
227 if [ -n "$PARTITION" ] ; then
228 einfo "Unmount $MNTPOINT"
233 if [ "$FSCK" = 'yes' ] ; then
235 [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
236 einfo "Checking filesystem on $TARGET using $FSCKTOOL"
242 # finally remove stages on main system so grml-deboostrap can be reexecuted
245 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
247 ## END OF FILE #################################################################