0fcaa58da7699c67e169ae7abf769e72f0991287
[grml-debootstrap.git] / chroot-script
1 #!/bin/sh
2 # Filename:      /etc/debootstrap/chroot-script
3 # Purpose:       script executed in chroot when installing Debian via grml-debootstrap
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:15:42 CET 2006 [mika]
8 ################################################################################
9
10 set -e # exit on any error
11
12 . /etc/debootstrap/config || exit 1
13
14 [ -r /proc/1 ] || mount -t proc   none /proc
15
16 if [ -n "$CHROOTMIRROR" ] ; then
17    echo "$CHROOTMIRROR" > /etc/apt/sources.list
18 fi
19
20 # if ! [ -n /etc/kernel-img.conf ] ; then
21 #   echo "do_initrd = Yes" > /etc/kernel-img.conf
22 # fi
23
24 # install additional packages
25 if [ "$PACKAGES" = 'yes' ] ; then
26    if ! [ -r /etc/debootstrap/packages ] ; then
27      echo "Error: /etc/debootstrap/packages not found, exiting."
28      exit 1
29    else
30      apt-get update
31      apt-get -y install $(cat /etc/debootstrap/packages)
32    fi
33 fi
34
35 if [ -n "$RECONFIGURE" ] ; then
36    for package in $RECONFIGURE ; do
37        dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
38    done
39 fi
40
41 # set password of user root
42 echo "Activating shadow passwords."
43 shadowconfig on
44 echo "Setting password for user root:"
45 passwd
46 echo ""
47
48 if ! [ -f /etc/hosts ] ; then
49    echo "Setting up /etc/hosts"
50    echo "127.0.0.1       localhost  $HOSTNAME" > /etc/hosts
51 fi
52
53 if ! [ -f /etc/network/interfaces ] ; then
54    echo "Setting up /etc/network/interfaces"
55    cat >> /etc/network/interfaces << EOF
56 iface lo inet loopback
57 iface eth0 inet dhcp
58 auto lo
59 auto eth0
60 EOF
61 fi
62
63 # adjust timezone
64 if [ -n "$TIMEZONE" ] ; then
65    echo "Adjusting /etc/localtime"
66    ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
67 fi
68
69 # set up /etc/fstab if file is UNCONFIGURED
70 if grep -q UNCONFIGURED /etc/fstab ; then
71    echo "Setting up /etc/fstab"
72 cat > /etc/fstab << EOF
73 $TARGET      /            auto    defaults,errors=remount-ro 0   1
74 sysfs          /sys         sysfs   auto                       0   0
75 proc           /proc        proc    defaults                   0   0
76 # /dev/sda2    none         swap    sw                         0   0
77 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
78 EOF
79 fi
80
81 # create default devices
82 if ! [ -r /dev/hda20 ] ; then
83    echo "Creating generic devices in /dev - this might take a while..."
84    cd /dev && MAKEDEV generic
85 fi
86
87 # assume the first available kernel as our main kernel
88 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
89 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
90
91 # generate initrd
92 if [ -n "$INITRD" ] ; then
93    echo "Generating initrd."
94    update-initramfs -c -t -k $KERNELVER
95    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
96       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
97       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
98    fi
99 fi
100
101 if [ -n "$GROOT" ] ; then
102    echo "Installing grub"
103
104    # copy stage-files to /boot/grub/
105    [ -d /boot/grub/ ] || mkdir /boot/grub
106    cp /usr/lib/grub/i386-pc/* /boot/grub/
107
108    # finally install grub
109    update-grub -y
110    sed -i "s/groot=.*/groot=(${GROOT})/g" /boot/grub/menu.lst
111    # not sure why savedefault does not work for me; any ideas?
112    sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
113    update-grub -y
114
115    if [ -z "$MBR" ] ; then
116       echo "Notice: \$MBR not set, will not install grub therefor."
117    else
118       cp /proc/mounts /etc/mtab
119       grub-install "$MBR"
120       rm /etc/mtab
121    fi
122 fi
123
124 # unmount all filesystems in chroot, make sure nothing is left...
125 umount -a    1>/dev/null 2>/dev/null || true
126 umount /proc 1>/dev/null 2>/dev/null || true
127 umount /proc 1>/dev/null 2>/dev/null || true
128 umount -a    1>/dev/null 2>/dev/null || true
129
130 # finally exit the chroot
131 echo "Finished chroot installation, exiting."
132 exit 0
133
134 ## END OF FILE #################################################################