]> spindle.queued.net Git - xodist/blob - initchroot.sh
initchroot: add a workaround for #314334
[xodist] / initchroot.sh
1 #!/bin/sh -e
2 #
3 # Copyright © 2008  Andres Salomon <dilinger@queued.net>
4 #
5 # This file is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 DIST=lenny
20 DEFUSER=olpc
21
22 . functions.sh
23
24 usage()
25 {
26         echo "" 1>&2
27         echo "Usage: $0 <root directory>" 1>&2
28         echo "" 1>&2
29         exit 1
30 }
31
32 if [ "$#" != "1" ]; then
33         usage
34 fi
35
36 ROOT_DIR=$1
37
38 if [ -d "${ROOT_DIR}" ]; then
39         echo "" 1>&2
40         echo "*** ${ROOT_DIR} already exists!" 1>&2
41         usage
42 fi
43
44 check_for_cmds debootstrap || exit 1
45
46 # create chroot
47 debootstrap --arch i386 lenny ${ROOT_DIR} http://http.us.debian.org/debian
48 mkdir ${ROOT_DIR}/ofw
49 mkdir ${ROOT_DIR}/var/cache/apt/cache
50 mount -t proc proc ${ROOT_DIR}/proc
51 mount -t devpts devpts ${ROOT_DIR}/dev/pts
52 mount -t tmpfs tmpfs ${ROOT_DIR}/var/cache/apt/cache
53
54 # allow daemons to be installed without breaking
55 mv ${ROOT_DIR}/sbin/start-stop-daemon ${ROOT_DIR}/sbin/start-stop-daemon.REAL
56 cat >${ROOT_DIR}/sbin/start-stop-daemon<<EOF
57 #!/bin/sh
58 echo
59 echo "Warning: Fake start-stop-daemon called, doing nothing"
60 EOF
61 chmod 755 ${ROOT_DIR}/sbin/start-stop-daemon
62
63 # set up apt (working around #314334)
64 export DEBIAN_FRONTEND=noninteractive
65 export DEBCONF_PRIORITY=critical
66 cat >${ROOT_DIR}/etc/apt/apt.conf<<EOF
67 Acquire::Pdiffs "false";
68 APT::Install-Recommends "false";
69 Dir {
70         Cache "var/cache/apt/" {
71                 srcpkgcache "cache/srcpkgcache.bin";
72                 pkgcache "cache/pkgcache.bin";
73         };
74 };
75 EOF
76 cat >${ROOT_DIR}/etc/apt/sources.list<<EOF
77 deb http://http.us.debian.org/debian ${DIST} main contrib non-free
78 deb http://security.debian.org/ ${DIST}/updates main contrib non-free
79 EOF
80 (chroot ${ROOT_DIR} aptitude update)
81
82 # set up base system
83 echo "en_US.UTF-8 UTF-8" >${ROOT_DIR}/etc/locale.gen
84 (chroot ${ROOT_DIR} aptitude install -y locales)
85
86 k=$(wget -O- http://queued.mit.edu/~dilinger/builds-master/ | sed -ne 's/.*href="\(.\+\)_i386.deb".*/\1_i386.deb/p' | tail -n1)
87 wget -O ${ROOT_DIR}/${k} http://queued.mit.edu/~dilinger/builds-master/${k}
88 (chroot ${ROOT_DIR} dpkg -i /${k})
89 rm -f ${ROOT_DIR}/${k}
90
91 echo "debxo" > ${ROOT_DIR}/etc/hostname
92 cat >${ROOT_DIR}/etc/hosts<<EOF
93 127.0.0.1 localhost.localdomain localhost
94 127.0.0.1 debxo
95
96 # The following lines are desirable for IPv6 capable hosts
97 ::1     ip6-localhost ip6-loopback
98 fe00::0 ip6-localnet
99 ff00::0 ip6-mcastprefix
100 ff02::1 ip6-allnodes
101 ff02::2 ip6-allrouters
102 ff02::3 ip6-allhosts
103 EOF
104
105 # install packages
106 (chroot ${ROOT_DIR} aptitude install -y `cat package_list`)
107
108 # configure X
109 cat >${ROOT_DIR}/etc/X11/xorg.conf<<EOF
110 # xorg.conf (X.Org X Window System server configuration file)
111
112 Section "Monitor"
113         Identifier "Configured Monitor"
114         HorizSync 30-67
115         VertRefresh 48-52
116         DisplaySize 152 114
117         Mode "1200x900"
118                 DotClock 57.275
119                 HTimings 1200 1208 1216 1240
120                 VTimings 900 905 908 912
121                 Flags "-HSync" "-VSync"
122         EndMode
123 EndSection
124
125 Section "Screen"
126         Identifier "Default Screen"
127         Monitor "Configured Monitor"
128 EndSection
129 EOF
130
131 # configure gdm, gnome
132 sed -i 's_\[daemon\]_\[daemon\]\n\nGreeter=/usr/lib/gdm/gdmlogin\n\nAutomaticLoginEnable=true\n\nAutomaticLogin=olpc_' ${ROOT_DIR}/etc/gdm/gdm.conf
133 cat >${ROOT_DIR}/etc/gconf/2/local-defaults.path<<EOF
134 # DebXO defaults (customized for the XO-1's display
135 xml:readonly:/etc/gconf/debxo.xml.defaults
136 EOF
137 mkdir -p ${ROOT_DIR}/etc/gconf/debxo.xml.defaults
138 cp %gconf-tree.xml ${ROOT_DIR}/etc/gconf/debxo.xml.defaults/
139
140 # add default user
141 (chroot ${ROOT_DIR} passwd -l root)
142 rm -rf ${ROOT_DIR}/home/*;      # i have no idea what's adding this crap...
143 (chroot ${ROOT_DIR} useradd -s /bin/bash --create-home ${DEFUSER})
144 (chroot ${ROOT_DIR} passwd -d ${DEFUSER})
145 (chroot ${ROOT_DIR} adduser ${DEFUSER} cdrom)
146 (chroot ${ROOT_DIR} adduser ${DEFUSER} audio)
147 (chroot ${ROOT_DIR} adduser ${DEFUSER} video)
148 (chroot ${ROOT_DIR} adduser ${DEFUSER} plugdev)
149 (chroot ${ROOT_DIR} adduser ${DEFUSER} netdev)
150 (chroot ${ROOT_DIR} adduser ${DEFUSER} powerdev)
151 echo "${DEFUSER} ALL=(ALL) ALL" >> ${ROOT_DIR}/etc/sudoers
152
153 # done, clean up
154 mv ${ROOT_DIR}/sbin/start-stop-daemon.REAL ${ROOT_DIR}/sbin/start-stop-daemon
155 (chroot ${ROOT_DIR} aptitude clean)
156 umount ${ROOT_DIR}/proc
157 umount ${ROOT_DIR}/dev/pts
158 umount ${ROOT_DIR}/var/cache/apt/cache