]> spindle.queued.net Git - xodist/blob - initchroot.sh
mkjffs2: add (redboot) partition support
[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                 shift
59                 ;;
60         --mirror)
61                 MIRROR=$2
62                 shift
63                 ;;
64         --othermirror)
65                 OTHERMIRROR=$2
66                 shift
67                 ;;
68         *)
69                 if [ "$#" != "1" ]; then
70                         echo "Unknown option $1" 1>&2
71                         usage
72                 else
73                         ROOT_DIR="$1"
74                 fi
75                 ;;
76         esac
77         shift
78 done
79
80 if [ "$ROOT_DIR" = "" ]; then
81         echo "" 1>&2
82         echo "*** No root directory specified!" 1>&2
83         usage
84 fi
85
86 if [ -d "${ROOT_DIR}" ]; then
87         echo "" 1>&2
88         echo "*** ${ROOT_DIR} already exists!" 1>&2
89         usage
90 fi
91
92 check_for_cmds debootstrap || exit 1
93
94 if [ -z "${OTHERMIRROR}" ]; then
95     OTHERMIRROR="deb http://security.debian.org/ ${DIST}/updates main contrib non-free"
96 fi
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 cat >${ROOT_DIR}/etc/apt/sources.list<<EOF
127 deb ${MIRROR} ${DIST} main contrib non-free
128 ${OTHERMIRROR}
129 EOF
130 (chroot ${ROOT_DIR} aptitude update)
131
132 # set up base system and base packages
133 echo "en_US.UTF-8 UTF-8" >${ROOT_DIR}/etc/locale.gen
134 (chroot ${ROOT_DIR} aptitude install -y `cat base.packages`)
135
136 k="http://lunge.mit.edu/~dilinger/debxo-0.2/initramfs-tools_0.92l.1_all.deb 
137  http://lunge.mit.edu/~dilinger/debxo-0.2/ofw-config_0.1_all.deb 
138  http://lunge.mit.edu/~dilinger/debxo-0.2/linux-2.6.25.15_2.6.25.15-68_i386.deb"
139 mkdir -p cache
140 for i in $k; do
141         pkg=$(basename ${i})
142         wget --continue -O cache/${pkg} ${i}
143         cp cache/${pkg} ${ROOT_DIR}/${pkg} 
144         (chroot ${ROOT_DIR} dpkg -i /${pkg})
145         rm -f ${ROOT_DIR}/${pkg}
146 done
147
148 # ensure certain modules get loaded during boot
149 cat >>${ROOT_DIR}/etc/modules<<EOF
150 lxfb
151 fbcon
152 olpc_dcon
153 scx200_acb
154 i8042
155 EOF
156
157 echo "debxo" > ${ROOT_DIR}/etc/hostname
158 cat >${ROOT_DIR}/etc/hosts<<EOF
159 127.0.0.1 localhost.localdomain localhost
160 127.0.0.1 debxo
161
162 # The following lines are desirable for IPv6 capable hosts
163 ::1     ip6-localhost ip6-loopback
164 fe00::0 ip6-localnet
165 ff00::0 ip6-mcastprefix
166 ff02::1 ip6-allnodes
167 ff02::2 ip6-allrouters
168 ff02::3 ip6-allhosts
169 EOF
170
171 # install packages
172 (chroot ${ROOT_DIR} aptitude install -y `cat ${PLIST}`)
173
174 # configure X
175 if [ -d ${ROOT_DIR}/etc/X11 ]; then
176     cat >${ROOT_DIR}/etc/X11/xorg.conf<<EOF
177 # xorg.conf (X.Org X Window System server configuration file)
178
179 Section "Monitor"
180         Identifier "Configured Monitor"
181         HorizSync 30-67
182         VertRefresh 48-52
183         DisplaySize 152 114
184         Mode "1200x900"
185                 DotClock 57.275
186                 HTimings 1200 1208 1216 1240
187                 VTimings 900 905 908 912
188                 Flags "-HSync" "-VSync"
189         EndMode
190 EndSection
191
192 Section "Screen"
193         Identifier "Default Screen"
194         Monitor "Configured Monitor"
195 EndSection
196 EOF
197 fi
198
199 # configure kdm, kde
200 if [ -d ${ROOT_DIR}/etc/kde3/kdm ]; then
201     sed --in-place "s/AllowNullPasswd=false/AllowNullPasswd=true/;s/#AutoLoginEnable=true/AutoLoginEnable=true/;s/#AutoLoginUser=fred/AutoLoginUser=${DEFUSER}/" ${ROOT_DIR}/etc/kde3/kdm/kdmrc
202 fi
203
204 # configure gdm, gnome
205 if [ -d ${ROOT_DIR}/etc/gdm ]; then
206     sed -i "s_\[daemon\]_\[daemon\]\n\nGreeter=/usr/lib/gdm/gdmlogin\n\nAutomaticLoginEnable=true\n\nAutomaticLogin=${DEFUSER}_" ${ROOT_DIR}/etc/gdm/gdm.conf
207 fi
208 if [ -d ${ROOT_DIR}/etc/gconf/2 ]; then
209     cat >${ROOT_DIR}/etc/gconf/2/local-defaults.path<<EOF
210 # DebXO defaults (customized for the XO-1's display
211 xml:readonly:/etc/gconf/debxo.xml.defaults
212 EOF
213     mkdir -p ${ROOT_DIR}/etc/gconf/debxo.xml.defaults
214     cp %gconf-tree.xml ${ROOT_DIR}/etc/gconf/debxo.xml.defaults/
215 fi
216
217 # add default user
218 (chroot ${ROOT_DIR} passwd -l root)
219 rm -rf ${ROOT_DIR}/home/*;      # i have no idea what's adding this crap...
220 (chroot ${ROOT_DIR} useradd -s /bin/bash --create-home ${DEFUSER})
221 (chroot ${ROOT_DIR} passwd -d ${DEFUSER})
222 (chroot ${ROOT_DIR} adduser ${DEFUSER} cdrom)
223 (chroot ${ROOT_DIR} adduser ${DEFUSER} audio)
224 (chroot ${ROOT_DIR} adduser ${DEFUSER} video)
225 (chroot ${ROOT_DIR} adduser ${DEFUSER} plugdev)
226 (chroot ${ROOT_DIR} adduser ${DEFUSER} netdev)
227 (chroot ${ROOT_DIR} adduser ${DEFUSER} powerdev)
228 (chroot ${ROOT_DIR} adduser ${DEFUSER} floppy)
229 echo "${DEFUSER} ALL=(ALL) NOPASSWD: ALL" >> ${ROOT_DIR}/etc/sudoers
230
231 # done, clean up
232 mv ${ROOT_DIR}/sbin/start-stop-daemon.REAL ${ROOT_DIR}/sbin/start-stop-daemon
233 (chroot ${ROOT_DIR} aptitude clean)
234 chroot_internal_umounts ${ROOT_DIR}