support tune2fs
[grml-debootstrap.git] / grml-debootstrap
1 #!/bin/sh
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 03 13:50:30 CET 2006 [mika]
8 ################################################################################
9 # http://www.debian.org/releases/stable/i386/apcs04.html.en
10
11 set -e # exit on any error
12
13 . /etc/grml/lsb-functions
14 . /etc/grml/script-functions
15
16 check4progs debootstrap || exit 1
17
18 set -u # make sure we don't have empty variables
19
20 if [ -r /etc/debootstrap/config ] ; then
21    . /etc/debootstrap/config
22 else
23    echo "/etc/debootstrap/config could not be read, exiting."
24    exit 1
25 fi
26
27 if [ -z "$TARGET" ] ; then
28    eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
29    exit 1
30 fi
31
32 if [ -n "$MKFS" ] ; then
33    einfo "Running $MKFS on $TARGET"
34    $MKFS $TARGET
35    eend $?
36 fi
37
38 if [ -n "$TUNE2FS" ] ; then
39    einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
40    TUNE2FS $TARGET
41    eend $?
42 fi
43
44 # now mount the new partition
45 if grep -q $TARGET /proc/mounts ; then
46    eerror "$TARGEt already mounted, exiting."
47 else
48   einfo "Mounting $TARGET to $MNTPOINT"
49   mount -o rw,suid,dev $TARGET $MNTPOINT
50   eend $?
51 fi
52
53 # get main packages from a debian-mirror
54 einfo "Running $DEBOOTSTRAP for release $RELEASE using mirror $MIRROR"
55 $DEBOOTSTRAP $RELEASE $MNTPOINT $MIRROR
56 eend $?
57
58 einfo "Preparing chroot system"
59   cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
60   chmod 755 $MNTPOINT/bin/chroot-script
61   mkdir $MNTPOINT/etc/debootstrap/
62
63   # make sure we have our files for later use via chroot-script
64   cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
65   cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
66
67   # copy any existing existing files to chroot
68   [ -d /etc/debootstrap/boot  ] && cp -a /etc/debootstrap/boot/*  $MNTPOINT/boot/
69   [ -d /etc/debootstrap/etc   ] && cp -a /etc/debootstrap/etc/*   $MNTPOINT/etc/
70   [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
71   [ -d /etc/debootstrap/usr   ] && cp -a /etc/debootstrap/usr/*   $MNTPOINT/usr/
72   [ -d /etc/debootstrap/var   ] && cp -a /etc/debootstrap/var/*   $MNTPOINT/var/
73 eend 0
74
75 einfo "Executing chroot-script now"
76 chroot $MNTPOINT /bin/chroot-script
77 eend $?
78
79 einfo "Unmount $MNTPOINT"
80 umount $MNTPOINT
81 eend $?
82
83 if [ "$FSCK" = 'yes' ] ; then
84    [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
85    einfo "Checking filesystem on $TARGET using $FSCKTOOL"
86    $FSCKTOOL $TARGET
87    eend $?
88 fi
89
90 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
91
92 ## END OF FILE #################################################################