run 'true' if umount... in chroot-script fails
[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 14:02:25 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 # install additional packages
21 if [ "$PACKAGES" = 'yes' ] ; then
22    if ! [ -r /etc/debootstrap/packages ] ; then
23      echo "Error: /etc/debootstrap/packages not found, exiting."
24      exit 1
25    else
26      apt-get update
27      apt-get -y install $(cat /etc/debootstrap/packages)
28    fi
29 fi
30
31 if [ -n "$RECONFIGURE" ] ; then
32    for package in $RECONFIGURE ; do
33        dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
34    done
35 fi
36
37 # set password of user root
38 echo "Activating shadow passwords."
39 shadowconfig on
40 echo "Setting password for user root:"
41 passwd
42 echo ""
43
44 if ! [ -f /etc/hosts ] ; then
45    echo "Setting up /etc/hosts"
46    echo "127.0.0.1       localhost  $HOSTNAME" > /etc/hosts
47 fi
48
49 if ! [ -f /etc/network/interfaces ] ; then
50    echo "Setting up /etc/network/interfaces"
51    cat >> /etc/network/interfaces << EOF
52 iface lo inet loopback
53 iface eth0 inet dhcp
54 auto lo
55 auto eth0
56 EOF
57 fi
58
59 # adjust timezone
60 if [ -n "$TIMEZONE" ] ; then
61    echo "Adjusting /etc/localtime"
62    ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
63 fi
64
65 # set up /etc/fstab if file is UNCONFIGURED
66 if grep -q UNCONFIGURED /etc/fstab ; then
67    echo "Setting up /etc/fstab"
68 cat >> /etc/fstab << EOF
69 sysfs          /sys         sysfs   auto                       0   0
70 proc           /proc        proc    defaults                   0   0
71 $TARGET      /            auto    defaults,errors=remount-ro 0   1
72 # /dev/sda2      none         swap    sw                         0   0
73 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
74 EOF
75 fi
76
77 # create default devices
78 if ! [ -r /dev/hda20 ] ; then
79    echo "Creating generic devices in /dev - this might take a while..."
80    cd /dev && MAKEDEV generic
81 fi
82
83 # assume the first available kernel as our main kernel
84 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
85 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
86
87 # generate initrd
88 if [ -n "$INITRD" ] ; then
89    echo "Generating initrd."
90    update-initramfs -c -t -k $KERNELVER
91    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
92       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
93       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
94    fi
95 fi
96
97 if [ "$BOOTMGR" = 'grub' ] ; then
98    echo "Installing grub"
99 #   if ! [ -f /boot/grub/menu.lst ] ; then
100 #      # setup grub
101 #      mkdir /boot/grub
102 #      cat >> /boot/grub/menu.lst << EOF
103 ## Boot automatically after 30 secs.
104 #timeout 30
105 #
106 ## By default, boot the first entry.
107 #default 0
108 #
109 ## Fallback to the second entry.
110 #fallback 1
111 #
112 #title           Debian Etch, kernel $KERNELVER (on $ARGET)
113 #root            (hd0,0)
114 #kernel          $KERNELIMG root=$TARGET ro
115 #$GRUBINITRD
116 #
117 ## For booting Windows
118 ## title Windows
119 ## rootnoverify (hd0,0)
120 ## makeactive
121 ## chainloader  +1
122 #EOF
123 #   fi
124
125    # copy stage-files to /boot/grub/
126    [ -d /boot/grub/ ] || mkdir /boot/grub
127    cp -i /usr/lib/grub/i386-pc/* /boot/grub/
128
129    # otherwise grub fails with 'Could not find device for /boot/boot: not found or not a block device'
130    cp /etc/mtab /etc/mtab.old
131    cp /proc/mounts /etc/mtab
132
133    # finally install grub
134    # grub-install $BOOT
135    update-grub -y
136
137    # restore mtab again
138    mv /etc/mtab.old /etc/mtab
139 fi
140
141 if [ "$BOOTMGR" = 'lilo' ] ; then
142    echo "Installing lilo"
143 # /usr/share/doc/lilo/examples/conf.sample
144 cat > /etc/lilo.conf << EOF
145 # This allows booting from any partition on disks with more than 1024 cylinders.
146 lba32
147
148 # Specifies the boot device
149 boot=$BOOT
150
151 # Specifies the device that should be mounted as root.
152 root=$TARGET
153
154 # use Debian on software raid:
155 # raid-extra-boot=mbr-only
156
157 install=text
158 # prompt
159 timeout=1
160 map=/boot/map
161 vga=normal
162
163 image=/boot/vmlinuz-2.6.17-grml
164         label="$KERNELVER"
165         #append="...."
166         read-only
167         $LILOINITRD
168 EOF
169 fi
170
171 # unmount all filesystems in chroot, make sure nothing is left...
172 umount -a     || true
173 umount /proc  || true
174 umount /proc  || true
175 umount -a     || true
176
177 # finally exit the chroot
178 echo "Finished chroot installation, exiting."
179 exit 0
180
181 ## END OF FILE #################################################################