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