[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 1 | #!/bin/bash -e |
| 2 | |
[email protected] | aac39c9 | 2012-02-08 18:39:53 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | e46cdae | 2009-08-25 20:59:27 | [diff] [blame] | 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 7 | # Script to install everything needed to build chromium (well, ideally, anyway) |
[email protected] | 592ea8ca | 2008-11-03 19:47:36 | [diff] [blame] | 8 | # See http://code.google.com/p/chromium/wiki/LinuxBuildInstructions |
| 9 | # and http://code.google.com/p/chromium/wiki/LinuxBuild64Bit |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 10 | |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 11 | usage() { |
| 12 | echo "Usage: $0 [--options]" |
| 13 | echo "Options:" |
| 14 | echo "--[no-]syms: enable or disable installation of debugging symbols" |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 15 | echo "--[no-]lib32: enable or disable installation of 32 bit libraries" |
[email protected] | e2544ed4 | 2012-04-23 04:48:31 | [diff] [blame] | 16 | echo "--no-prompt: silently select standard options/defaults" |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 17 | echo "Script will prompt interactively if options not given." |
| 18 | exit 1 |
| 19 | } |
| 20 | |
| 21 | while test "$1" != "" |
| 22 | do |
| 23 | case "$1" in |
[email protected] | ce77464 | 2011-09-12 23:21:39 | [diff] [blame] | 24 | --syms) do_inst_syms=1;; |
| 25 | --no-syms) do_inst_syms=0;; |
[email protected] | ce77464 | 2011-09-12 23:21:39 | [diff] [blame] | 26 | --lib32) do_inst_lib32=1;; |
| 27 | --no-lib32) do_inst_lib32=0;; |
[email protected] | e2544ed4 | 2012-04-23 04:48:31 | [diff] [blame] | 28 | --no-prompt) do_default=1 |
| 29 | do_quietly="-qq --assume-yes" |
| 30 | ;; |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 31 | *) usage;; |
| 32 | esac |
| 33 | shift |
| 34 | done |
| 35 | |
[email protected] | a51551d | 2010-07-15 22:59:48 | [diff] [blame] | 36 | if ! egrep -q \ |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 37 | 'Ubuntu (10\.04|10\.10|11\.04|11\.10|12\.04|lucid|maverick|natty|oneiric|precise)' \ |
[email protected] | a51551d | 2010-07-15 22:59:48 | [diff] [blame] | 38 | /etc/issue; then |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 39 | echo "Only Ubuntu 10.04 (lucid) through 12.04 (precise) are currently" \ |
[email protected] | a51551d | 2010-07-15 22:59:48 | [diff] [blame] | 40 | "supported" >&2 |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 41 | exit 1 |
| 42 | fi |
[email protected] | cf1df40 | 2008-10-31 21:45:30 | [diff] [blame] | 43 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 44 | if ! uname -m | egrep -q "i686|x86_64"; then |
| 45 | echo "Only x86 architectures are currently supported" >&2 |
| 46 | exit |
| 47 | fi |
| 48 | |
| 49 | if [ "x$(id -u)" != x0 ]; then |
| 50 | echo "Running as non-root user." |
| 51 | echo "You might have to enter your password one or more times for 'sudo'." |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 52 | echo |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 53 | fi |
| 54 | |
[email protected] | fdc6bf5 | 2010-06-07 22:01:57 | [diff] [blame] | 55 | # Packages needed for chromeos only |
[email protected] | e8626b9 | 2012-04-20 18:06:18 | [diff] [blame] | 56 | chromeos_dev_list="libbluetooth-dev libpulse-dev" |
[email protected] | fdc6bf5 | 2010-06-07 22:01:57 | [diff] [blame] | 57 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 58 | # Packages need for development |
[email protected] | 041d14a | 2011-12-13 01:42:48 | [diff] [blame] | 59 | dev_list="apache2.2-bin bison curl elfutils fakeroot flex g++ gperf |
| 60 | language-pack-fr libapache2-mod-php5 libasound2-dev libbz2-dev |
[email protected] | 6ffd19f35 | 2012-10-23 02:00:41 | [diff] [blame] | 61 | libcairo2-dev libcups2-dev libcurl4-gnutls-dev libelf-dev |
| 62 | libgconf2-dev libgl1-mesa-dev libglib2.0-dev libglu1-mesa-dev |
| 63 | libgnome-keyring-dev libgtk2.0-dev libkrb5-dev libnspr4-dev |
[email protected] | ca3a1d26 | 2012-10-30 22:33:20 | [diff] [blame] | 64 | libnss3-dev libpam0g-dev libpci-dev libsctp-dev libsqlite3-dev |
| 65 | libssl-dev libudev-dev libwww-perl libxslt1-dev libxss-dev libxt-dev |
| 66 | libxtst-dev mesa-common-dev patch perl php5-cgi pkg-config python |
| 67 | python-cherrypy3 python-dev python-psutil rpm ruby subversion |
| 68 | ttf-dejavu-core ttf-indic-fonts ttf-kochi-gothic ttf-kochi-mincho |
| 69 | ttf-thai-tlwg wdiff git-core $chromeos_dev_list" |
[email protected] | fdc6bf5 | 2010-06-07 22:01:57 | [diff] [blame] | 70 | |
[email protected] | f16aabf | 2012-08-15 21:00:14 | [diff] [blame] | 71 | # 64-bit systems need a minimum set of 32-bit compat packages for the pre-built |
[email protected] | d93d68b1 | 2012-10-15 06:39:53 | [diff] [blame] | 72 | # NaCl binaries. These are always needed, regardless of whether or not we want |
[email protected] | f16aabf | 2012-08-15 21:00:14 | [diff] [blame] | 73 | # the full 32-bit "cross-compile" support (--lib32). |
| 74 | if [ "$(uname -m)" = "x86_64" ]; then |
[email protected] | d93d68b1 | 2012-10-15 06:39:53 | [diff] [blame] | 75 | dev_list="${dev_list} libc6-i386 lib32gcc1 lib32stdc++6" |
[email protected] | f16aabf | 2012-08-15 21:00:14 | [diff] [blame] | 76 | fi |
| 77 | |
[email protected] | fdc6bf5 | 2010-06-07 22:01:57 | [diff] [blame] | 78 | # Run-time libraries required by chromeos only |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 79 | chromeos_lib_list="libpulse0 libbz2-1.0 libcurl4-gnutls-dev" |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 80 | |
| 81 | # Full list of required run-time libraries |
[email protected] | 6ffd19f35 | 2012-10-23 02:00:41 | [diff] [blame] | 82 | lib_list="libatk1.0-0 libc6 libasound2 libcairo2 libcups2 libexpat1 |
| 83 | libfontconfig1 libfreetype6 libglib2.0-0 libgnome-keyring0 |
[email protected] | ca3a1d26 | 2012-10-30 22:33:20 | [diff] [blame] | 84 | libgtk2.0-0 libpam0g libpango1.0-0 libpci3 libpcre3 libpixman-1-0 |
[email protected] | 6de217b7 | 2011-12-17 03:36:32 | [diff] [blame] | 85 | libpng12-0 libstdc++6 libsqlite3-0 libudev0 libx11-6 libxau6 libxcb1 |
[email protected] | fd11101b | 2011-02-16 04:46:46 | [diff] [blame] | 86 | libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 |
| 87 | libxi6 libxinerama1 libxrandr2 libxrender1 libxtst6 zlib1g |
[email protected] | 9dc4bed | 2010-11-04 19:23:30 | [diff] [blame] | 88 | $chromeos_lib_list" |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 89 | |
| 90 | # Debugging symbols for all of the run-time libraries |
[email protected] | 6ffd19f35 | 2012-10-23 02:00:41 | [diff] [blame] | 91 | dbg_list="libatk1.0-dbg libc6-dbg libcairo2-dbg libfontconfig1-dbg |
| 92 | libglib2.0-0-dbg libgtk2.0-0-dbg libpango1.0-0-dbg libpcre3-dbg |
| 93 | libpixman-1-0-dbg libsqlite3-0-dbg libx11-6-dbg libxau6-dbg |
| 94 | libxcb1-dbg libxcomposite1-dbg libxcursor1-dbg libxdamage1-dbg |
| 95 | libxdmcp6-dbg libxext6-dbg libxfixes3-dbg libxi6-dbg libxinerama1-dbg |
| 96 | libxrandr2-dbg libxrender1-dbg libxtst6-dbg zlib1g-dbg" |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 97 | |
[email protected] | 31a60553 | 2011-08-23 22:27:35 | [diff] [blame] | 98 | # Plugin lists needed for tests. |
| 99 | plugin_list="flashplugin-installer" |
| 100 | |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 101 | # Some package names have changed over time |
[email protected] | b11411c | 2012-03-21 22:09:41 | [diff] [blame] | 102 | if apt-cache show ttf-mscorefonts-installer >/dev/null 2>&1; then |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 103 | dev_list="${dev_list} ttf-mscorefonts-installer" |
[email protected] | b11411c | 2012-03-21 22:09:41 | [diff] [blame] | 104 | else |
| 105 | dev_list="${dev_list} msttcorefonts" |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 106 | fi |
[email protected] | b11411c | 2012-03-21 22:09:41 | [diff] [blame] | 107 | if apt-cache show libnspr4-dbg >/dev/null 2>&1; then |
[email protected] | 1a0f64a | 2011-05-20 17:53:55 | [diff] [blame] | 108 | dbg_list="${dbg_list} libnspr4-dbg libnss3-dbg" |
| 109 | lib_list="${lib_list} libnspr4 libnss3" |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 110 | else |
| 111 | dbg_list="${dbg_list} libnspr4-0d-dbg libnss3-1d-dbg" |
| 112 | lib_list="${lib_list} libnspr4-0d libnss3-1d" |
| 113 | fi |
[email protected] | b11411c | 2012-03-21 22:09:41 | [diff] [blame] | 114 | if apt-cache show libjpeg-dev >/dev/null 2>&1; then |
| 115 | dev_list="${dev_list} libjpeg-dev" |
| 116 | else |
| 117 | dev_list="${dev_list} libjpeg62-dev" |
| 118 | fi |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 119 | |
| 120 | # Some packages are only needed, if the distribution actually supports |
| 121 | # installing them. |
[email protected] | b11411c | 2012-03-21 22:09:41 | [diff] [blame] | 122 | if apt-cache show appmenu-gtk >/dev/null 2>&1; then |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 123 | lib_list="$lib_list appmenu-gtk" |
[email protected] | 4da8fad | 2011-04-11 18:42:42 | [diff] [blame] | 124 | fi |
| 125 | |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 126 | # Waits for the user to press 'Y' or 'N'. Either uppercase of lowercase is |
| 127 | # accepted. Returns 0 for 'Y' and 1 for 'N'. If an optional parameter has |
| 128 | # been provided to yes_no(), the function also accepts RETURN as a user input. |
| 129 | # The parameter specifies the exit code that should be returned in that case. |
| 130 | # The function will echo the user's selection followed by a newline character. |
| 131 | # Users can abort the function by pressing CTRL-C. This will call "exit 1". |
| 132 | yes_no() { |
[email protected] | e2544ed4 | 2012-04-23 04:48:31 | [diff] [blame] | 133 | if [ 0 -ne "${do_default-0}" ] ; then |
| 134 | return $1 |
| 135 | fi |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 136 | local c |
| 137 | while :; do |
| 138 | c="$(trap 'stty echo -iuclc icanon 2>/dev/null' EXIT INT TERM QUIT |
| 139 | stty -echo iuclc -icanon 2>/dev/null |
| 140 | dd count=1 bs=1 2>/dev/null | od -An -tx1)" |
| 141 | case "$c" in |
| 142 | " 0a") if [ -n "$1" ]; then |
| 143 | [ $1 -eq 0 ] && echo "Y" || echo "N" |
| 144 | return $1 |
| 145 | fi |
| 146 | ;; |
| 147 | " 79") echo "Y" |
| 148 | return 0 |
| 149 | ;; |
| 150 | " 6e") echo "N" |
| 151 | return 1 |
| 152 | ;; |
| 153 | "") echo "Aborted" >&2 |
| 154 | exit 1 |
| 155 | ;; |
| 156 | *) # The user pressed an unrecognized key. As we are not echoing |
| 157 | # any incorrect user input, alert the user by ringing the bell. |
| 158 | (tput bel) 2>/dev/null |
| 159 | ;; |
| 160 | esac |
| 161 | done |
| 162 | } |
| 163 | |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 164 | if test "$do_inst_syms" = "" |
| 165 | then |
| 166 | echo "This script installs all tools and libraries needed to build Chromium." |
| 167 | echo "" |
| 168 | echo "For most of the libraries, it can also install debugging symbols, which" |
| 169 | echo "will allow you to debug code in the system libraries. Most developers" |
| 170 | echo "won't need these symbols." |
| 171 | echo -n "Do you want me to install them for you (y/N) " |
| 172 | if yes_no 1; then |
| 173 | do_inst_syms=1 |
| 174 | fi |
| 175 | fi |
| 176 | if test "$do_inst_syms" = "1"; then |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 177 | echo "Installing debugging symbols." |
| 178 | else |
| 179 | echo "Skipping installation of debugging symbols." |
| 180 | dbg_list= |
| 181 | fi |
| 182 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 183 | sudo apt-get update |
| 184 | |
| 185 | # We initially run "apt-get" with the --reinstall option and parse its output. |
| 186 | # This way, we can find all the packages that need to be newly installed |
| 187 | # without accidentally promoting any packages from "auto" to "manual". |
| 188 | # We then re-run "apt-get" with just the list of missing packages. |
| 189 | echo "Finding missing packages..." |
[email protected] | 31a60553 | 2011-08-23 22:27:35 | [diff] [blame] | 190 | packages="${dev_list} ${lib_list} ${dbg_list} ${plugin_list}" |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 191 | # Intentionally leaving $packages unquoted so it's more readable. |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 192 | echo "Packages required: " $packages |
| 193 | echo |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 194 | new_list_cmd="sudo apt-get install --reinstall $(echo $packages)" |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 195 | if new_list="$(yes n | LANG=C $new_list_cmd)"; then |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 196 | # We probably never hit this following line. |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 197 | echo "No missing packages, and the packages are up-to-date." |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 198 | elif [ $? -eq 1 ]; then |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 199 | # We expect apt-get to have exit status of 1. |
[email protected] | 757c296 | 2012-03-15 19:05:18 | [diff] [blame] | 200 | # This indicates that we cancelled the install with "yes n|". |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 201 | new_list=$(echo "$new_list" | |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 202 | sed -e '1,/The following NEW packages will be installed:/d;s/^ //;t;d') |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 203 | new_list=$(echo "$new_list" | sed 's/ *$//') |
| 204 | if [ -z "$new_list" ] ; then |
| 205 | echo "No missing packages, and the packages are up-to-date." |
| 206 | else |
| 207 | echo "Installing missing packages: $new_list." |
[email protected] | e2544ed4 | 2012-04-23 04:48:31 | [diff] [blame] | 208 | sudo apt-get install ${do_quietly-} ${new_list} |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 209 | fi |
| 210 | echo |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 211 | else |
| 212 | # An apt-get exit status of 100 indicates that a real error has occurred. |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 213 | |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 214 | # I am intentionally leaving out the '"'s around new_list_cmd, |
| 215 | # as this makes it easier to cut and paste the output |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 216 | echo "The following command failed: " ${new_list_cmd} |
| 217 | echo |
| 218 | echo "It produces the following output:" |
| 219 | yes n | $new_list_cmd || true |
| 220 | echo |
| 221 | echo "You will have to install the above packages yourself." |
| 222 | echo |
| 223 | exit 100 |
| 224 | fi |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 225 | |
| 226 | # Install 32bit backwards compatibility support for 64bit systems |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 227 | if [ "$(uname -m)" = "x86_64" ]; then |
[email protected] | 1eae2bfb | 2010-01-26 18:17:53 | [diff] [blame] | 228 | if test "$do_inst_lib32" != "1" |
| 229 | then |
[email protected] | 4a242bea | 2012-11-07 19:31:52 | [diff] [blame^] | 230 | echo "NOTE: If you were expecting the option to install 32bit libs," |
| 231 | echo "please run with the --lib32 flag." |
| 232 | echo |
| 233 | echo "Installation complete." |
[email protected] | 8ada8c5 | 2009-03-10 21:53:08 | [diff] [blame] | 234 | exit 0 |
| 235 | fi |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 236 | |
[email protected] | 4a242bea | 2012-11-07 19:31:52 | [diff] [blame^] | 237 | echo "WARNING" |
[email protected] | e76a363 | 2012-03-15 20:56:27 | [diff] [blame] | 238 | echo |
[email protected] | 4a242bea | 2012-11-07 19:31:52 | [diff] [blame^] | 239 | echo "We no longer recommend that you use this script to install" |
| 240 | echo "32bit libraries on a 64bit system. Instead, consider using the" |
| 241 | echo "install-chroot.sh script to help you set up a 32bit environment" |
| 242 | echo "for building and testing 32bit versions of Chrome." |
| 243 | echo |
| 244 | echo "The code for installing 32bit libraries on a 64bit system is" |
| 245 | echo "unmaintained and might not work with modern versions of Ubuntu" |
| 246 | echo "or Debian." |
| 247 | echo |
| 248 | echo -n "Are you sure you want to proceed (y/N) " |
| 249 | if yes_no 1; then |
| 250 | do_inst_lib32=1 |
| 251 | fi |
| 252 | if test "$do_inst_lib32" != "1" |
| 253 | exit 0 |
| 254 | fi |
[email protected] | e76a363 | 2012-03-15 20:56:27 | [diff] [blame] | 255 | |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 256 | # Standard 32bit compatibility libraries |
| 257 | echo "First, installing the limited existing 32-bit support..." |
[email protected] | 7cf14b37 | 2011-12-08 18:32:52 | [diff] [blame] | 258 | cmp_list="ia32-libs lib32asound2-dev lib32stdc++6 lib32z1 |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 259 | lib32z1-dev libc6-dev-i386 libc6-i386 g++-multilib" |
[email protected] | 7cf14b37 | 2011-12-08 18:32:52 | [diff] [blame] | 260 | if [ -n "`apt-cache search lib32readline-gplv2-dev 2>/dev/null`" ]; then |
| 261 | cmp_list="${cmp_list} lib32readline-gplv2-dev" |
| 262 | else |
| 263 | cmp_list="${cmp_list} lib32readline5-dev" |
| 264 | fi |
[email protected] | 221569d3 | 2012-05-20 04:55:48 | [diff] [blame] | 265 | sudo apt-get install ${do_quietly-} $cmp_list |
[email protected] | b62f11e7 | 2010-05-03 17:20:45 | [diff] [blame] | 266 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 267 | tmp=/tmp/install-32bit.$$ |
| 268 | trap 'rm -rf "${tmp}"' EXIT INT TERM QUIT |
| 269 | mkdir -p "${tmp}/apt/lists/partial" "${tmp}/cache" "${tmp}/partial" |
| 270 | touch "${tmp}/status" |
| 271 | |
| 272 | [ -r /etc/apt/apt.conf ] && cp /etc/apt/apt.conf "${tmp}/apt/" |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 273 | cat >>"${tmp}/apt/apt.conf" <<EOF |
[email protected] | 79a9d296 | 2009-08-06 21:10:58 | [diff] [blame] | 274 | Apt::Architecture "i386"; |
| 275 | Dir::Cache "${tmp}/cache"; |
| 276 | Dir::Cache::Archives "${tmp}/"; |
| 277 | Dir::State::Lists "${tmp}/apt/lists/"; |
| 278 | Dir::State::status "${tmp}/status"; |
[email protected] | b6e06452 | 2009-08-10 18:47:51 | [diff] [blame] | 279 | EOF |
[email protected] | 1bf2ac97 | 2009-06-30 23:57:48 | [diff] [blame] | 280 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 281 | # Download 32bit packages |
| 282 | echo "Computing list of available 32bit packages..." |
[email protected] | a81e44e1 | 2010-05-17 21:16:53 | [diff] [blame] | 283 | sudo apt-get -c="${tmp}/apt/apt.conf" update |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 284 | |
| 285 | echo "Downloading available 32bit packages..." |
[email protected] | a81e44e1 | 2010-05-17 21:16:53 | [diff] [blame] | 286 | sudo apt-get -c="${tmp}/apt/apt.conf" \ |
| 287 | --yes --download-only --force-yes --reinstall install \ |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 288 | ${lib_list} ${dbg_list} |
| 289 | |
| 290 | # Open packages, remove everything that is not a library, move the |
| 291 | # library to a lib32 directory and package everything as a *.deb file. |
| 292 | echo "Repackaging and installing 32bit packages for use on 64bit systems..." |
| 293 | for i in ${lib_list} ${dbg_list}; do |
| 294 | orig="$(echo "${tmp}/${i}"_*_i386.deb)" |
| 295 | compat="$(echo "${orig}" | |
| 296 | sed -e 's,\(_[^_/]*_\)i386\(.deb\),-ia32\1amd64\2,')" |
| 297 | rm -rf "${tmp}/staging" |
| 298 | msg="$(fakeroot -u sh -exc ' |
| 299 | # Unpack 32bit Debian archive |
| 300 | umask 022 |
| 301 | mkdir -p "'"${tmp}"'/staging/dpkg/DEBIAN" |
| 302 | cd "'"${tmp}"'/staging" |
| 303 | ar x "'${orig}'" |
| 304 | tar zCfx dpkg data.tar.gz |
| 305 | tar zCfx dpkg/DEBIAN control.tar.gz |
| 306 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 307 | # Create a posix extended regular expression fragment that will |
| 308 | # recognize the includes which have changed. Should be rare, |
| 309 | # will almost always be empty. |
| 310 | includes=`sed -n -e "s/^[0-9a-z]* //g" \ |
| 311 | -e "\,usr/include/,p" dpkg/DEBIAN/md5sums | |
| 312 | xargs -n 1 -I FILE /bin/sh -c \ |
| 313 | "cmp -s dpkg/FILE /FILE || echo FILE" | |
| 314 | tr "\n" "|" | |
| 315 | sed -e "s,|$,,"` |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 316 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 317 | # If empty, set it to not match anything. |
| 318 | test -z "$includes" && includes="^//" |
| 319 | |
| 320 | # Turn the conflicts into an extended RE for removal from the |
| 321 | # Provides line. |
| 322 | conflicts=`sed -n -e "/Conflicts/s/Conflicts: *//;T;s/, */|/g;p" \ |
| 323 | dpkg/DEBIAN/control` |
| 324 | |
| 325 | # Rename package, change architecture, remove conflicts and dependencies |
| 326 | sed -r -i \ |
| 327 | -e "/Package/s/$/-ia32/" \ |
| 328 | -e "/Architecture/s/:.*$/: amd64/" \ |
| 329 | -e "/Depends/s/:.*/: ia32-libs/" \ |
| 330 | -e "/Provides/s/($conflicts)(, *)?//g;T1;s/, *$//;:1" \ |
| 331 | -e "/Recommends/d" \ |
| 332 | -e "/Conflicts/d" \ |
| 333 | dpkg/DEBIAN/control |
| 334 | |
| 335 | # Only keep files that live in "lib" directories or the includes |
| 336 | # that have changed. |
| 337 | sed -r -i \ |
| 338 | -e "/\/lib64\//d" -e "/\/.?bin\//d" \ |
| 339 | -e "\,$includes,s,[ /]include/,&32/,g;s,include/32/,include32/,g" \ |
| 340 | -e "s, lib/, lib32/,g" \ |
| 341 | -e "s,/lib/,/lib32/,g" \ |
| 342 | -e "t;d" \ |
| 343 | -e "\,^/usr/lib32/debug\(.*/lib32\),s,^/usr/lib32/debug,/usr/lib/debug," \ |
| 344 | dpkg/DEBIAN/md5sums |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 345 | |
| 346 | # Re-run ldconfig after installation/removal |
| 347 | { echo "#!/bin/sh"; echo "[ \"x\$1\" = xconfigure ]&&ldconfig||:"; } \ |
| 348 | >dpkg/DEBIAN/postinst |
| 349 | { echo "#!/bin/sh"; echo "[ \"x\$1\" = xremove ]&&ldconfig||:"; } \ |
| 350 | >dpkg/DEBIAN/postrm |
| 351 | chmod 755 dpkg/DEBIAN/postinst dpkg/DEBIAN/postrm |
| 352 | |
| 353 | # Remove any other control files |
| 354 | find dpkg/DEBIAN -mindepth 1 "(" -name control -o -name md5sums -o \ |
| 355 | -name postinst -o -name postrm ")" -o -print | |
| 356 | xargs -r rm -rf |
| 357 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 358 | # Remove any files/dirs that live outside of "lib" directories, |
| 359 | # or are not in our list of changed includes. |
| 360 | find dpkg -mindepth 1 -regextype posix-extended \ |
| 361 | "(" -name DEBIAN -o -name lib -o -regex "dpkg/($includes)" ")" \ |
| 362 | -prune -o -print | tac | |
| 363 | xargs -r -n 1 sh -c "rm \$0 2>/dev/null || rmdir \$0 2>/dev/null || : " |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 364 | find dpkg -name lib64 -o -name bin -o -name "?bin" | |
| 365 | tac | xargs -r rm -rf |
| 366 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 367 | # Remove any symbolic links that were broken by the above steps. |
| 368 | find -L dpkg -type l -print | tac | xargs -r rm -rf |
| 369 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 370 | # Rename lib to lib32, but keep debug symbols in /usr/lib/debug/usr/lib32 |
| 371 | # That is where gdb looks for them. |
| 372 | find dpkg -type d -o -path "*/lib/*" -print | |
| 373 | xargs -r -n 1 sh -c " |
| 374 | i=\$(echo \"\${0}\" | |
| 375 | sed -e s,/lib/,/lib32/,g \ |
| 376 | -e s,/usr/lib32/debug\\\\\(.*/lib32\\\\\),/usr/lib/debug\\\\1,); |
| 377 | mkdir -p \"\${i%/*}\"; |
| 378 | mv \"\${0}\" \"\${i}\"" |
| 379 | |
[email protected] | 34799f9d | 2010-07-08 17:51:33 | [diff] [blame] | 380 | # Rename include to include32. |
| 381 | [ -d "dpkg/usr/include" ] && mv "dpkg/usr/include" "dpkg/usr/include32" |
| 382 | |
[email protected] | e041ed1 | 2009-03-10 16:43:01 | [diff] [blame] | 383 | # Prune any empty directories |
| 384 | find dpkg -type d | tac | xargs -r -n 1 rmdir 2>/dev/null || : |
| 385 | |
| 386 | # Create our own Debian package |
| 387 | cd .. |
| 388 | dpkg --build staging/dpkg .' 2>&1)" |
| 389 | compat="$(eval echo $(echo "${compat}" | |
| 390 | sed -e 's,_[^_/]*_amd64.deb,_*_amd64.deb,'))" |
| 391 | [ -r "${compat}" ] || { |
| 392 | echo "${msg}" >&2 |
| 393 | echo "Failed to build new Debian archive!" >&2 |
| 394 | exit 1 |
| 395 | } |
| 396 | |
| 397 | msg="$(sudo dpkg -i "${compat}" 2>&1)" && { |
| 398 | echo "Installed ${compat##*/}" |
| 399 | } || { |
| 400 | # echo "${msg}" >&2 |
| 401 | echo "Skipped ${compat##*/}" |
| 402 | } |
| 403 | done |
| 404 | |
| 405 | # Add symbolic links for developing 32bit code |
| 406 | echo "Adding missing symbolic links, enabling 32bit code development..." |
| 407 | for i in $(find /lib32 /usr/lib32 -maxdepth 1 -name \*.so.\* | |
| 408 | sed -e 's/[.]so[.][0-9].*/.so/' | |
| 409 | sort -u); do |
| 410 | [ "x${i##*/}" = "xld-linux.so" ] && continue |
| 411 | [ -r "$i" ] && continue |
| 412 | j="$(ls "$i."* | sed -e 's/.*[.]so[.]\([^.]*\)$/\1/;t;d' | |
| 413 | sort -n | tail -n 1)" |
| 414 | [ -r "$i.$j" ] || continue |
| 415 | sudo ln -s "${i##*/}.$j" "$i" |
| 416 | done |
| 417 | fi |