3 # Copyright © 2008-2009 Andres Salomon <dilinger@collabora.co.uk>
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.
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.
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.
21 # load & set default values
23 . ./configs/${CONFIG_TYPE}/variables
24 . ./configs/${CONFIG_TYPE}/hooks
25 BASE_PLIST="./configs/${CONFIG_TYPE}/packages"
31 echo "Usage: $0 [<options>] <root directory>" 1>&2
34 echo " --config-type <config> directory name in configs/ to use" 1>&2
35 echo " --help display this help screen" 1>&2
36 echo " --local-apt-mirror <srcs> sources.list for local mirror" 1>&2
46 [ -d ./configs/${CONFIG_TYPE} ] || {
47 echo "Error: can't find directory './configs/${CONFIG_TYPE}/'!" 1>&2
60 if [ "$#" != "1" ]; then
61 echo "Unknown option $1" 1>&2
71 if [ "$ROOT_DIR" = "" ]; then
73 echo "*** No root directory specified!" 1>&2
77 if [ -d "${ROOT_DIR}" ]; then
79 echo "*** ${ROOT_DIR} already exists!" 1>&2
83 if [ "$UID" != "0" ]; then
85 echo "*** $0 must be run with root privs!" 1>&2
89 start_logging $ROOT_DIR
91 # load config-specific values
92 . ./configs/${CONFIG_TYPE}/variables
93 . ./configs/${CONFIG_TYPE}/hooks
94 PLIST="./configs/${CONFIG_TYPE}/packages"
96 if [ -z "${LOCAL_APT_MIRROR}" ]; then
97 LOCAL_APT_MIRROR="${APT_SOURCES}"
101 MIRROR=$(printf "${LOCAL_APT_MIRROR}\n" | awk '/deb /{print $2}' | head -n1)
102 DIST=$(printf "${LOCAL_APT_MIRROR}\n" | awk '/deb /{print $3}' | head -n1)
105 debootstrap --arch ${IMG_ARCH} ${DIST} ${ROOT_DIR} ${MIRROR}
106 mount -t proc proc ${ROOT_DIR}/proc
107 mount -t devpts devpts ${ROOT_DIR}/dev/pts
109 # allow daemons to be installed without breaking
110 mv ${ROOT_DIR}/sbin/start-stop-daemon ${ROOT_DIR}/sbin/start-stop-daemon.REAL
111 cat >${ROOT_DIR}/sbin/start-stop-daemon<<EOF
114 echo "Warning: Fake start-stop-daemon called, doing nothing"
116 chmod 755 ${ROOT_DIR}/sbin/start-stop-daemon
118 # set up hostname stuff
119 echo "${IMG_HOSTNAME}" > ${ROOT_DIR}/etc/hostname
120 cat >${ROOT_DIR}/etc/hosts<<EOF
121 127.0.0.1 localhost.localdomain localhost
122 127.0.0.1 ${IMG_HOSTNAME}
124 # The following lines are desirable for IPv6 capable hosts
125 ::1 ip6-localhost ip6-loopback
127 ff00::0 ip6-mcastprefix
129 ff02::2 ip6-allrouters
133 # add local network interface
134 cat >>${ROOT_DIR}/etc/network/interfaces<<EOF
137 iface lo inet loopback
140 # set the default locale
141 echo "${IMG_LOCALE}" >${ROOT_DIR}/etc/locale.gen
143 # add support for installation onto a block device
144 mkdir -p ${ROOT_DIR}/etc/initramfs-tools/scripts/local-bottom
145 cp installer ${ROOT_DIR}/etc/initramfs-tools/scripts/local-bottom/
147 # make sure dpkg doesn't attempt to prompt for input
148 export DEBIAN_FRONTEND=noninteractive
149 export DEBCONF_PRIORITY=critical
151 # run any customizations necessary pre-package install
152 customize_chroot_hook "$ROOT_DIR"
155 printf "${LOCAL_APT_MIRROR}\n" >${ROOT_DIR}/etc/apt/sources.list
156 (chroot ${ROOT_DIR} aptitude update)
158 # generic packages are always installed
159 (chroot ${ROOT_DIR} aptitude install -y `grep --invert-match '^#' ${BASE_PLIST}`)
161 # install the rest of the packages
162 (chroot ${ROOT_DIR} aptitude install -y `grep --invert-match '^#' ${PLIST}`)
164 # post-install customization hook
165 package_configure_hook "${ROOT_DIR}"
168 (chroot ${ROOT_DIR} passwd -l root)
169 rm -rf ${ROOT_DIR}/home/*; # i have no idea what's adding this crap...
170 (chroot ${ROOT_DIR} useradd -s /bin/bash --create-home ${DEFUSER})
171 (chroot ${ROOT_DIR} passwd -d ${DEFUSER})
172 (chroot ${ROOT_DIR} adduser ${DEFUSER} cdrom)
173 (chroot ${ROOT_DIR} adduser ${DEFUSER} audio)
174 (chroot ${ROOT_DIR} adduser ${DEFUSER} video)
175 (chroot ${ROOT_DIR} adduser ${DEFUSER} plugdev)
176 (chroot ${ROOT_DIR} adduser ${DEFUSER} netdev)
177 (chroot ${ROOT_DIR} adduser ${DEFUSER} powerdev)
178 (chroot ${ROOT_DIR} adduser ${DEFUSER} floppy)
179 echo "${DEFUSER} ALL=(ALL) NOPASSWD: ALL" >> ${ROOT_DIR}/etc/sudoers
181 # override sources.list with shipping version
182 printf "${APT_SOURCES}\n" >${ROOT_DIR}/etc/apt/sources.list
183 (chroot ${ROOT_DIR} aptitude update)
186 mv ${ROOT_DIR}/sbin/start-stop-daemon.REAL ${ROOT_DIR}/sbin/start-stop-daemon
187 (chroot ${ROOT_DIR} aptitude clean)
188 umount ${ROOT_DIR}/proc
189 umount ${ROOT_DIR}/dev/pts
191 # custom cleanup stuff
192 cleanup_chroot_hook "${ROOT_DIR}"