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.
9 #@ Generally this script is invoked as:
10 #@ sysroot-creator-debian.wheezy.sh <mode> <args>*
11 #@ Available modes are shown below.
15 ######################################################################
17 ######################################################################
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 ######################################################################
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
="\
65 libcairo-script-interpreter2 \
91 libgdk-pixbuf2.0-dev \
95 libgnome-keyring-dev \
138 libpulse-mainloop-glib0 \
187 x11proto-composite-dev \
189 x11proto-damage-dev \
194 x11proto-record-dev \
195 x11proto-render-dev \
196 x11proto-scrnsaver-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 ######################################################################
208 ######################################################################
211 echo "######################################################################"
213 echo "######################################################################"
218 echo "......................................................................"
220 echo "......................................................................"
225 egrep "^#@" "$0" | cut
--bytes=3-
230 if [ -f "$2" ] ; then
231 echo "$2 already in place"
236 echo "$1" |
grep -qs ^http
:// && HTTP
=1
237 if [ "$HTTP" = "1" ]; then
238 SubBanner
"downloading from $1 -> $2"
241 SubBanner
"copying from $1"
247 SetEnvironmentVariables
() {
249 echo $1 |
grep -qs Amd64$
&& ARCH
=AMD64
250 if [ -z "$ARCH" ]; then
251 echo $1 |
grep -qs I386$
&& ARCH
=I386
255 INSTALL_ROOT
="$INSTALL_ROOT_AMD64";
258 INSTALL_ROOT
="$INSTALL_ROOT_I386";
261 echo "ERROR: Unexpected bad architecture."
271 # some sanity checks to make sure this script is run from the right place
272 # with the right tools
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"
282 if ! mkdir
-p "${INSTALL_ROOT}" ; then
283 echo "ERROR: ${INSTALL_ROOT} can't be created."
287 TMP
=$
(mktemp
-q -t -d debian-wheezy-XXXXXX
)
288 if [ -z "$TMP" ]; then
289 echo "ERROR: temp dir can't be created."
294 for tool
in ${REQUIRED_TOOLS} ; do
295 if ! which ${tool} ; then
296 echo "Required binary $tool not found."
305 # Change directory to where this script is.
311 Banner
"clearing dirs in ${INSTALL_ROOT}"
312 rm -rf ${INSTALL_ROOT}/*
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}
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
386 echo "ERROR: bad package ${package}"
389 dpkg
--fsys-tarfile ${package}\
390 |
tar -xvf - --exclude=.
/usr
/share
-C ${INSTALL_ROOT}
395 CleanupJailSymlinks
() {
396 Banner
"jail symlink cleanup"
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}"
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}"
414 # Relativize the symlink.
415 ln -snfv "../..${target}" "${link}"
418 # Relativize the symlink.
419 ln -snfv "..${target}" "${link}"
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}"
436 #@ BuildSysrootAmd64 <tarball-name>
438 #@ Build everything and package it
439 BuildSysrootAmd64
() {
441 InstallIntoSysroot
${DEBIAN_DEP_FILES_AMD64}
448 #@ BuildSysrootI386 <tarball-name>
450 #@ Build everything and package it
453 InstallIntoSysroot
${DEBIAN_DEP_FILES_I386}
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."
473 # VerifyPackageListing
475 # Verifies the downloaded Packages.bz2 file has the right checksums.
477 VerifyPackageListing
() {
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}"
502 if [ "${#sha1sum}" -ne "40" ]; then
503 echo "Bad sha1sum from ${RELEASE_LIST}"
506 if [ "${#sha256sum}" -ne "64" ]; then
507 echo "Bad sha256sum from ${RELEASE_LIST}"
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
522 GeneratePackageList
() {
524 echo "Updating: ${output_file}"
525 /bin
/rm -f ${output_file}
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"
533 echo $pkg_full |
sed "s/^pool\///" >> $output_file
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"
572 elif [ "$(type -t $1)" != "function" ]; then
573 echo "ERROR: unknown function '$1'." >&2
574 echo "For help, try:"
579 SetEnvironmentVariables
"$1"