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 \
94 libgdk-pixbuf2.0-dev \
101 libgnome-keyring-dev \
104 libgnutls-openssl27 \
144 libpulse-mainloop-glib0 \
197 x11proto-composite-dev \
199 x11proto-damage-dev \
204 x11proto-record-dev \
205 x11proto-render-dev \
206 x11proto-scrnsaver-dev \
211 readonly DEBIAN_DEP_LIST_AMD64="${SCRIPT_DIR}/packagelist.debian.wheezy.amd64"
212 readonly DEBIAN_DEP_LIST_I386="${SCRIPT_DIR}/packagelist.debian.wheezy.i386"
214 ######################################################################
216 ######################################################################
219 echo "######################################################################"
221 echo "######################################################################"
226 echo "......................................................................"
228 echo "......................................................................"
233 egrep "^#@" "$0" | cut --bytes=3-
238 if [ -f "$2" ] ; then
239 echo "$2 already in place"
244 echo "$1" | grep -qs ^http:// && HTTP=1
245 if [ "$HTTP" = "1" ]; then
246 SubBanner "downloading from $1 -> $2"
249 SubBanner "copying from $1"
255 SetEnvironmentVariables() {
257 echo $1 | grep -qs Amd64$ && ARCH=AMD64
258 if [ -z "$ARCH" ]; then
259 echo $1 | grep -qs I386$ && ARCH=I386
263 INSTALL_ROOT="$INSTALL_ROOT_AMD64";
266 INSTALL_ROOT="$INSTALL_ROOT_I386";
269 echo "ERROR: Unexpected bad architecture."
279 # some sanity checks to make sure this script is run from the right place
280 # with the right tools
282 Banner "Sanity Checks"
284 if [ "$(basename $(pwd))" != "sysroot_scripts" ] ; then
285 echo -n "ERROR: run this script from "
286 echo "src/chrome/installer/linux/sysroot_scripts"
290 if ! mkdir -p "${INSTALL_ROOT}" ; then
291 echo "ERROR: ${INSTALL_ROOT} can't be created."
295 TMP=$(mktemp -q -t -d debian-wheezy-XXXXXX)
296 if [ -z "$TMP" ]; then
297 echo "ERROR: temp dir can't be created."
302 for tool in ${REQUIRED_TOOLS} ; do
303 if ! which ${tool} ; then
304 echo "Required binary $tool not found."
313 # Change directory to where this script is.
319 Banner "Clearing dirs in ${INSTALL_ROOT}"
320 rm -rf ${INSTALL_ROOT}/*
326 Banner "Creating tar ball ${tarball}"
327 tar zcf ${tarball} -C ${INSTALL_ROOT} .
330 CheckBuildSysrootArgs() {
331 if [ "$#" -ne "1" ]; then
332 echo "ERROR: BuildSysroot commands only take 1 argument"
337 echo "ERROR: tarball name required"
342 ExtractPackageBz2() {
343 bzcat "$1" | egrep '^(Package:|Filename:|SHA256:) ' > "$2"
346 GeneratePackageListAmd64() {
347 local output_file="$1"
348 local package_list="${TMP}/Packages.wheezy_amd64.bz2"
349 DownloadOrCopy ${PACKAGE_LIST_AMD64} ${package_list}
350 VerifyPackageListing ${PACKAGE_FILE_AMD64} ${package_list}
351 ExtractPackageBz2 "$package_list" "${TMP}/Packages"
353 GeneratePackageList "$output_file" "${DEBIAN_PACKAGES}"
356 GeneratePackageListI386() {
357 local output_file="$1"
358 local package_list="${TMP}/Packages.wheezy_i386.bz2"
359 DownloadOrCopy ${PACKAGE_LIST_I386} ${package_list}
360 VerifyPackageListing ${PACKAGE_FILE_I386} ${package_list}
361 ExtractPackageBz2 "$package_list" "${TMP}/Packages"
363 GeneratePackageList "$output_file" "${DEBIAN_PACKAGES}"
366 StripChecksumsFromPackageList() {
367 local package_file="$1"
368 sed -i 's/ [a-f0-9]\{64\}$//' "$package_file"
371 VerifyPackageFilesMatch() {
372 local downloaded_package_file="$1"
373 local stored_package_file="$2"
374 diff -u "$downloaded_package_file" "$stored_package_file"
375 if [ "$?" -ne "0" ]; then
376 echo "ERROR: downloaded package files does not match $2."
377 echo "You may need to run UpdatePackageLists."
382 ######################################################################
384 ######################################################################
386 HacksAndPatchesAmd64() {
387 Banner "Misc Hacks & Patches"
388 # these are linker scripts with absolute pathnames in them
389 # which we rewrite here
390 lscripts="${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libpthread.so \
391 ${INSTALL_ROOT}/usr/lib/x86_64-linux-gnu/libc.so"
393 #SubBanner "Rewriting Linker Scripts"
394 sed -i -e 's|/usr/lib/x86_64-linux-gnu/||g' ${lscripts}
395 sed -i -e 's|/lib/x86_64-linux-gnu/||g' ${lscripts}
397 # This is for chrome's ./build/linux/pkg-config-wrapper
398 # which overwrites PKG_CONFIG_PATH internally
399 SubBanner "Package Configs Symlink"
400 mkdir -p ${INSTALL_ROOT}/usr/share
401 ln -s ../lib/x86_64-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
403 SubBanner "Adding an additional ld.conf include"
404 LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
405 echo /usr/lib/gcc/x86_64-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
406 echo /usr/lib >> "$LD_SO_HACK_CONF"
410 HacksAndPatchesI386() {
411 Banner "Misc Hacks & Patches"
412 # these are linker scripts with absolute pathnames in them
413 # which we rewrite here
414 lscripts="${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libpthread.so \
415 ${INSTALL_ROOT}/usr/lib/i386-linux-gnu/libc.so"
417 #SubBanner "Rewriting Linker Scripts"
418 sed -i -e 's|/usr/lib/i386-linux-gnu/||g' ${lscripts}
419 sed -i -e 's|/lib/i386-linux-gnu/||g' ${lscripts}
421 # This is for chrome's ./build/linux/pkg-config-wrapper
422 # which overwrites PKG_CONFIG_PATH internally
423 SubBanner "Package Configs Symlink"
424 mkdir -p ${INSTALL_ROOT}/usr/share
425 ln -s ../lib/i386-linux-gnu/pkgconfig ${INSTALL_ROOT}/usr/share/pkgconfig
427 SubBanner "Adding an additional ld.conf include"
428 LD_SO_HACK_CONF="${INSTALL_ROOT}/etc/ld.so.conf.d/zz_hack.conf"
429 echo /usr/lib/gcc/i486-linux-gnu/4.6 > "$LD_SO_HACK_CONF"
430 echo /usr/lib >> "$LD_SO_HACK_CONF"
434 InstallIntoSysroot() {
435 Banner "Install Libs And Headers Into Jail"
437 mkdir -p ${TMP}/debian-packages
438 mkdir -p ${INSTALL_ROOT}
441 local package="${TMP}/debian-packages/${file##*/}"
445 if [ "${#sha256sum}" -ne "64" ]; then
446 echo "Bad sha256sum from package list"
450 Banner "Installing ${file}"
451 DownloadOrCopy ${DEBIAN_REPO}/pool/${file} ${package}
452 if [ ! -s "${package}" ] ; then
454 echo "ERROR: bad package ${package}"
457 echo "${sha256sum} ${package}" | sha256sum --quiet -c
459 SubBanner "Extracting to ${INSTALL_ROOT}"
460 dpkg --fsys-tarfile ${package}\
461 | tar -xvf - --exclude=./usr/share -C ${INSTALL_ROOT}
466 CleanupJailSymlinks() {
467 Banner "Jail symlink cleanup"
471 find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
472 # skip links with non-absolute paths
473 echo "${target}" | grep -qs ^/ || continue
474 echo "${link}: ${target}"
476 usr/lib/gcc/x86_64-linux-gnu/4.*/* | usr/lib/gcc/i486-linux-gnu/4.*/*)
477 # Relativize the symlink.
478 ln -snfv "../../../../..${target}" "${link}"
480 usr/lib/x86_64-linux-gnu/* | usr/lib/i386-linux-gnu/*)
481 # Relativize the symlink.
482 ln -snfv "../../..${target}" "${link}"
485 # Relativize the symlink.
486 ln -snfv "../..${target}" "${link}"
489 # Relativize the symlink.
490 ln -snfv "..${target}" "${link}"
495 find lib lib64 usr/lib -type l -printf '%p %l\n' | while read link target; do
496 # Make sure we catch new bad links.
497 if [ ! -r "${link}" ]; then
498 echo "ERROR: FOUND BAD LINK ${link}"
507 #@ BuildSysrootAmd64 <tarball-name>
509 #@ Build everything and package it
510 BuildSysrootAmd64() {
511 CheckBuildSysrootArgs $@
513 local package_file="$TMP/package_with_sha256sum_amd64"
514 GeneratePackageListAmd64 "$package_file"
515 local files_and_sha256sums="$(cat ${package_file})"
516 StripChecksumsFromPackageList "$package_file"
517 VerifyPackageFilesMatch "$package_file" "$DEBIAN_DEP_LIST_AMD64"
518 InstallIntoSysroot ${files_and_sha256sums}
525 #@ BuildSysrootI386 <tarball-name>
527 #@ Build everything and package it
529 CheckBuildSysrootArgs $@
531 local package_file="$TMP/package_with_sha256sum_amd64"
532 GeneratePackageListI386 "$package_file"
533 local files_and_sha256sums="$(cat ${package_file})"
534 StripChecksumsFromPackageList "$package_file"
535 VerifyPackageFilesMatch "$package_file" "$DEBIAN_DEP_LIST_I386"
536 InstallIntoSysroot ${files_and_sha256sums}
543 # CheckForDebianGPGKeys
545 # Make sure the Debian GPG keys exist. Otherwise print a helpful message.
547 CheckForDebianGPGKeys() {
548 if [ ! -e "/etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg" ] ||
549 [ ! -e "/etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg" ]; then
550 echo "Debian GPG keys missing. Install the debian-archive-keyring package."
556 # VerifyPackageListing
558 # Verifies the downloaded Packages.bz2 file has the right checksums.
560 VerifyPackageListing() {
563 local release_file="${TMP}/${RELEASE_FILE}"
564 local release_file_gpg="${TMP}/${RELEASE_FILE_GPG}"
566 CheckForDebianGPGKeys
568 DownloadOrCopy ${RELEASE_LIST} ${release_file}
569 DownloadOrCopy ${RELEASE_LIST_GPG} ${release_file_gpg}
570 echo "Verifying: ${release_file} with ${release_file_gpg}"
571 gpgv --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg \
572 --keyring /etc/apt/trusted.gpg.d/debian-archive-wheezy-stable.gpg \
573 ${release_file_gpg} ${release_file}
575 echo "Verifying: ${output_file}"
576 local checksums=$(grep ${file_path} ${release_file} | cut -d " " -f 2)
577 local sha256sum=$(echo ${checksums} | cut -d " " -f 3)
579 if [ "${#sha256sum}" -ne "64" ]; then
580 echo "Bad sha256sum from ${RELEASE_LIST}"
584 echo "${sha256sum} ${output_file}" | sha256sum --quiet -c
588 # GeneratePackageList
590 # Looks up package names in ${TMP}/Packages and write list of URLs
593 GeneratePackageList() {
594 local output_file="$1"
595 echo "Updating: ${output_file}"
596 /bin/rm -f "${output_file}"
599 local pkg_full=$(grep -A 1 " ${pkg}\$" "${TMP}/Packages" | \
601 if [ -z "${pkg_full}" ]; then
602 echo "ERROR: missing package: $pkg"
605 local pkg_nopool=$(echo "$pkg_full" | sed "s/^pool\///")
606 local sha256sum=$(grep -A 4 " ${pkg}\$" "${TMP}/Packages" | \
607 grep ^SHA256: | sed 's/^SHA256: //')
608 if [ "${#sha256sum}" -ne "64" ]; then
609 echo "Bad sha256sum from Packages"
612 echo $pkg_nopool $sha256sum >> "$output_file"
614 # sort -o does an in-place sort of this file
615 sort "$output_file" -o "$output_file"
619 #@ UpdatePackageListsAmd64
621 #@ Regenerate the package lists such that they contain an up-to-date
622 #@ list of URLs within the Debian archive. (For amd64)
623 UpdatePackageListsAmd64() {
624 GeneratePackageListAmd64 "$DEBIAN_DEP_LIST_AMD64"
625 StripChecksumsFromPackageList "$DEBIAN_DEP_LIST_AMD64"
629 #@ UpdatePackageListsI386
631 #@ Regenerate the package lists such that they contain an up-to-date
632 #@ list of URLs within the Debian archive. (For i386)
633 UpdatePackageListsI386() {
634 GeneratePackageListI386 "$DEBIAN_DEP_LIST_I386"
635 StripChecksumsFromPackageList "$DEBIAN_DEP_LIST_I386"
638 if [ $# -eq 0 ] ; then
639 echo "ERROR: you must specify a mode on the commandline"
643 elif [ "$(type -t $1)" != "function" ]; then
644 echo "ERROR: unknown function '$1'." >&2
645 echo "For help, try:"
650 SetEnvironmentVariables "$1"