Add jessie support to install-build-deps.sh

This CL
- Enables jessie support in install-build-deps.sh
- Adds a note in linux_build_instructions.md about adding the
  'contrib' component in sources.list.
- Fixes a bug in package_exists where if a ppa is added, a package is
  installed from it, and then the ppa is removed, and the package is
  removed but not purged, package_exists would still return true for
  the package.

[email protected]

Review-Url: https://codereview.chromium.org/2556133003
Cr-Commit-Position: refs/heads/master@{#437198}
diff --git a/build/install-build-deps.sh b/build/install-build-deps.sh
index dce1931..dcc4108 100755
--- a/build/install-build-deps.sh
+++ b/build/install-build-deps.sh
@@ -68,7 +68,7 @@
 # Checks whether a particular package is available in the repos.
 # USAGE: $ package_exists <package name>
 package_exists() {
-  apt-cache pkgnames | grep -x "$1" > /dev/null 2>&1
+  [ ! -z "`apt-cache search --names-only "$1"`" ]
 }
 
 # These default to on because (some) bots need them and it keeps things
@@ -111,12 +111,12 @@
 fi
 
 lsb_release=$(lsb_release --codename --short)
-ubuntu_codenames="(precise|trusty|utopic|vivid|wily|xenial)"
+supported_releases="(precise|trusty|utopic|vivid|wily|xenial|jessie)"
 if [ 0 -eq "${do_unsupported-0}" ] && [ 0 -eq "${do_quick_check-0}" ] ; then
-  if [[ ! $lsb_release =~ $ubuntu_codenames ]]; then
+  if [[ ! $lsb_release =~ $supported_releases ]]; then
     echo "ERROR: Only Ubuntu 12.04 (precise), 14.04 (trusty), " \
-      "14.10 (utopic), 15.04 (vivid), 15.10 (wily) and 16.04 (xenial) " \
-      "are currently supported" >&2
+      "14.10 (utopic), 15.04 (vivid), 15.10 (wily) and 16.04 (xenial), " \
+      "and Debian 8 (jessie) are currently supported" >&2
     exit 1
   fi
 
@@ -284,11 +284,6 @@
 nacl_list="${nacl_list} libgl1-mesa-glx${mesa_variant}:i386"
 
 # Some package names have changed over time
-if package_exists ttf-mscorefonts-installer; then
-  dev_list="${dev_list} ttf-mscorefonts-installer"
-else
-  dev_list="${dev_list} msttcorefonts"
-fi
 if package_exists libnspr4-dbg; then
   dbg_list="${dbg_list} libnspr4-dbg libnss3-dbg"
   lib_list="${lib_list} libnspr4 libnss3"
@@ -331,6 +326,14 @@
 else
   dev_list="${dev_list} php5-cgi libapache2-mod-php5"
 fi
+# ttf-mscorefonts-installer is in the Debian contrib repo, which has
+# dependencies on non-free software.  Install it only if the user has already
+# enabled contrib.
+if package_exists ttf-mscorefonts-installer; then
+  dev_list="${dev_list} ttf-mscorefonts-installer"
+elif package_exists msttcorefonts; then
+  dev_list="${dev_list} msttcorefonts"
+fi
 # Ubuntu 16.04 has this package deleted.
 if package_exists ttf-kochi-gothic; then
   dev_list="${dev_list} ttf-kochi-gothic"
diff --git a/docs/linux_build_instructions.md b/docs/linux_build_instructions.md
index 957254e0..0fe97e6 100644
--- a/docs/linux_build_instructions.md
+++ b/docs/linux_build_instructions.md
@@ -334,14 +334,34 @@
 
 ### Debian
 
-`build/install-build-deps.sh` doesn't currently run on Debian, but you can
-probably hack it to get it to work. You will probably need to update the
-following package names:
+Some tests require the `ttf-mscorefonts-installer` package from the `contrib`
+component. `contrib` packages may have dependencies on non-free software.
 
-*   `libexpat-dev` → `libexpat1-dev`
-*   `freetype-dev` → `libfreetype6-dev`
-*   `libbzip2-dev` → `libbz2-dev`
-*   `libcupsys2-dev` → `libcups2-dev`
+If you need to run tests requiring MS TTF fonts, you can edit your apt
+`sources.list` by adding `contrib` to the end of each line beginning with `deb`.
+You might end up with something like this:
+
+```
+deb http://ftp.us.debian.org/debian/ jessie main contrib
+deb-src http://ftp.us.debian.org/debian/ jessie main contrib
+
+deb http://security.debian.org/ jessie/updates main contrib
+deb-src http://security.debian.org/ jessie/updates main contrib
+
+# jessie-updates, previously known as 'volatile'
+deb http://ftp.us.debian.org/debian/ jessie-updates main contrib
+deb-src http://ftp.us.debian.org/debian/ jessie-updates main contrib
+```
+
+Next, run:
+
+``` shell
+$ sudo apt-get update
+$ sudo apt-get install ttf-mscorefonts-installer
+```
+
+If you already have the `contrib` component enabled, `install-build-deps.sh`
+will install `ttf-mscorefonts-installer` for you.
 
 ### Fedora