]> spindle.queued.net Git - xodist/blob - mkchroot.sh
debxo-sugar: update packages for squeeze
[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 . ./functions.sh
20
21 # load & set default values
22 CONFIG_TYPE=generic
23 . ./configs/${CONFIG_TYPE}/variables
24 . ./configs/${CONFIG_TYPE}/hooks
25 BASE_PLIST="./configs/${CONFIG_TYPE}/packages"
26 LOCAL_APT_MIRROR=
27
28 usage()
29 {
30         echo "" 1>&2
31         echo "Usage: $0 [<options>] <root directory>" 1>&2
32         echo "" 1>&2
33         echo "Options:" 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
37         echo "" 1>&2
38         exit 1
39 }
40
41 while test $# != 0
42 do
43         case $1 in
44         --config-type)
45                 CONFIG_TYPE=$2
46                 [ -d ./configs/${CONFIG_TYPE} ] || {
47                         echo "Error: can't find directory './configs/${CONFIG_TYPE}/'!" 1>&2
48                         exit 2
49                 }
50                 shift
51                 ;;
52         --local-apt-mirror)
53                 LOCAL_APT_MIRROR="$2"
54                 shift
55                 ;;
56         --help|-h)
57                 usage
58                 ;;
59         *)
60                 if [ "$#" != "1" ]; then
61                         echo "Unknown option $1" 1>&2
62                         usage
63                 else
64                         ROOT_DIR="$1"
65                 fi
66                 ;;
67         esac
68         shift
69 done
70
71 if [ "$ROOT_DIR" = "" ]; then
72         echo "" 1>&2
73         echo "*** No root directory specified!" 1>&2
74         usage
75 fi
76
77 if [ -d "${ROOT_DIR}" ]; then
78         echo "" 1>&2
79         echo "*** ${ROOT_DIR} already exists!" 1>&2
80         usage
81 fi
82
83 if [ "$UID" != "0" ]; then
84         echo "" 1>&2
85         echo "*** $0 must be run with root privs!" 1>&2
86         exit 1
87 fi
88
89 # load config-specific values
90 . ./configs/${CONFIG_TYPE}/variables
91 . ./configs/${CONFIG_TYPE}/hooks
92 PLIST="./configs/${CONFIG_TYPE}/packages"
93
94 if [ -z "${LOCAL_APT_MIRROR}" ]; then
95     LOCAL_APT_MIRROR="${APT_SOURCES}"
96 fi
97
98 # parse apt mirror
99 MIRROR=$(printf "${LOCAL_APT_MIRROR}\n" | awk '/deb /{print $2}' | head -n1)
100 DIST=$(printf "${LOCAL_APT_MIRROR}\n" | awk '/deb /{print $3}' | head -n1)
101
102 # create chroot
103 debootstrap --arch ${IMG_ARCH} ${DIST} ${ROOT_DIR} ${MIRROR}
104 mount -t proc proc ${ROOT_DIR}/proc
105 mount -t devpts devpts ${ROOT_DIR}/dev/pts
106
107 # allow daemons to be installed without breaking
108 mv ${ROOT_DIR}/sbin/start-stop-daemon ${ROOT_DIR}/sbin/start-stop-daemon.REAL
109 cat >${ROOT_DIR}/sbin/start-stop-daemon<<EOF
110 #!/bin/sh
111 echo
112 echo "Warning: Fake start-stop-daemon called, doing nothing"
113 EOF
114 chmod 755 ${ROOT_DIR}/sbin/start-stop-daemon
115
116 # set up hostname stuff
117 echo "${IMG_HOSTNAME}" > ${ROOT_DIR}/etc/hostname
118 cat >${ROOT_DIR}/etc/hosts<<EOF
119 127.0.0.1 localhost.localdomain localhost
120 127.0.0.1 ${IMG_HOSTNAME}
121
122 # The following lines are desirable for IPv6 capable hosts
123 ::1     ip6-localhost ip6-loopback
124 fe00::0 ip6-localnet
125 ff00::0 ip6-mcastprefix
126 ff02::1 ip6-allnodes
127 ff02::2 ip6-allrouters
128 ff02::3 ip6-allhosts
129 EOF
130
131 # add local network interface
132 cat >>${ROOT_DIR}/etc/network/interfaces<<EOF
133
134 auto lo
135 iface lo inet loopback
136 EOF
137
138 # set the default locale
139 echo "${IMG_LOCALE}" >${ROOT_DIR}/etc/locale.gen
140
141 # add support for installation onto a block device
142 mkdir -p ${ROOT_DIR}/etc/initramfs-tools/scripts/local-bottom
143 cp installer ${ROOT_DIR}/etc/initramfs-tools/scripts/local-bottom/
144
145 # make sure dpkg doesn't attempt to prompt for input
146 export DEBIAN_FRONTEND=noninteractive
147 export DEBCONF_PRIORITY=critical
148
149 # run any customizations necessary pre-package install
150 customize_chroot_hook "$ROOT_DIR"
151
152 # initialize apt
153 printf "${LOCAL_APT_MIRROR}\n" >${ROOT_DIR}/etc/apt/sources.list
154 (chroot ${ROOT_DIR} aptitude update)
155
156 # generic packages are always installed
157 (chroot ${ROOT_DIR} aptitude install -y `grep --invert-match '^#' ${BASE_PLIST}`)
158
159 # install the rest of the packages
160 (chroot ${ROOT_DIR} aptitude install -y `grep --invert-match '^#' ${PLIST}`)
161
162 # post-install customization hook
163 package_configure_hook "${ROOT_DIR}"
164
165 # add default user
166 (chroot ${ROOT_DIR} passwd -l root)
167 rm -rf ${ROOT_DIR}/home/*;      # i have no idea what's adding this crap...
168 (chroot ${ROOT_DIR} useradd -s /bin/bash --create-home ${DEFUSER})
169 (chroot ${ROOT_DIR} passwd -d ${DEFUSER})
170 (chroot ${ROOT_DIR} adduser ${DEFUSER} cdrom || true)
171 (chroot ${ROOT_DIR} adduser ${DEFUSER} audio || true)
172 (chroot ${ROOT_DIR} adduser ${DEFUSER} video || true)
173 (chroot ${ROOT_DIR} adduser ${DEFUSER} plugdev || true)
174 (chroot ${ROOT_DIR} adduser ${DEFUSER} netdev || true)
175 (chroot ${ROOT_DIR} adduser ${DEFUSER} powerdev || true)
176 (chroot ${ROOT_DIR} adduser ${DEFUSER} floppy || true)
177 (chroot ${ROOT_DIR} adduser ${DEFUSER} fuse || true)
178 echo "${DEFUSER} ALL=(ALL) NOPASSWD: ALL" >> ${ROOT_DIR}/etc/sudoers
179
180 # override sources.list with shipping version
181 printf "${APT_SOURCES}\n" >${ROOT_DIR}/etc/apt/sources.list
182 (chroot ${ROOT_DIR} aptitude update)
183
184 # done, clean up
185 mv ${ROOT_DIR}/sbin/start-stop-daemon.REAL ${ROOT_DIR}/sbin/start-stop-daemon
186 (chroot ${ROOT_DIR} aptitude clean)
187 umount ${ROOT_DIR}/proc
188 umount ${ROOT_DIR}/dev/pts
189
190 # custom cleanup stuff
191 cleanup_chroot_hook "${ROOT_DIR}"
192
193 exit 0