]> spindle.queued.net Git - xodist/blob - initchroot.sh
release: FAIL
[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 PLIST=gnome.packages
22 MIRROR=http://http.us.debian.org/debian/
23 OTHERMIRROR=
24
25 . functions.sh
26
27 usage()
28 {
29         echo "" 1>&2
30         echo "Usage: $0 [<options>] <root directory>" 1>&2
31         echo "" 1>&2
32         echo "Options:" 1>&2
33         echo "  --distribution <name>     Which distribution to use" 1>&2
34         echo "  --user <user>             Username for default user" 1>&2
35         echo "  --package-list <list>     File containing package list" 1>&2
36         echo "  --mirror <url>            Main Mirror URL prefix" 1>&2
37         echo "  --othermirror <line>      An additional sources.list line" 1>&2
38         echo "" 1>&2
39         exit 1
40 }
41
42 while test $# != 0
43 do
44         case $1 in
45         --distribution)
46                 DIST=$2
47                 shift
48                 if [ -z "${OTHERMIRROR}" ]; then
49                     OTHERMIRROR="deb http://security.debian.org/ ${DIST}/updates main contrib non-free"
50                 fi
51                 ;;
52         --user)
53                 DEFUSER=$2
54                 shift
55                 ;;
56         --package-list)
57                 PLIST=$2
58                 [ -f ${PLIST} ] || {
59                         echo "Error: can't find file '${PLIST}'!" 1>&2
60                         exit 2
61                 }
62                 shift
63                 ;;
64         --mirror)
65                 MIRROR=$2
66                 shift
67                 ;;
68         --othermirror)
69                 OTHERMIRROR=$2
70                 shift
71                 ;;
72         *)
73                 if [ "$#" != "1" ]; then
74                         echo "Unknown option $1" 1>&2
75                         usage
76                 else
77                         ROOT_DIR="$1"
78                 fi
79                 ;;
80         esac
81         shift
82 done
83
84 if [ "$ROOT_DIR" = "" ]; then
85         echo "" 1>&2
86         echo "*** No root directory specified!" 1>&2
87         usage
88 fi
89
90 if [ -d "${ROOT_DIR}" ]; then
91         echo "" 1>&2
92         echo "*** ${ROOT_DIR} already exists!" 1>&2
93         usage
94 fi
95
96 check_for_cmds debootstrap || exit 1
97
98 if [ -z "${OTHERMIRROR}" ]; then
99     OTHERMIRROR="deb http://security.debian.org/ ${DIST}/updates main contrib non-free"
100 fi
101
102 # create chroot
103 debootstrap --arch i386 ${DIST} ${ROOT_DIR} ${MIRROR}
104 mkdir ${ROOT_DIR}/ofw
105 mkdir ${ROOT_DIR}/var/cache/apt/cache
106 chroot_internal_mounts ${ROOT_DIR}
107
108 # allow daemons to be installed without breaking
109 mv ${ROOT_DIR}/sbin/start-stop-daemon ${ROOT_DIR}/sbin/start-stop-daemon.REAL
110 cat >${ROOT_DIR}/sbin/start-stop-daemon<<EOF
111 #!/bin/sh
112 echo
113 echo "Warning: Fake start-stop-daemon called, doing nothing"
114 EOF
115 chmod 755 ${ROOT_DIR}/sbin/start-stop-daemon
116
117 # set up apt (working around #314334)
118 export DEBIAN_FRONTEND=noninteractive
119 export DEBCONF_PRIORITY=critical
120 cat >${ROOT_DIR}/etc/apt/apt.conf<<EOF
121 Acquire::Pdiffs "false";
122 APT::Install-Recommends "false";
123 Dir {
124         Cache "var/cache/apt/" {
125                 srcpkgcache "cache/srcpkgcache.bin";
126                 pkgcache "cache/pkgcache.bin";
127         };
128 };
129 EOF
130 cat >${ROOT_DIR}/etc/apt/sources.list<<EOF
131 deb ${MIRROR} ${DIST} main contrib non-free
132 ${OTHERMIRROR}
133 EOF
134 (chroot ${ROOT_DIR} aptitude update)
135
136 # set up base system and base packages
137 echo "en_US.UTF-8 UTF-8" >${ROOT_DIR}/etc/locale.gen
138 (chroot ${ROOT_DIR} aptitude install -y `cat base.packages`)
139
140 k="http://lunge.mit.edu/~dilinger/debxo-0.2/initramfs-tools_0.92l.2_all.deb 
141  http://lunge.mit.edu/~dilinger/debxo-0.2/ofw-config_0.1_all.deb 
142  http://lunge.mit.edu/~dilinger/debxo-0.3/linux-2.6.25.15_2.6.25.15-147_i386.deb"
143 mkdir -p cache
144 for i in $k; do
145         pkg=$(basename ${i})
146         wget --continue -O cache/${pkg} ${i}
147         cp cache/${pkg} ${ROOT_DIR}/${pkg} 
148         (chroot ${ROOT_DIR} dpkg -i /${pkg})
149         pkgbase=$(echo $pkg | cut -d_ -f1)
150         echo $pkgbase hold | (chroot ${ROOT_DIR} dpkg --set-selections)
151         rm -f ${ROOT_DIR}/${pkg}
152 done
153
154 # ensure certain modules get loaded during boot
155 cat >>${ROOT_DIR}/etc/modules<<EOF
156 lxfb
157 fbcon
158 olpc_dcon
159 scx200_acb
160 i8042
161 EOF
162
163 echo "debxo" > ${ROOT_DIR}/etc/hostname
164 cat >${ROOT_DIR}/etc/hosts<<EOF
165 127.0.0.1 localhost.localdomain localhost
166 127.0.0.1 debxo
167
168 # The following lines are desirable for IPv6 capable hosts
169 ::1     ip6-localhost ip6-loopback
170 fe00::0 ip6-localnet
171 ff00::0 ip6-mcastprefix
172 ff02::1 ip6-allnodes
173 ff02::2 ip6-allrouters
174 ff02::3 ip6-allhosts
175 EOF
176
177 # install packages
178 (chroot ${ROOT_DIR} aptitude install -y `cat ${PLIST}`)
179
180 # configure X
181 if [ -d ${ROOT_DIR}/etc/X11 ]; then
182     cat >${ROOT_DIR}/etc/X11/xorg.conf<<EOF
183 # xorg.conf (X.Org X Window System server configuration file)
184
185 Section "Monitor"
186         Identifier "Configured Monitor"
187         HorizSync 30-67
188         VertRefresh 48-52
189         DisplaySize 152 114
190         Mode "1200x900"
191                 DotClock 57.275
192                 HTimings 1200 1208 1216 1240
193                 VTimings 900 905 908 912
194                 Flags "-HSync" "-VSync"
195         EndMode
196 EndSection
197
198 Section "Screen"
199         Identifier "Default Screen"
200         Monitor "Configured Monitor"
201 EndSection
202 EOF
203 fi
204
205 # configure kdm, kde
206 if [ -d ${ROOT_DIR}/etc/kde3/kdm ]; then
207     sed --in-place "s/AllowNullPasswd=false/AllowNullPasswd=true/;s/#AutoLoginEnable=true/AutoLoginEnable=true/;s/#AutoLoginUser=fred/AutoLoginUser=${DEFUSER}/" ${ROOT_DIR}/etc/kde3/kdm/kdmrc
208 fi
209
210 # configure gdm, gnome
211 if [ -d ${ROOT_DIR}/etc/gdm ]; then
212     sed -i "s_\[daemon\]_\[daemon\]\n\nGreeter=/usr/lib/gdm/gdmlogin\n\nAutomaticLoginEnable=true\n\nAutomaticLogin=${DEFUSER}_" ${ROOT_DIR}/etc/gdm/gdm.conf
213 fi
214 if [ -d ${ROOT_DIR}/etc/gconf/2 ]; then
215     cat >${ROOT_DIR}/etc/gconf/2/local-defaults.path<<EOF
216 # DebXO defaults (customized for the XO-1's display
217 xml:readonly:/etc/gconf/debxo.xml.defaults
218 EOF
219     mkdir -p ${ROOT_DIR}/etc/gconf/debxo.xml.defaults
220     cp %gconf-tree.xml ${ROOT_DIR}/etc/gconf/debxo.xml.defaults/
221 fi
222
223 # add default user
224 (chroot ${ROOT_DIR} passwd -l root)
225 rm -rf ${ROOT_DIR}/home/*;      # i have no idea what's adding this crap...
226 (chroot ${ROOT_DIR} useradd -s /bin/bash --create-home ${DEFUSER})
227 (chroot ${ROOT_DIR} passwd -d ${DEFUSER})
228 (chroot ${ROOT_DIR} adduser ${DEFUSER} cdrom)
229 (chroot ${ROOT_DIR} adduser ${DEFUSER} audio)
230 (chroot ${ROOT_DIR} adduser ${DEFUSER} video)
231 (chroot ${ROOT_DIR} adduser ${DEFUSER} plugdev)
232 (chroot ${ROOT_DIR} adduser ${DEFUSER} netdev)
233 (chroot ${ROOT_DIR} adduser ${DEFUSER} powerdev)
234 (chroot ${ROOT_DIR} adduser ${DEFUSER} floppy)
235 echo "${DEFUSER} ALL=(ALL) NOPASSWD: ALL" >> ${ROOT_DIR}/etc/sudoers
236
237 # add local network interface
238 cat >>${ROOT_DIR}/etc/network/interfaces<<EOF
239
240 auto lo
241 iface lo inet loopback
242 EOF
243
244 # configure sugar
245 if [ -d ${ROOT_DIR}/usr/share/sugar ]; then
246     # #?
247     ln -sf /usr/share/activities/ ${ROOT_DIR}/usr/share/sugar
248     cat >> ${ROOT_DIR}/home/${DEFUSER}/.Xsession <<- EOF
249 matchbox-window-manager -use_titlebar no &
250 sugar
251 EOF
252 fi
253
254 # done, clean up
255 mv ${ROOT_DIR}/sbin/start-stop-daemon.REAL ${ROOT_DIR}/sbin/start-stop-daemon
256 (chroot ${ROOT_DIR} aptitude clean)
257 chroot_internal_umounts ${ROOT_DIR}