]> spindle.queued.net Git - xodist/blob - mkchroot.sh
mkchroot: drop internal_mount functions
[xodist] / mkchroot.sh
1 #!/bin/bash -e
2 #
3 # Copyright © 2008-2009  Andres Salomon <dilinger@collabora.co.uk>
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 start_logging $ROOT_DIR
89
90 check_for_cmds debootstrap || exit 1
91
92 if [ -z "${LOCAL_APT_MIRROR}" ]; then
93     LOCAL_APT_MIRROR="${APT_SOURCES}"
94 fi
95
96 # parse apt mirror
97 MIRROR=$(printf "${LOCAL_APT_MIRROR}\n" | awk '/deb /{print $2}' | head -n1)
98 DIST=$(printf "${LOCAL_APT_MIRROR}\n" | awk '/deb /{print $3}' | head -n1)
99
100 # create chroot
101 debootstrap --arch i386 ${DIST} ${ROOT_DIR} ${MIRROR}
102 mkdir ${ROOT_DIR}/ofw
103 mkdir ${ROOT_DIR}/var/cache/apt/cache
104 mount -t proc proc ${ROOT_DIR}/proc
105 mount -t devpts devpts ${ROOT_DIR}/dev/pts
106 mount -t tmpfs tmpfs ${ROOT_DIR}/var/cache/apt/cache
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 hostname stuff
118 echo "debxo" > ${ROOT_DIR}/etc/hostname
119 cat >${ROOT_DIR}/etc/hosts<<EOF
120 127.0.0.1 localhost.localdomain localhost
121 127.0.0.1 debxo
122
123 # The following lines are desirable for IPv6 capable hosts
124 ::1     ip6-localhost ip6-loopback
125 fe00::0 ip6-localnet
126 ff00::0 ip6-mcastprefix
127 ff02::1 ip6-allnodes
128 ff02::2 ip6-allrouters
129 ff02::3 ip6-allhosts
130 EOF
131
132 # set up apt (working around #314334)
133 export DEBIAN_FRONTEND=noninteractive
134 export DEBCONF_PRIORITY=critical
135 cat >${ROOT_DIR}/etc/apt/apt.conf<<EOF
136 Acquire::Pdiffs "false";
137 APT::Install-Recommends "false";
138 Dir {
139         Cache "var/cache/apt/" {
140                 srcpkgcache "cache/srcpkgcache.bin";
141                 pkgcache "cache/pkgcache.bin";
142         };
143 };
144 EOF
145 printf "${LOCAL_APT_MIRROR}\n" >${ROOT_DIR}/etc/apt/sources.list
146 (chroot ${ROOT_DIR} aptitude update)
147
148 # set up base system and base packages
149 echo "en_US.UTF-8 UTF-8" >${ROOT_DIR}/etc/locale.gen
150 (chroot ${ROOT_DIR} aptitude install -y `cat base.packages`)
151
152 k="http://lunge.mit.edu/~dilinger/debxo-0.2/initramfs-tools_0.92l.2_all.deb 
153  http://lunge.mit.edu/~dilinger/debxo-0.2/ofw-config_0.1_all.deb 
154  http://lunge.mit.edu/~dilinger/debxo-0.4/linux-2.6.25.15_2.6.25.15-165_i386.deb 
155  http://lunge.mit.edu/~dilinger/debxo-0.5/xserver-xorg-video-geode_2.11.0-0.3_i386.deb 
156  http://lunge.mit.edu/~dilinger/debxo-0.5/autox_0.1_all.deb"
157 mkdir -p cache
158 for i in $k; do
159         pkg=$(basename ${i})
160         wget --continue -O cache/${pkg} ${i}
161         cp cache/${pkg} ${ROOT_DIR}/${pkg} 
162         (chroot ${ROOT_DIR} dpkg -i /${pkg})
163         pkgbase=$(echo $pkg | cut -d_ -f1)
164         echo $pkgbase hold | (chroot ${ROOT_DIR} dpkg --set-selections)
165         rm -f ${ROOT_DIR}/${pkg}
166 done
167 # take the geode driver off hold
168 echo xserver-xorg-video-geode install | (chroot ${ROOT_DIR} dpkg --set-selections)
169 # take autox off hold
170 echo autox install | (chroot ${ROOT_DIR} dpkg --set-selections)
171
172 # ensure certain modules get loaded during boot
173 cat >>${ROOT_DIR}/etc/modules<<EOF
174 lxfb
175 fbcon
176 olpc_dcon
177 scx200_acb
178 i8042
179 olpc_battery
180 msr
181 EOF
182
183 # install packages
184 (chroot ${ROOT_DIR} aptitude install -y `grep --invert-match '^#' ${PLIST}`)
185
186 # no longer a need for xorg.conf
187 rm -f ${ROOT_DIR}/etc/X11/xorg.conf
188
189 # key bindings/mappings
190 if [ -d ${ROOT_DIR}/usr/share/hal/fdi/information/10freedesktop/ ]; then
191     cp 30-keymap-olpc.fdi ${ROOT_DIR}/usr/share/hal/fdi/information/10freedesktop/
192 fi
193
194 # configure autox
195 if [ -f ${ROOT_DIR}/etc/default/autox ]; then
196     sed --in-place "s/USER=$/USER=${DEFUSER}/" ${ROOT_DIR}/etc/default/autox
197 fi
198
199 # configure gnome
200 if [ -d ${ROOT_DIR}/etc/gconf/2 ]; then
201     cat >${ROOT_DIR}/etc/gconf/2/local-defaults.path<<EOF
202 # DebXO defaults (customized for the XO-1's display
203 xml:readonly:/etc/gconf/debxo.xml.defaults
204 EOF
205     mkdir -p ${ROOT_DIR}/etc/gconf/debxo.xml.defaults
206     cp %gconf-tree.xml ${ROOT_DIR}/etc/gconf/debxo.xml.defaults/
207 fi
208
209 # add default user
210 (chroot ${ROOT_DIR} passwd -l root)
211 rm -rf ${ROOT_DIR}/home/*;      # i have no idea what's adding this crap...
212 (chroot ${ROOT_DIR} useradd -s /bin/bash --create-home ${DEFUSER})
213 (chroot ${ROOT_DIR} passwd -d ${DEFUSER})
214 (chroot ${ROOT_DIR} adduser ${DEFUSER} cdrom)
215 (chroot ${ROOT_DIR} adduser ${DEFUSER} audio)
216 (chroot ${ROOT_DIR} adduser ${DEFUSER} video)
217 (chroot ${ROOT_DIR} adduser ${DEFUSER} plugdev)
218 (chroot ${ROOT_DIR} adduser ${DEFUSER} netdev)
219 (chroot ${ROOT_DIR} adduser ${DEFUSER} powerdev)
220 (chroot ${ROOT_DIR} adduser ${DEFUSER} floppy)
221 echo "${DEFUSER} ALL=(ALL) NOPASSWD: ALL" >> ${ROOT_DIR}/etc/sudoers
222
223 # add local network interface
224 cat >>${ROOT_DIR}/etc/network/interfaces<<EOF
225
226 auto lo
227 iface lo inet loopback
228 EOF
229
230 # configure sugar
231 if [ -d ${ROOT_DIR}/usr/share/sugar ]; then
232     # #?
233     cat >> ${ROOT_DIR}/home/${DEFUSER}/.Xsession <<- EOF
234 matchbox-window-manager -use_titlebar no &
235 sugar
236 EOF
237 fi
238
239 # run any local postinstall scripts for the build
240 PLIST_DIR=${PLIST/.packages/}
241 if [ -d ${PLIST_DIR} ]; then
242     if [ -x ${PLIST_DIR}/postinst.sh ]; then
243         ${PLIST_DIR}/postinst.sh ${ROOT_DIR}
244     fi
245     if [ -x ${PLIST_DIR}/postinst-local.sh ]; then
246         ${PLIST_DIR}/postinst-local.sh ${ROOT_DIR}
247     fi
248 fi
249
250 # override sources.list with shipping version
251 printf "${APT_SOURCES}\n" >${ROOT_DIR}/etc/apt/sources.list
252 (chroot ${ROOT_DIR} aptitude update)
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 umount ${ROOT_DIR}/proc
258 umount ${ROOT_DIR}/dev/pts
259 umount ${ROOT_DIR}/var/cache/apt/cache