0ced334c1e38d25cd435f636956b710037a3bb42
[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:37:19 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 "MIRROR_LIST" ] ; then
17    echo $MIRROR_LIST > /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 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 && 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
43 if ! [ -f /etc/hosts ] ; then
44    echo "127.0.0.1       localhost  $HOSTNAME" > /etc/hosts
45 fi
46
47 if ! [ -f /etc/network/interfaces ] ; then
48    cat >> /etc/network/interfaces << EOF
49 iface lo inet loopback 
50 iface eth0 inet dhcp
51 auto lo
52 auto eth0
53 EOF
54 fi
55
56 # adjust timezone
57 if [ -n "$TIMEZONE" ] ; then
58    ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
59 fi
60
61 if ! [ -f /etc/fstab ] ; then
62 cat >> /etc/fstab << EOF
63 sysfs          /sys         sysfs   auto                       0   0
64 proc           /proc        proc    defaults                   0   0
65 $TARGET      /            auto    defaults,errors=remount-ro 0   1
66 # /dev/sda2      none         swap    sw                         0   0 
67 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
68 EOF
69 fi
70
71 # create default devices
72 echo "Creating generic devices in /dev - this might take a while..."
73 cd /dev && MAKEDEV generic
74
75 # generate initrd
76 if [ -n "$INITRD" ] ; then
77    echo "Generating initrd."
78    update-initramfs -c -t -k $KERNEL
79    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
80       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
81       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
82    fi
83 fi
84
85 # assume the first available kernel as our main kernel
86 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
87 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
88
89 if [ "$BOOTMGR" = 'grub' ] ; then
90    echo "Installing grub"
91    if ! [ -f /boot/grub/menu.lst ] ; then
92       # setup grub
93       mkdir /boot/grub
94       cat >> /boot/grub/menu.lst << EOF
95 # Boot automatically after 30 secs.
96 timeout 30
97
98 # By default, boot the first entry.
99 default 0
100
101 # Fallback to the second entry.
102 fallback 1
103
104 title           Debian Etch, kernel $KERNELVER (on $ARGET)
105 root            (hd0,0)
106 kernel          $KERNELIMG root=$TARGET ro
107 $GRUBINITRD
108
109 # For booting Windows
110 # title Windows
111 # rootnoverify (hd0,0)
112 # makeactive
113 # chainloader  +1
114 EOF
115    fi
116
117    # copy stage-files to /boot/grub/
118    cp -i /usr/lib/grub/i386-pc/* /boot/grub/
119
120    # finally install grub
121    grub-install $BOOT
122 fi
123
124 if [ "$BOOTMGR" = 'lilo' ] ; then
125    echo "Installing lilo"
126 # /usr/share/doc/lilo/examples/conf.sample
127 cat > /etc/lilo.conf << EOF
128 # This allows booting from any partition on disks with more than 1024 cylinders.
129 lba32
130
131 # Specifies the boot device
132 boot=$BOOT
133
134 # Specifies the device that should be mounted as root.
135 root=$TARGET
136
137 # use Debian on software raid:
138 # raid-extra-boot=mbr-only
139
140 install=text
141 # prompt
142 timeout=1
143 map=/boot/map
144 vga=normal
145
146 image=/boot/vmlinuz-2.6.17-grml
147         label="$KERNELVER"
148         #append="...."
149         read-only
150         $LILOINITRD
151 EOF
152 fi
153
154 # unmount all filesystems in chroot, make sure nothing is left...
155 umount -a
156 umount /proc
157 umount /proc
158 umount -a
159
160 # finally exit the chroot
161 echo "Finished chroot installation, exiting."
162 exit 0
163
164 ## END OF FILE #################################################################