michael@0: #!/bin/bash -e michael@0: michael@0: # Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: # Script to install everything needed to build chromium (well, ideally, anyway) michael@0: # See http://code.google.com/p/chromium/wiki/LinuxBuildInstructions michael@0: # and http://code.google.com/p/chromium/wiki/LinuxBuild64Bit michael@0: michael@0: usage() { michael@0: echo "Usage: $0 [--options]" michael@0: echo "Options:" michael@0: echo "--[no-]syms: enable or disable installation of debugging symbols" michael@0: echo "--[no-]lib32: enable or disable installation of 32 bit libraries" michael@0: echo "--no-prompt: silently select standard options/defaults" michael@0: echo "Script will prompt interactively if options not given." michael@0: exit 1 michael@0: } michael@0: michael@0: while test "$1" != "" michael@0: do michael@0: case "$1" in michael@0: --syms) do_inst_syms=1;; michael@0: --no-syms) do_inst_syms=0;; michael@0: --lib32) do_inst_lib32=1;; michael@0: --no-lib32) do_inst_lib32=0;; michael@0: --no-prompt) do_default=1 michael@0: do_quietly="-qq --assume-yes" michael@0: ;; michael@0: *) usage;; michael@0: esac michael@0: shift michael@0: done michael@0: michael@0: if ! egrep -q \ michael@0: 'Ubuntu (10\.04|10\.10|11\.04|11\.10|12\.04|lucid|maverick|natty|oneiric|precise)' \ michael@0: /etc/issue; then michael@0: echo "Only Ubuntu 10.04 (lucid) through 12.04 (precise) are currently" \ michael@0: "supported" >&2 michael@0: exit 1 michael@0: fi michael@0: michael@0: if ! uname -m | egrep -q "i686|x86_64"; then michael@0: echo "Only x86 architectures are currently supported" >&2 michael@0: exit michael@0: fi michael@0: michael@0: if [ "x$(id -u)" != x0 ]; then michael@0: echo "Running as non-root user." michael@0: echo "You might have to enter your password one or more times for 'sudo'." michael@0: echo michael@0: fi michael@0: michael@0: # Packages needed for chromeos only michael@0: chromeos_dev_list="libbluetooth-dev libpulse-dev" michael@0: michael@0: # Packages need for development michael@0: dev_list="apache2.2-bin bison curl elfutils fakeroot flex g++ gperf michael@0: language-pack-fr libapache2-mod-php5 libasound2-dev libbz2-dev michael@0: libcairo2-dev libcups2-dev libcurl4-gnutls-dev libdbus-glib-1-dev michael@0: libelf-dev libgconf2-dev libgl1-mesa-dev libglib2.0-dev michael@0: libglu1-mesa-dev libgnome-keyring-dev libgtk2.0-dev michael@0: libkrb5-dev libnspr4-dev libnss3-dev libpam0g-dev libsctp-dev michael@0: libsqlite3-dev libssl-dev libudev-dev libwww-perl libxslt1-dev michael@0: libxss-dev libxt-dev libxtst-dev mesa-common-dev patch michael@0: perl php5-cgi pkg-config python python-cherrypy3 python-dev michael@0: python-psutil rpm ruby subversion ttf-dejavu-core ttf-indic-fonts michael@0: ttf-kochi-gothic ttf-kochi-mincho ttf-thai-tlwg wdiff git-core michael@0: $chromeos_dev_list" michael@0: michael@0: # 64-bit systems need a minimum set of 32-bit compat packages for the pre-built michael@0: # NaCl binaries. These are always needed, regardless of whether or not we want michael@0: # the full 32-bit "cross-compile" support (--lib32). michael@0: if [ "$(uname -m)" = "x86_64" ]; then michael@0: dev_list="${dev_list} libc6-i386 lib32gcc1 lib32stdc++6" michael@0: fi michael@0: michael@0: # Run-time libraries required by chromeos only michael@0: chromeos_lib_list="libpulse0 libbz2-1.0 libcurl4-gnutls-dev" michael@0: michael@0: # Full list of required run-time libraries michael@0: lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libcups2 libdbus-glib-1-2 michael@0: libexpat1 libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0 michael@0: libgtk2.0-0 libpam0g libpango1.0-0 libpcre3 libpixman-1-0 michael@0: libpng12-0 libstdc++6 libsqlite3-0 libudev0 libx11-6 libxau6 libxcb1 michael@0: libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 michael@0: libxi6 libxinerama1 libxrandr2 libxrender1 libxtst6 zlib1g michael@0: $chromeos_lib_list" michael@0: michael@0: # Debugging symbols for all of the run-time libraries michael@0: dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg libdbus-glib-1-2-dbg michael@0: libfontconfig1-dbg libglib2.0-0-dbg libgtk2.0-0-dbg michael@0: libpango1.0-0-dbg libpcre3-dbg libpixman-1-0-dbg michael@0: libsqlite3-0-dbg michael@0: libx11-6-dbg libxau6-dbg libxcb1-dbg libxcomposite1-dbg michael@0: libxcursor1-dbg libxdamage1-dbg libxdmcp6-dbg libxext6-dbg michael@0: libxfixes3-dbg libxi6-dbg libxinerama1-dbg libxrandr2-dbg michael@0: libxrender1-dbg libxtst6-dbg zlib1g-dbg" michael@0: michael@0: # Plugin lists needed for tests. michael@0: plugin_list="flashplugin-installer" michael@0: michael@0: # Some package names have changed over time michael@0: if apt-cache show ttf-mscorefonts-installer >/dev/null 2>&1; then michael@0: dev_list="${dev_list} ttf-mscorefonts-installer" michael@0: else michael@0: dev_list="${dev_list} msttcorefonts" michael@0: fi michael@0: if apt-cache show libnspr4-dbg >/dev/null 2>&1; then michael@0: dbg_list="${dbg_list} libnspr4-dbg libnss3-dbg" michael@0: lib_list="${lib_list} libnspr4 libnss3" michael@0: else michael@0: dbg_list="${dbg_list} libnspr4-0d-dbg libnss3-1d-dbg" michael@0: lib_list="${lib_list} libnspr4-0d libnss3-1d" michael@0: fi michael@0: if apt-cache show libjpeg-dev >/dev/null 2>&1; then michael@0: dev_list="${dev_list} libjpeg-dev" michael@0: else michael@0: dev_list="${dev_list} libjpeg62-dev" michael@0: fi michael@0: michael@0: # Some packages are only needed, if the distribution actually supports michael@0: # installing them. michael@0: if apt-cache show appmenu-gtk >/dev/null 2>&1; then michael@0: lib_list="$lib_list appmenu-gtk" michael@0: fi michael@0: michael@0: # Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is michael@0: # accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has michael@0: # been provided to yes_no(), the function also accepts RETURN as a user input. michael@0: # The parameter specifies the exit code that should be returned in that case. michael@0: # The function will echo the user's selection followed by a newline character. michael@0: # Users can abort the function by pressing CTRL-C. This will call "exit 1". michael@0: yes_no() { michael@0: if [ 0 -ne "${do_default-0}" ] ; then michael@0: return $1 michael@0: fi michael@0: local c michael@0: while :; do michael@0: c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT michael@0: stty -echo iuclc -icanon 2>/dev/null michael@0: dd count=1 bs=1 2>/dev/null | od -An -tx1)" michael@0: case "$c" in michael@0: " 0a") if [ -n "$1" ]; then michael@0: [ $1 -eq 0 ] && echo "Y" || echo "N" michael@0: return $1 michael@0: fi michael@0: ;; michael@0: " 79") echo "Y" michael@0: return 0 michael@0: ;; michael@0: " 6e") echo "N" michael@0: return 1 michael@0: ;; michael@0: "") echo "Aborted" >&2 michael@0: exit 1 michael@0: ;; michael@0: *) # The user pressed an unrecognized key. As we are not echoing michael@0: # any incorrect user input, alert the user by ringing the bell. michael@0: (tput bel) 2>/dev/null michael@0: ;; michael@0: esac michael@0: done michael@0: } michael@0: michael@0: if test "$do_inst_syms" = "" michael@0: then michael@0: echo "This script installs all tools and libraries needed to build Chromium." michael@0: echo "" michael@0: echo "For most of the libraries, it can also install debugging symbols, which" michael@0: echo "will allow you to debug code in the system libraries. Most developers" michael@0: echo "won't need these symbols." michael@0: echo -n "Do you want me to install them for you (y/N) " michael@0: if yes_no 1; then michael@0: do_inst_syms=1 michael@0: fi michael@0: fi michael@0: if test "$do_inst_syms" = "1"; then michael@0: echo "Installing debugging symbols." michael@0: else michael@0: echo "Skipping installation of debugging symbols." michael@0: dbg_list= michael@0: fi michael@0: michael@0: sudo apt-get update michael@0: michael@0: # We initially run "apt-get" with the --reinstall option and parse its output. michael@0: # This way, we can find all the packages that need to be newly installed michael@0: # without accidentally promoting any packages from "auto" to "manual". michael@0: # We then re-run "apt-get" with just the list of missing packages. michael@0: echo "Finding missing packages..." michael@0: packages="${dev_list} ${lib_list} ${dbg_list} ${plugin_list}" michael@0: # Intentionally leaving $packages unquoted so it's more readable. michael@0: echo "Packages required: " $packages michael@0: echo michael@0: new_list_cmd="sudo apt-get install --reinstall $(echo $packages)" michael@0: if new_list="$(yes n | LANG=C $new_list_cmd)"; then michael@0: # We probably never hit this following line. michael@0: echo "No missing packages, and the packages are up-to-date." michael@0: elif [ $? -eq 1 ]; then michael@0: # We expect apt-get to have exit status of 1. michael@0: # This indicates that we cancelled the install with "yes n|". michael@0: new_list=$(echo "$new_list" | michael@0: sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d') michael@0: new_list=$(echo "$new_list" | sed 's/ *$//') michael@0: if [ -z "$new_list" ] ; then michael@0: echo "No missing packages, and the packages are up-to-date." michael@0: else michael@0: echo "Installing missing packages: $new_list." michael@0: sudo apt-get install ${do_quietly-} ${new_list} michael@0: fi michael@0: echo michael@0: else michael@0: # An apt-get exit status of 100 indicates that a real error has occurred. michael@0: michael@0: # I am intentionally leaving out the '"'s around new_list_cmd, michael@0: # as this makes it easier to cut and paste the output michael@0: echo "The following command failed: " ${new_list_cmd} michael@0: echo michael@0: echo "It produces the following output:" michael@0: yes n | $new_list_cmd || true michael@0: echo michael@0: echo "You will have to install the above packages yourself." michael@0: echo michael@0: exit 100 michael@0: fi michael@0: michael@0: # Install 32bit backwards compatibility support for 64bit systems michael@0: if [ "$(uname -m)" = "x86_64" ]; then michael@0: if test "$do_inst_lib32" = "" michael@0: then michael@0: echo "We no longer recommend that you use this script to install" michael@0: echo "32bit libraries on a 64bit system. Instead, consider using" michael@0: echo "the install-chroot.sh script to help you set up a 32bit" michael@0: echo "environment for building and testing 32bit versions of Chrome." michael@0: echo michael@0: echo "If you nonetheless want to try installing 32bit libraries" michael@0: echo "directly, you can do so by explicitly passing the --lib32" michael@0: echo "option to install-build-deps.sh." michael@0: fi michael@0: if test "$do_inst_lib32" != "1" michael@0: then michael@0: echo "Exiting without installing any 32bit libraries." michael@0: exit 0 michael@0: fi michael@0: michael@0: echo "N.B. the code for installing 32bit libraries on a 64bit" michael@0: echo " system is no longer actively maintained and might" michael@0: echo " not work with modern versions of Ubuntu or Debian." michael@0: echo michael@0: michael@0: # Standard 32bit compatibility libraries michael@0: echo "First, installing the limited existing 32-bit support..." michael@0: cmp_list="ia32-libs lib32asound2-dev lib32stdc++6 lib32z1 michael@0: lib32z1-dev libc6-dev-i386 libc6-i386 g++-multilib" michael@0: if [ -n "`apt-cache search lib32readline-gplv2-dev 2>/dev/null`" ]; then michael@0: cmp_list="${cmp_list} lib32readline-gplv2-dev" michael@0: else michael@0: cmp_list="${cmp_list} lib32readline5-dev" michael@0: fi michael@0: sudo apt-get install ${do_quietly-} $cmp_list michael@0: michael@0: tmp=/tmp/install-32bit.$$ michael@0: trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT michael@0: mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial" michael@0: touch "${tmp}/status" michael@0: michael@0: [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/" michael@0: cat >>"${tmp}/apt/apt.conf" <dpkg/DEBIAN/postinst michael@0: { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \ michael@0: >dpkg/DEBIAN/postrm michael@0: chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm michael@0: michael@0: # Remove any other control files michael@0: find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \ michael@0: -name postinst -o -name postrm ")" -o -print | michael@0: xargs -r rm -rf michael@0: michael@0: # Remove any files/dirs that live outside of "lib" directories, michael@0: # or are not in our list of changed includes. michael@0: find dpkg -mindepth 1 -regextype posix-extended \ michael@0: "(" -name DEBIAN -o -name lib -o -regex "dpkg/($includes)" ")" \ michael@0: -prune -o -print | tac | michael@0: xargs -r -n 1 sh -c "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : " michael@0: find dpkg -name lib64 -o -name bin -o -name "?bin" | michael@0: tac | xargs -r rm -rf michael@0: michael@0: # Remove any symbolic links that were broken by the above steps. michael@0: find -L dpkg -type l -print | tac | xargs -r rm -rf michael@0: michael@0: # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32 michael@0: # That is where gdb looks for them. michael@0: find dpkg -type d -o -path "*/lib/*" -print | michael@0: xargs -r -n 1 sh -c " michael@0: i=\$(echo \"\${0}\" | michael@0: sed -e s,/lib/,/lib32/,g \ michael@0: -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,); michael@0: mkdir -p \"\${i%/*}\"; michael@0: mv \"\${0}\" \"\${i}\"" michael@0: michael@0: # Rename include to include32. michael@0: [ -d "dpkg/usr/include" ] && mv "dpkg/usr/include" "dpkg/usr/include32" michael@0: michael@0: # Prune any empty directories michael@0: find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || : michael@0: michael@0: # Create our own Debian package michael@0: cd .. michael@0: dpkg --build staging/dpkg .' 2>&1)" michael@0: compat="$(eval echo $(echo "${compat}" | michael@0: sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))" michael@0: [ -r "${compat}" ] || { michael@0: echo "${msg}" >&2 michael@0: echo "Failed to build new Debian archive!" >&2 michael@0: exit 1 michael@0: } michael@0: michael@0: msg="$(sudo dpkg -i "${compat}" 2>&1)" && { michael@0: echo "Installed ${compat##*/}" michael@0: } || { michael@0: # echo "${msg}" >&2 michael@0: echo "Skipped ${compat##*/}" michael@0: } michael@0: done michael@0: michael@0: # Add symbolic links for developing 32bit code michael@0: echo "Adding missing symbolic links, enabling 32bit code development..." michael@0: for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* | michael@0: sed -e 's/[.]so[.][0-9].*/.so/' | michael@0: sort -u); do michael@0: [ "x${i##*/}" = "xld-linux.so" ] && continue michael@0: [ -r "$i" ] && continue michael@0: j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' | michael@0: sort -n | tail -n 1)" michael@0: [ -r "$i.$j" ] || continue michael@0: sudo ln -s "${i##*/}.$j" "$i" michael@0: done michael@0: fi