prompt user for check of configuration before executing it
[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 17:59:33 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 VERSION='0.1'
17
18 case $* in
19    -h*|--h*)
20      einfo "$0 - wrapper around debootstrap for installing plain Debian via grml"
21      einfo "Configure via /etc/debootstrap/config and invoke $0 afterwards."
22      eend 0
23      exit 0
24    ;;
25    -v|--v*)
26      einfo "$0 version $VERSION"
27      einfo "Send bug reports to Michael Prokop <mika@grml.org>."
28      eend 0
29      exit 0
30    ;;
31 esac
32
33 check4progs debootstrap || exit 1
34 check4root || exit 1
35
36 if [ -r /etc/debootstrap/config ] ; then
37    . /etc/debootstrap/config
38 else
39    echo "/etc/debootstrap/config could not be read, exiting."
40    exit 1
41 fi
42
43 if [ -z "$TARGET" ] ; then
44    eerror "Please adjust /etc/debootstrap/config before running ${0}" ; eend 1
45    exit 1
46 fi
47
48 einfo "$0 - Please recheck configuration before execution:"
49 echo "
50 target partition: $TARGET
51 mount-point:      $MNTPOINT
52 install grub to:  $MBR / $GROOT [if empty it will not be installed]
53
54 Notice: continuing will delete all data from $TARGET
55 "
56 einfo "Is this ok? [y/N]"
57
58 read a
59 if ! [ "$a" = 'y' -o "$a" = 'Y' ] ; then
60    eerror "Exiting as requested." ; eend 1
61    exit 1
62 fi
63
64 if [ -n "$MKFS" ] ; then
65    einfo "Running $MKFS on $TARGET"
66    $MKFS $TARGET
67    eend $?
68 fi
69
70 if [ -n "$TUNE2FS" ] ; then
71    einfo "Disabling automatic filesystem check on $TARGET via tune2fs"
72    $TUNE2FS $TARGET
73    eend $?
74 fi
75
76 # now mount the new partition
77 if grep -q $TARGET /proc/mounts ; then
78    eerror "$TARGET already mounted, exiting."
79 else
80   [ -n "$MNTPOINT" ] || MNTPOINT='/mnt/test'
81   einfo "Mounting $TARGET to $MNTPOINT"
82   [ -d "$MNTPOINT" ] || mkdir -p "$MNTPOINT"
83   mount -o rw,suid,dev $TARGET $MNTPOINT
84   eend $?
85 fi
86
87 # get main packages from a debian-mirror
88 einfo "Running $DEBOOTSTRAP for release $RELEASE using mirror $MIRROR"
89 $DEBOOTSTRAP $RELEASE $MNTPOINT $MIRROR
90 eend $?
91
92 einfo "Preparing chroot system"
93   cp $CONFFILES/chroot-script $MNTPOINT/bin/chroot-script
94   chmod 755 $MNTPOINT/bin/chroot-script
95   mkdir $MNTPOINT/etc/debootstrap/
96
97   # make sure we have our files for later use via chroot-script
98   cp /etc/debootstrap/config $MNTPOINT/etc/debootstrap/
99   cp /etc/debootstrap/packages $MNTPOINT/etc/debootstrap/packages
100
101   # copy any existing existing files to chroot
102   [ -d /etc/debootstrap/boot  ] && cp -a /etc/debootstrap/boot/*  $MNTPOINT/boot/
103   [ -d /etc/debootstrap/etc   ] && cp -a /etc/debootstrap/etc/*   $MNTPOINT/etc/
104   [ -d /etc/debootstrap/share ] && cp -a /etc/debootstrap/share/* $MNTPOINT/share/
105   [ -d /etc/debootstrap/usr   ] && cp -a /etc/debootstrap/usr/*   $MNTPOINT/usr/
106   [ -d /etc/debootstrap/var   ] && cp -a /etc/debootstrap/var/*   $MNTPOINT/var/
107 eend 0
108
109 einfo "Executing chroot-script now"
110 chroot $MNTPOINT /bin/chroot-script
111 eend $?
112
113 einfo "Unmount $MNTPOINT"
114 umount $MNTPOINT
115 eend $?
116
117 if [ "$FSCK" = 'yes' ] ; then
118    [ -n "$FSCKTOOL" ] || FSCKTOOL="fsck.${MKFS#mkfs.}"
119    einfo "Checking filesystem on $TARGET using $FSCKTOOL"
120    $FSCKTOOL $TARGET
121    eend $?
122 fi
123
124 einfo "Finished execution of $0 - enjoy your Debian system." ; eend 0
125
126 ## END OF FILE #################################################################