- support setting locales through /etc/debootstrap/locale.gen
[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 22:27:09 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 ! [ -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 -y install $(cat /etc/debootstrap/packages)
38    fi
39 fi
40
41 if [ -n "$RECONFIGURE" ] ; then
42    for package in $RECONFIGURE ; do
43        dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
44    done
45 fi
46
47 # set password of user root
48 echo "Activating shadow passwords."
49 shadowconfig on
50 echo "Setting password for user root:"
51 passwd
52 echo ""
53
54 if ! [ -f /etc/hosts ] ; then
55    echo "Setting up /etc/hosts"
56    echo "127.0.0.1       localhost  $HOSTNAME" > /etc/hosts
57 fi
58
59 if ! [ -f /etc/network/interfaces ] ; then
60    echo "Setting up /etc/network/interfaces"
61    cat >> /etc/network/interfaces << EOF
62 iface lo inet loopback
63 iface eth0 inet dhcp
64 auto lo
65 auto eth0
66 EOF
67 fi
68
69 # adjust timezone
70 if [ -n "$TIMEZONE" ] ; then
71    echo "Adjusting /etc/localtime"
72    ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
73 fi
74
75 function createfstab(){
76    echo "Setting up /etc/fstab"
77 cat > /etc/fstab << EOF
78 $TARGET      /            auto    defaults,errors=remount-ro 0   1
79 sysfs          /sys         sysfs   auto                       0   0
80 proc           /proc        proc    defaults                   0   0
81 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
82 # /dev/sda2    none         swap    sw                         0   0
83 EOF
84 }
85
86 # set up /etc/fstab if file is not present (cdebootstrap)
87 if [ ! -f /etc/fstab  ] ; then
88    createfstab
89 fi
90
91 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
92 if grep -q UNCONFIGURED /etc/fstab ; then
93    createfstab
94 fi
95
96 # set up hostname
97 if [ -n "$HOSTNAME" ] ; then
98    echo "Setting hostname to ${HOSTNAME}."
99    echo "$HOSTNAME" > /etc/hostname
100 fi
101
102 # create default devices
103 if ! [ -r /dev/hda20 ] ; then
104    echo "Creating generic devices in /dev - this might take a while..."
105    cd /dev && MAKEDEV generic
106 fi
107
108 # assume the first available kernel as our main kernel
109 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
110 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
111
112 # generate initrd
113 if [ -n "$INITRD" ] ; then
114    echo "Generating initrd."
115    update-initramfs -c -t -k $KERNELVER
116    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
117       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
118       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
119    fi
120 fi
121
122 if [ -n "$GROOT" ] ; then
123    echo "Installing grub"
124
125    # copy stage-files to /boot/grub/
126    [ -d /boot/grub/ ] || mkdir /boot/grub
127    cp /usr/lib/grub/i386-pc/* /boot/grub/
128
129    # finally install grub
130    update-grub -y
131    sed -i "s/groot=.*/groot=(${GROOT})/g" /boot/grub/menu.lst
132    # not sure why savedefault does not work for me; any ideas?
133    sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
134    update-grub -y
135
136    if [ -z "$MBR" ] ; then
137       echo "Notice: \$MBR not set, will not install grub therefor."
138    else
139       cp /proc/mounts /etc/mtab
140       grub-install "$MBR"
141       rm /etc/mtab
142    fi
143 fi
144
145 # make sure we don't have any running processes left
146 [ -x /etc/init.d/ssh ] && /etc/init.d/ssh stop
147
148 # unmount all filesystems in chroot, make sure nothing is left...
149 umount -a    1>/dev/null 2>/dev/null || true
150 umount /proc 1>/dev/null 2>/dev/null || true
151 umount /proc 1>/dev/null 2>/dev/null || true
152 umount -a    1>/dev/null 2>/dev/null || true
153
154 # finally exit the chroot
155 echo "Finished chroot installation, exiting."
156 exit 0
157
158 ## END OF FILE #################################################################