add [kernel|linux]-headers-
[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 23:30:04 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 "deb $CHROOTMIRROR $RELEASE main contrib non-free" /etc/apt/sources.list
18 fi
19
20 if ! [ -r /etc/kernel-img.conf ] ; then
21    echo "Setting up /etc/kernel-img.conf"
22    cat > /etc/kernel-img.conf << EOF
23 # Kernel Image management overrides
24 # See kernel-img.conf(5) for details
25 do_initrd = Yes
26 do_symlinks = Yes
27 EOF
28 fi
29
30 # install additional packages
31 if [ "$PACKAGES" = 'yes' ] ; then
32    if ! [ -r /etc/debootstrap/packages ] ; then
33      echo "Error: /etc/debootstrap/packages not found, exiting."
34      exit 1
35    else
36      apt-get update
37      apt-get --force-yes -y install $(cat /etc/debootstrap/packages)
38    fi
39 fi
40
41 if [ -n "$KERNEL" ] ; then
42    apt-get update
43    if [ "$RELEASE" = 'sarge' ] ; then
44       KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
45    else
46       KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
47    fi
48    apt-get --force-yes -y install $KERNELPACKAGES
49 fi
50
51 if [ -n "$RECONFIGURE" ] ; then
52    for package in $RECONFIGURE ; do
53        dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
54    done
55 fi
56
57 # set password of user root
58 echo "Activating shadow passwords."
59 shadowconfig on
60 echo "Setting password for user root:"
61 passwd
62 echo ""
63
64 if ! [ -f /etc/hosts ] ; then
65    echo "Setting up /etc/hosts"
66    echo "127.0.0.1       localhost  $HOSTNAME" > /etc/hosts
67 fi
68
69 if ! [ -f /etc/network/interfaces ] ; then
70    echo "Setting up /etc/network/interfaces"
71    cat >> /etc/network/interfaces << EOF
72 iface lo inet loopback
73 iface eth0 inet dhcp
74 auto lo
75 auto eth0
76 EOF
77 fi
78
79 # adjust timezone
80 if [ -n "$TIMEZONE" ] ; then
81    echo "Adjusting /etc/localtime"
82    ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
83 fi
84
85 function createfstab(){
86    echo "Setting up /etc/fstab"
87 cat > /etc/fstab << EOF
88 $TARGET      /            auto    defaults,errors=remount-ro 0   1
89 /sys           /sys         sysfs   rw,nosuid,nodev,noexec     0   0
90 proc           /proc        proc    defaults                   0   0
91 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
92 # some other examples:
93 # /dev/sda2       none         swap    sw                   0   0
94 # /dev/hda1       /Grml        ext3    dev,suid,user,noauto 0  2
95 # //1.2.3.4/pub   /smb/pub     smbfs   defaults,user,noauto,uid=grml,gid=grml 0 0
96 # linux:/pub      /beer        nfs     defaults             0  0
97 # tmpfs           /tmp         tmpfs   size=300M            0  0
98 EOF
99 }
100
101 # set up /etc/fstab if file is not present (cdebootstrap)
102 if [ ! -f /etc/fstab  ] ; then
103    createfstab
104 fi
105
106 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
107 if grep -q UNCONFIGURED /etc/fstab ; then
108    createfstab
109 fi
110
111 # set up hostname
112 if [ -n "$HOSTNAME" ] ; then
113    echo "Setting hostname to ${HOSTNAME}."
114    echo "$HOSTNAME" > /etc/hostname
115 fi
116
117 # create default devices
118 if ! [ -r /dev/hda20 ] ; then
119    echo "Creating generic devices in /dev - this might take a while..."
120    cd /dev && MAKEDEV generic
121 fi
122
123 # assume the first available kernel as our main kernel
124 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
125 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
126
127 # generate initrd
128 if [ -n "$INITRD" ] ; then
129    echo "Generating initrd."
130    update-initramfs -c -t -k $KERNELVER
131    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
132       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
133       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
134    fi
135 fi
136
137 if [ -n "$GROOT" ] ; then
138    echo "Installing grub"
139
140    # copy stage-files to /boot/grub/
141    [ -d /boot/grub/ ] || mkdir /boot/grub
142    cp /usr/lib/grub/i386-pc/* /boot/grub/
143
144    # finally install grub
145    update-grub -y
146    sed -i "s/groot=.*/groot=(${GROOT})/g" /boot/grub/menu.lst
147    # not sure why savedefault does not work for me; any ideas?
148    sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
149    update-grub -y
150
151    if [ -z "$MBR" ] ; then
152       echo "Notice: \$MBR not set, will not install grub therefor."
153    else
154       cp /proc/mounts /etc/mtab
155       grub-install "$MBR"
156       rm /etc/mtab
157    fi
158 fi
159
160 # make sure we don't have any running processes left
161 [ -x /etc/init.d/ssh ] && /etc/init.d/ssh stop
162
163 # unmount all filesystems in chroot, make sure nothing is left...
164 umount -a    1>/dev/null 2>/dev/null || true
165 umount /proc 1>/dev/null 2>/dev/null || true
166 umount /proc 1>/dev/null 2>/dev/null || true
167 umount -a    1>/dev/null 2>/dev/null || true
168
169 # finally exit the chroot
170 echo "Finished chroot installation, exiting."
171 exit 0
172
173 ## END OF FILE #################################################################