Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / installer / linux / sysroot_scripts / sysroot-creator-debian.wheezy.sh
blob530865a1c111d8b00edac4d5ac7f521e01311e3c
1 #!/bin/sh
3 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
7 #@ This script builds a Debian Wheezy sysroot for building Google Chrome.
8 #@
9 #@ Generally this script is invoked as:
10 #@ sysroot-creator-debian.wheezy.sh <mode> <args>*
11 #@ Available modes are shown below.
13 #@ List of modes:
15 ######################################################################
16 # Config
17 ######################################################################
19 set -o nounset
20 set -o errexit
22 readonly SCRIPT_DIR=$(dirname $0)
24 # This is where the staging sysroot is.
25 readonly INSTALL_ROOT_AMD64=$(pwd)/debian_wheezy_amd64_staging
26 readonly INSTALL_ROOT_I386=$(pwd)/debian_wheezy_i386_staging
28 readonly REQUIRED_TOOLS="wget"
30 ######################################################################
31 # Package Config
32 ######################################################################
34 # this is where we get all the debian packages from
35 readonly DEBIAN_REPO=http://http.us.debian.org/debian
36 readonly REPO_BASEDIR="${DEBIAN_REPO}/dists/wheezy"
38 readonly RELEASE_FILE="Release"
39 readonly RELEASE_FILE_GPG="Release.gpg"
40 readonly RELEASE_LIST="${REPO_BASEDIR}/${RELEASE_FILE}"
41 readonly RELEASE_LIST_GPG="${REPO_BASEDIR}/${RELEASE_FILE_GPG}"
42 readonly PACKAGE_FILE_AMD64="main/binary-amd64/Packages.bz2"
43 readonly PACKAGE_FILE_I386="main/binary-i386/Packages.bz2"
44 readonly PACKAGE_LIST_AMD64="${REPO_BASEDIR}/${PACKAGE_FILE_AMD64}"
45 readonly PACKAGE_LIST_I386="${REPO_BASEDIR}/${PACKAGE_FILE_I386}"
47 # Sysroot packages: these are the packages needed to build chrome.
48 # NOTE: When DEBIAN_PACKAGES is modified, the packagelist files must be updated
49 # by running this script in GeneratePackageList mode.
50 readonly DEBIAN_PACKAGES="\
51 comerr-dev \
52 gcc-4.6 \
53 krb5-multidev \
54 libasound2 \
55 libasound2-dev \
56 libatk1.0-0 \
57 libatk1.0-dev \
58 libavahi-client3 \
59 libavahi-common3 \
60 libc6 \
61 libc6-dev \
62 libcairo2 \
63 libcairo2-dev \
64 libcairo-gobject2 \
65 libcairo-script-interpreter2 \
66 libcap-dev \
67 libcap2 \
68 libcomerr2 \
69 libcups2 \
70 libcups2-dev \
71 libdbus-1-3 \
72 libdbus-1-dev \
73 libdbus-glib-1-2 \
74 libelf1 \
75 libelf-dev \
76 libexpat1 \
77 libexpat1-dev \
78 libffi5 \
79 libfontconfig1 \
80 libfontconfig1-dev \
81 libfreetype6 \
82 libfreetype6-dev \
83 libgcc1 \
84 libgcc1 \
85 libgconf-2-4 \
86 libgconf2-4 \
87 libgconf2-dev \
88 libgcrypt11 \
89 libgcrypt11-dev \
90 libgdk-pixbuf2.0-0 \
91 libgdk-pixbuf2.0-dev \
92 libglib2.0-0 \
93 libglib2.0-dev \
94 libgnome-keyring0 \
95 libgnome-keyring-dev \
96 libgnutls26 \
97 libgnutls-dev \
98 libgnutls-openssl27 \
99 libgnutlsxx27 \
100 libgomp1 \
101 libgpg-error0 \
102 libgpg-error-dev \
103 libgssapi-krb5-2 \
104 libgssrpc4 \
105 libgtk2.0-0 \
106 libgtk2.0-dev \
107 libk5crypto3 \
108 libkadm5clnt-mit8 \
109 libkadm5srv-mit8 \
110 libkdb5-6 \
111 libkeyutils1 \
112 libkrb5-3 \
113 libkrb5-dev \
114 libkrb5support0 \
115 libnspr4 \
116 libnspr4-dev \
117 libnss3 \
118 libnss3-dev \
119 libnss-db \
120 liborbit2 \
121 libp11-2 \
122 libp11-kit0 \
123 libpam0g \
124 libpam0g-dev \
125 libpango1.0-0 \
126 libpango1.0-dev \
127 libpci3 \
128 libpci-dev \
129 libpcre3 \
130 libpcre3-dev \
131 libpcrecpp0 \
132 libpixman-1-0 \
133 libpixman-1-dev \
134 libpng12-0 \
135 libpng12-dev \
136 libpulse0 \
137 libpulse-dev \
138 libpulse-mainloop-glib0 \
139 libquadmath0 \
140 libselinux1 \
141 libspeechd2 \
142 libspeechd-dev \
143 libssl1.0.0 \
144 libssl-dev \
145 libstdc++6 \
146 libstdc++6-4.6-dev \
147 libtasn1-3 \
148 libudev0 \
149 libudev-dev \
150 libx11-6 \
151 libx11-dev \
152 libxau6 \
153 libxau-dev \
154 libxcb1 \
155 libxcb1-dev \
156 libxcb-render0 \
157 libxcb-render0-dev \
158 libxcb-shm0 \
159 libxcb-shm0-dev \
160 libxcomposite1 \
161 libxcomposite-dev \
162 libxcursor1 \
163 libxcursor-dev \
164 libxdamage1 \
165 libxdamage-dev \
166 libxdmcp6 \
167 libxext6 \
168 libxext-dev \
169 libxfixes3 \
170 libxfixes-dev \
171 libxi6 \
172 libxi-dev \
173 libxinerama1 \
174 libxinerama-dev \
175 libxrandr2 \
176 libxrandr-dev \
177 libxrender1 \
178 libxrender-dev \
179 libxss1 \
180 libxss-dev \
181 libxt6 \
182 libxt-dev \
183 libxtst6 \
184 libxtst-dev \
185 linux-libc-dev \
186 speech-dispatcher \
187 x11proto-composite-dev \
188 x11proto-core-dev \
189 x11proto-damage-dev \
190 x11proto-fixes-dev \
191 x11proto-input-dev \
192 x11proto-kb-dev \
193 x11proto-randr-dev \
194 x11proto-record-dev \
195 x11proto-render-dev \
196 x11proto-scrnsaver-dev \
197 x11proto-xext-dev \
198 zlib1g \
199 zlib1g-dev"
201 readonly DEBIAN_DEP_LIST_AMD64="${SCRIPT_DIR}/packagelist.debian.wheezy.amd64"
202 readonly DEBIAN_DEP_LIST_I386="${SCRIPT_DIR}/packagelist.debian.wheezy.i386"
203 readonly DEBIAN_DEP_FILES_AMD64="$(cat ${DEBIAN_DEP_LIST_AMD64})"
204 readonly DEBIAN_DEP_FILES_I386="$(cat ${DEBIAN_DEP_LIST_I386})"
206 ######################################################################
207 # Helper
208 ######################################################################
210 Banner() {
211 echo "######################################################################"
212 echo $*
213 echo "######################################################################"
217 SubBanner() {
218 echo "......................................................................"
219 echo $*
220 echo "......................................................................"
224 Usage() {
225 egrep "^#@" "$0" | cut --bytes=3-
229 DownloadOrCopy() {
230 if [ -f "$2" ] ; then
231 echo "$2 already in place"
232 return
235 HTTP=0
236 echo "$1" | grep -qs ^http:// && HTTP=1
237 if [ "$HTTP" = "1" ]; then
238 SubBanner "downloading from $1 -> $2"
239 wget "$1" -O "$2"
240 else
241 SubBanner "copying from $1"
242 cp "$1" "$2"
247 SetEnvironmentVariables() {
248 ARCH=""
249 echo $1 | grep -qs Amd64$ && ARCH=AMD64
250 if [ -z "$ARCH" ]; then
251 echo $1 | grep -qs I386$ && ARCH=I386
253 case "$ARCH" in
254 AMD64)
255 INSTALL_ROOT="$INSTALL_ROOT_AMD64";
257 I386)
258 INSTALL_ROOT="$INSTALL_ROOT_I386";
261 echo "ERROR: Unexpected bad architecture."
262 exit 1
264 esac
267 Cleanup() {
268 rm -rf "$TMP"
271 # some sanity checks to make sure this script is run from the right place
272 # with the right tools
273 SanityCheck() {
274 Banner "Sanity Checks"
276 if [ "$(basename $(pwd))" != "sysroot_scripts" ] ; then
277 echo -n "ERROR: run this script from "
278 echo "src/chrome/installer/linux/sysroot_scripts"
279 exit 1
282 if ! mkdir -p "${INSTALL_ROOT}" ; then
283 echo "ERROR: ${INSTALL_ROOT} can't be created."
284 exit 1
287 TMP=$(mktemp -q -t -d debian-wheezy-XXXXXX)
288 if [ -z "$TMP" ]; then
289 echo "ERROR: temp dir can't be created."
290 exit 1
292 trap Cleanup 0
294 for tool in ${REQUIRED_TOOLS} ; do
295 if ! which ${tool} ; then
296 echo "Required binary $tool not found."
297 echo "Exiting."
298 exit 1
300 done
304 ChangeDirectory() {
305 # Change directory to where this script is.
306 cd $(dirname "$0")
310 ClearInstallDir() {
311 Banner "clearing dirs in ${INSTALL_ROOT}"
312 rm -rf ${INSTALL_ROOT}/*
316 CreateTarBall() {
317 local tarball=$1
318 Banner "creating tar ball ${tarball}"
319 tar zcf ${tarball} -C ${INSTALL_ROOT} .
322 ######################################################################
324 ######################################################################
326 HacksAndPatchesAmd64() {
327 Banner "Misc Hacks & Patches"
328 # these are linker scripts with absolute pathnames in them
329 # which we rewrite here
330 lscripts="${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libpthread.so \
331 ${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libc.so"
333 #SubBanner "Rewriting Linker Scripts"
334 sed -i -e 's|/usr/lib/x86_64-linux-gnu/||g' ${lscripts}
335 sed -i -e 's|/lib/x86_64-linux-gnu/||g' ${lscripts}
337 # This is for chrome's ./build/linux/pkg-config-wrapper
338 # which overwrites PKG_CONFIG_PATH internally
339 SubBanner "Package Configs Symlink"
340 mkdir -p ${INSTALL_ROOT}/usr/share
341 ln -s ../lib/x86_64-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
343 SubBanner "Adding an additional ld.conf include"
344 LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
345 echo /usr/lib/gcc/x86_64-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
346 echo /usr/lib >> "$LD_SO_HACK_CONF"
350 HacksAndPatchesI386() {
351 Banner "Misc Hacks & Patches"
352 # these are linker scripts with absolute pathnames in them
353 # which we rewrite here
354 lscripts="${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libpthread.so \
355 ${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libc.so"
357 #SubBanner "Rewriting Linker Scripts"
358 sed -i -e 's|/usr/lib/i386-linux-gnu/||g' ${lscripts}
359 sed -i -e 's|/lib/i386-linux-gnu/||g' ${lscripts}
361 # This is for chrome's ./build/linux/pkg-config-wrapper
362 # which overwrites PKG_CONFIG_PATH internally
363 SubBanner "Package Configs Symlink"
364 mkdir -p ${INSTALL_ROOT}/usr/share
365 ln -s ../lib/i386-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
367 SubBanner "Adding an additional ld.conf include"
368 LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
369 echo /usr/lib/gcc/i486-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
370 echo /usr/lib >> "$LD_SO_HACK_CONF"
374 InstallIntoSysroot() {
375 Banner "Install Libs And Headers Into Jail"
377 mkdir -p ${TMP}/debian-packages
378 mkdir -p ${INSTALL_ROOT}
379 for file in $@ ; do
380 local package="${TMP}/debian-packages/${file##*/}"
381 Banner "installing ${file}"
382 DownloadOrCopy ${DEBIAN_REPO}/pool/${file} ${package}
383 SubBanner "extracting to ${INSTALL_ROOT}"
384 if [ ! -s "${package}" ] ; then
385 echo
386 echo "ERROR: bad package ${package}"
387 exit 1
389 dpkg --fsys-tarfile ${package}\
390 | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT}
391 done
395 CleanupJailSymlinks() {
396 Banner "jail symlink cleanup"
398 SAVEDPWD=$(pwd)
399 cd ${INSTALL_ROOT}
400 find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
401 # skip links with non-absolute paths
402 echo "${target}" | grep -qs ^/ || continue
403 echo "${link}: ${target}"
404 case "${link}" in
405 usr/lib/gcc/x86_64-linux-gnu/4.*/* | usr/lib/gcc/i486-linux-gnu/4.*/*)
406 # Relativize the symlink.
407 ln -snfv "../../../../..${target}" "${link}"
409 usr/lib/x86_64-linux-gnu/* | usr/lib/i386-linux-gnu/*)
410 # Relativize the symlink.
411 ln -snfv "../../..${target}" "${link}"
413 usr/lib/*)
414 # Relativize the symlink.
415 ln -snfv "../..${target}" "${link}"
417 lib64/* | lib/*)
418 # Relativize the symlink.
419 ln -snfv "..${target}" "${link}"
421 esac
422 done
424 find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
425 # Make sure we catch new bad links.
426 if [ ! -r "${link}" ]; then
427 echo "ERROR: FOUND BAD LINK ${link}"
428 ls -l ${link}
429 exit 1
431 done
432 cd "$SAVEDPWD"
436 #@ BuildSysrootAmd64 <tarball-name>
438 #@ Build everything and package it
439 BuildSysrootAmd64() {
440 ClearInstallDir
441 InstallIntoSysroot ${DEBIAN_DEP_FILES_AMD64}
442 CleanupJailSymlinks
443 HacksAndPatchesAmd64
444 CreateTarBall $1
448 #@ BuildSysrootI386 <tarball-name>
450 #@ Build everything and package it
451 BuildSysrootI386() {
452 ClearInstallDir
453 InstallIntoSysroot ${DEBIAN_DEP_FILES_I386}
454 CleanupJailSymlinks
455 HacksAndPatchesI386
456 CreateTarBall $1
460 # CheckForDebianGPGKeys
462 # Make sure the Debian GPG keys exist. Otherwise print a helpful message.
464 CheckForDebianGPGKeys() {
465 if [ ! -e "/etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg" ] ||
466 [ ! -e "/etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg" ]; then
467 echo "Debian GPG keys missing. Install the debian-archive-keyring package."
468 exit 1
473 # VerifyPackageListing
475 # Verifies the downloaded Packages.bz2 file has the right checksums.
477 VerifyPackageListing() {
478 local file_path=$1
479 local output_file=$2
480 local release_file="${TMP}/${RELEASE_FILE}"
481 local release_file_gpg="${TMP}/${RELEASE_FILE_GPG}"
483 CheckForDebianGPGKeys
485 DownloadOrCopy ${RELEASE_LIST} ${release_file}
486 DownloadOrCopy ${RELEASE_LIST_GPG} ${release_file_gpg}
487 echo "Verifying: ${release_file} with ${release_file_gpg}"
488 gpgv --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg \
489 --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg \
490 ${release_file_gpg} ${release_file}
492 echo "Verifying: ${output_file}"
493 local checksums=$(grep ${file_path} ${release_file} | cut -d " " -f 2)
494 local md5sum=$(echo ${checksums} | cut -d " " -f 1)
495 local sha1sum=$(echo ${checksums} | cut -d " " -f 2)
496 local sha256sum=$(echo ${checksums} | cut -d " " -f 3)
498 if [ "${#md5sum}" -ne "32" ]; then
499 echo "Bad md5sum from ${RELEASE_LIST}"
500 exit 1
502 if [ "${#sha1sum}" -ne "40" ]; then
503 echo "Bad sha1sum from ${RELEASE_LIST}"
504 exit 1
506 if [ "${#sha256sum}" -ne "64" ]; then
507 echo "Bad sha256sum from ${RELEASE_LIST}"
508 exit 1
511 echo "${md5sum} ${output_file}" | md5sum --quiet -c
512 echo "${sha1sum} ${output_file}" | sha1sum --quiet -c
513 echo "${sha256sum} ${output_file}" | sha256sum --quiet -c
517 # GeneratePackageList
519 # Looks up package names in ${TMP}/Packages and write list of URLs
520 # to output file.
522 GeneratePackageList() {
523 local output_file=$1
524 echo "Updating: ${output_file}"
525 /bin/rm -f ${output_file}
526 shift
527 for pkg in $@ ; do
528 local pkg_full=$(grep -A 1 " ${pkg}\$" ${TMP}/Packages | egrep -o "pool/.*")
529 if [ -z "${pkg_full}" ]; then
530 echo "ERROR: missing package: $pkg"
531 exit 1
533 echo $pkg_full | sed "s/^pool\///" >> $output_file
534 done
535 # sort -o does an in-place sort of this file
536 sort $output_file -o $output_file
540 #@ UpdatePackageListsAmd64
542 #@ Regenerate the package lists such that they contain an up-to-date
543 #@ list of URLs within the Debian archive. (For amd64)
544 UpdatePackageListsAmd64() {
545 local package_list="${TMP}/Packages.wheezy_amd64.bz2"
546 DownloadOrCopy ${PACKAGE_LIST_AMD64} ${package_list}
547 VerifyPackageListing ${PACKAGE_FILE_AMD64} ${package_list}
548 bzcat ${package_list} | egrep '^(Package:|Filename:)' > ${TMP}/Packages
550 GeneratePackageList ${DEBIAN_DEP_LIST_AMD64} "${DEBIAN_PACKAGES}"
554 #@ UpdatePackageListsI386
556 #@ Regenerate the package lists such that they contain an up-to-date
557 #@ list of URLs within the Debian archive. (For i386)
558 UpdatePackageListsI386() {
559 local package_list="${TMP}/Packages.wheezy_i386.bz2"
560 DownloadOrCopy ${PACKAGE_LIST_I386} ${package_list}
561 VerifyPackageListing ${PACKAGE_FILE_I386} ${package_list}
562 bzcat ${package_list} | egrep '^(Package:|Filename:)' > ${TMP}/Packages
564 GeneratePackageList ${DEBIAN_DEP_LIST_I386} "${DEBIAN_PACKAGES}"
567 if [ $# -eq 0 ] ; then
568 echo "ERROR: you must specify a mode on the commandline"
569 echo
570 Usage
571 exit 1
572 elif [ "$(type -t $1)" != "function" ]; then
573 echo "ERROR: unknown function '$1'." >&2
574 echo "For help, try:"
575 echo " $0 help"
576 exit 1
577 else
578 ChangeDirectory
579 SetEnvironmentVariables "$1"
580 SanityCheck
581 "$@"