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