Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / installer / linux / debian / build.sh
blobbf84089ec4b71129e502c709931b7b5be7045841
1 #!/bin/bash
3 # Copyright (c) 2012 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 # TODO(mmoss) This currently only works with official builds, since non-official
8 # builds don't add the "${BUILDDIR}/installer/" files needed for packaging.
10 set -e
11 set -o pipefail
12 if [ "$VERBOSE" ]; then
13 set -x
15 set -u
17 # Create the Debian changelog file needed by dpkg-gencontrol. This just adds a
18 # placeholder change, indicating it is the result of an automatic build.
19 # TODO(mmoss) Release packages should create something meaningful for a
20 # changelog, but simply grabbing the actual 'svn log' is way too verbose. Do we
21 # have any type of "significant/visible changes" log that we could use for this?
22 gen_changelog() {
23 rm -f "${DEB_CHANGELOG}"
24 process_template "${SCRIPTDIR}/changelog.template" "${DEB_CHANGELOG}"
25 debchange -a --nomultimaint -m --changelog "${DEB_CHANGELOG}" \
26 "Release Notes: ${RELEASENOTES}"
27 GZLOG="${STAGEDIR}/usr/share/doc/${PACKAGE}-${CHANNEL}/changelog.gz"
28 mkdir -p "$(dirname "${GZLOG}")"
29 gzip -9 -c "${DEB_CHANGELOG}" > "${GZLOG}"
30 chmod 644 "${GZLOG}"
33 # Create the Debian control file needed by dpkg-deb.
34 gen_control() {
35 dpkg-gencontrol -v"${VERSIONFULL}" -c"${DEB_CONTROL}" -l"${DEB_CHANGELOG}" \
36 -f"${DEB_FILES}" -p"${PACKAGE}-${CHANNEL}" -P"${STAGEDIR}" \
37 -O > "${STAGEDIR}/DEBIAN/control"
38 rm -f "${DEB_CONTROL}"
41 # Setup the installation directory hierachy in the package staging area.
42 prep_staging_debian() {
43 prep_staging_common
44 install -m 755 -d "${STAGEDIR}/DEBIAN" \
45 "${STAGEDIR}/etc/cron.daily" \
46 "${STAGEDIR}/usr/share/menu" \
47 "${STAGEDIR}/usr/share/doc/${PACKAGE}"
50 # Put the package contents in the staging area.
51 stage_install_debian() {
52 # Always use a different name for /usr/bin symlink depending on channel.
53 # First, to avoid file collisions. Second, to make it possible to
54 # use update-alternatives for /usr/bin/google-chrome.
55 local USR_BIN_SYMLINK_NAME="${PACKAGE}-${CHANNEL}"
57 if [ "$CHANNEL" != "stable" ]; then
58 # This would ideally be compiled into the app, but that's a bit too
59 # intrusive of a change for these limited use channels, so we'll just hack
60 # it into the wrapper script. The user can still override since it seems to
61 # work to specify --user-data-dir multiple times on the command line, with
62 # the last occurrence winning.
63 local SXS_USER_DATA_DIR="\${XDG_CONFIG_HOME:-\${HOME}/.config}/${PACKAGE}-${CHANNEL}"
64 local DEFAULT_FLAGS="--user-data-dir=\"${SXS_USER_DATA_DIR}\""
66 # Avoid file collisions between channels.
67 local INSTALLDIR="${INSTALLDIR}-${CHANNEL}"
69 local PACKAGE="${PACKAGE}-${CHANNEL}"
71 # Make it possible to distinguish between menu entries
72 # for different channels.
73 local MENUNAME="${MENUNAME} (${CHANNEL})"
75 prep_staging_debian
76 stage_install_common
77 echo "Staging Debian install files in '${STAGEDIR}'..."
78 install -m 755 -d "${STAGEDIR}/${INSTALLDIR}/cron"
79 process_template "${BUILDDIR}/installer/common/repo.cron" \
80 "${STAGEDIR}/${INSTALLDIR}/cron/${PACKAGE}"
81 chmod 755 "${STAGEDIR}/${INSTALLDIR}/cron/${PACKAGE}"
82 pushd "${STAGEDIR}/etc/cron.daily/"
83 ln -snf "${INSTALLDIR}/cron/${PACKAGE}" "${PACKAGE}"
84 popd
85 process_template "${BUILDDIR}/installer/debian/debian.menu" \
86 "${STAGEDIR}/usr/share/menu/${PACKAGE}.menu"
87 chmod 644 "${STAGEDIR}/usr/share/menu/${PACKAGE}.menu"
88 process_template "${BUILDDIR}/installer/debian/postinst" \
89 "${STAGEDIR}/DEBIAN/postinst"
90 chmod 755 "${STAGEDIR}/DEBIAN/postinst"
91 process_template "${BUILDDIR}/installer/debian/prerm" \
92 "${STAGEDIR}/DEBIAN/prerm"
93 chmod 755 "${STAGEDIR}/DEBIAN/prerm"
94 process_template "${BUILDDIR}/installer/debian/postrm" \
95 "${STAGEDIR}/DEBIAN/postrm"
96 chmod 755 "${STAGEDIR}/DEBIAN/postrm"
99 # Actually generate the package file.
100 do_package() {
101 echo "Packaging ${ARCHITECTURE}..."
102 PREDEPENDS="$COMMON_PREDEPS"
103 DEPENDS="${COMMON_DEPS}"
104 REPLACES=""
105 CONFLICTS=""
106 PROVIDES="www-browser"
107 gen_changelog
108 process_template "${SCRIPTDIR}/control.template" "${DEB_CONTROL}"
109 export DEB_HOST_ARCH="${ARCHITECTURE}"
110 if [ -f "${DEB_CONTROL}" ]; then
111 gen_control
113 fakeroot dpkg-deb -Zxz -z9 -b "${STAGEDIR}" .
116 # Remove temporary files and unwanted packaging output.
117 cleanup() {
118 echo "Cleaning..."
119 rm -rf "${STAGEDIR}"
120 rm -rf "${TMPFILEDIR}"
123 usage() {
124 echo "usage: $(basename $0) [-c channel] [-a target_arch] [-o 'dir'] "
125 echo " [-b 'dir'] -d branding"
126 echo "-c channel the package channel (trunk, asan, unstable, beta, stable)"
127 echo "-a arch package architecture (ia32 or x64)"
128 echo "-o dir package output directory [${OUTPUTDIR}]"
129 echo "-b dir build input directory [${BUILDDIR}]"
130 echo "-d brand either chromium or google_chrome"
131 echo "-h this help message"
134 # Check that the channel name is one of the allowable ones.
135 verify_channel() {
136 case $CHANNEL in
137 stable )
138 CHANNEL=stable
139 RELEASENOTES="http://googlechromereleases.blogspot.com/search/label/Stable%20updates"
141 unstable|dev|alpha )
142 CHANNEL=unstable
143 RELEASENOTES="http://googlechromereleases.blogspot.com/search/label/Dev%20updates"
145 testing|beta )
146 CHANNEL=beta
147 RELEASENOTES="http://googlechromereleases.blogspot.com/search/label/Beta%20updates"
149 trunk|asan )
150 # Setting this to empty will prevent it from updating any existing configs
151 # from release packages.
152 REPOCONFIG=""
153 RELEASENOTES="http://googlechromereleases.blogspot.com/"
156 echo
157 echo "ERROR: '$CHANNEL' is not a valid channel type."
158 echo
159 exit 1
161 esac
164 process_opts() {
165 while getopts ":o:b:c:a:d:h" OPTNAME
167 case $OPTNAME in
169 OUTPUTDIR=$(readlink -f "${OPTARG}")
170 mkdir -p "${OUTPUTDIR}"
173 BUILDDIR=$(readlink -f "${OPTARG}")
176 CHANNEL="$OPTARG"
179 TARGETARCH="$OPTARG"
182 BRANDING="$OPTARG"
185 usage
186 exit 0
188 \: )
189 echo "'-$OPTARG' needs an argument."
190 usage
191 exit 1
194 echo "invalid command-line option: $OPTARG"
195 usage
196 exit 1
198 esac
199 done
202 #=========
203 # MAIN
204 #=========
206 SCRIPTDIR=$(readlink -f "$(dirname "$0")")
207 OUTPUTDIR="${PWD}"
208 STAGEDIR=$(mktemp -d -t deb.build.XXXXXX) || exit 1
209 TMPFILEDIR=$(mktemp -d -t deb.tmp.XXXXXX) || exit 1
210 DEB_CHANGELOG="${TMPFILEDIR}/changelog"
211 DEB_FILES="${TMPFILEDIR}/files"
212 DEB_CONTROL="${TMPFILEDIR}/control"
213 CHANNEL="trunk"
214 # Default target architecture to same as build host.
215 if [ "$(uname -m)" = "x86_64" ]; then
216 TARGETARCH="x64"
217 else
218 TARGETARCH="ia32"
221 # call cleanup() on exit
222 trap cleanup 0
223 process_opts "$@"
224 BUILDDIR=${BUILDDIR:=$(readlink -f "${SCRIPTDIR}/../../../../out/Release")}
226 source ${BUILDDIR}/installer/common/installer.include
228 get_version_info
229 VERSIONFULL="${VERSION}-${PACKAGE_RELEASE}"
231 if [ "$BRANDING" = "google_chrome" ]; then
232 source "${BUILDDIR}/installer/common/google-chrome.info"
233 else
234 source "${BUILDDIR}/installer/common/chromium-browser.info"
236 eval $(sed -e "s/^\([^=]\+\)=\(.*\)$/export \1='\2'/" \
237 "${BUILDDIR}/installer/theme/BRANDING")
239 REPOCONFIG="deb http://dl.google.com/linux/chrome/deb/ stable main"
240 SSLREPOCONFIG="deb https://dl.google.com/linux/chrome/deb/ stable main"
241 verify_channel
243 # Some Debian packaging tools want these set.
244 export DEBFULLNAME="${MAINTNAME}"
245 export DEBEMAIL="${MAINTMAIL}"
247 # We'd like to eliminate more of these deps by relying on the 'lsb' package, but
248 # that brings in tons of unnecessary stuff, like an mta and rpm. Until that full
249 # 'lsb' package is installed by default on DEB distros, we'll have to stick with
250 # the LSB sub-packages, to avoid pulling in all that stuff that's not installed
251 # by default.
253 # Need a dummy debian/control file for dpkg-shlibdeps.
254 DUMMY_STAGING_DIR="${TMPFILEDIR}/dummy_staging"
255 mkdir "$DUMMY_STAGING_DIR"
256 cd "$DUMMY_STAGING_DIR"
257 mkdir debian
258 touch debian/control
260 # Generate the dependencies,
261 # TODO(mmoss): This is a workaround for a problem where dpkg-shlibdeps was
262 # resolving deps using some of our build output shlibs (i.e.
263 # out/Release/lib.target/libfreetype.so.6), and was then failing with:
264 # dpkg-shlibdeps: error: no dependency information found for ...
265 # It's not clear if we ever want to look in LD_LIBRARY_PATH to resolve deps,
266 # but it seems that we don't currently, so this is the most expediant fix.
267 SAVE_LDLP=${LD_LIBRARY_PATH:-}
268 unset LD_LIBRARY_PATH
269 DPKG_SHLIB_DEPS=$(dpkg-shlibdeps -O "$BUILDDIR/chrome" | \
270 sed 's/^shlibs:Depends=//')
271 if [ -n "$SAVE_LDLP" ]; then
272 LD_LIBRARY_PATH=$SAVE_LDLP
275 # Format it nicely and save it for comparison.
276 # The grep -v is for a duplicate libc6 dep caused by Lucid glibc silliness.
277 echo "$DPKG_SHLIB_DEPS" | sed 's/, /\n/g' | \
278 grep -v '^libc6 (>= 2.3.6-6~)$' > actual
280 # Compare the expected dependency list to the generate list.
281 BAD_DIFF=0
282 diff "$SCRIPTDIR/expected_deps_$TARGETARCH" actual || BAD_DIFF=1
283 if [ $BAD_DIFF -ne 0 ] && [ -z "${IGNORE_DEPS_CHANGES:-}" ]; then
284 echo
285 echo "ERROR: Shared library dependencies changed!"
286 echo "If this is intentional, please update:"
287 echo "chrome/installer/linux/debian/expected_deps_ia32"
288 echo "chrome/installer/linux/debian/expected_deps_x64"
289 echo
290 exit $BAD_DIFF
292 rm -rf "$DUMMY_STAGING_DIR"
294 # Additional dependencies not in the dpkg-shlibdeps output.
295 # - Pull a more recent version of NSS than required by runtime linking, for
296 # security and stability updates in NSS.
297 ADDITION_DEPS="ca-certificates, fonts-liberation, libappindicator1, libcurl3, \
298 libnss3 (>= 3.14.3), lsb-base (>=3.2), xdg-utils (>= 1.0.2), wget"
300 # Fix-up libnspr dependency due to renaming in Ubuntu (the old package still
301 # exists, but it was moved to "universe" repository, which isn't installed by
302 # default).
303 DPKG_SHLIB_DEPS=$(sed \
304 's/\(libnspr4-0d ([^)]*)\), /\1 | libnspr4 (>= 4.9.5-0ubuntu0), /g' \
305 <<< $DPKG_SHLIB_DEPS)
307 COMMON_DEPS="${DPKG_SHLIB_DEPS}, ${ADDITION_DEPS}"
308 COMMON_PREDEPS="dpkg (>= 1.14.0)"
311 # Make everything happen in the OUTPUTDIR.
312 cd "${OUTPUTDIR}"
314 case "$TARGETARCH" in
315 ia32 )
316 export ARCHITECTURE="i386"
317 stage_install_debian
319 x64 )
320 export ARCHITECTURE="amd64"
321 stage_install_debian
324 echo
325 echo "ERROR: Don't know how to build DEBs for '$TARGETARCH'."
326 echo
327 exit 1
329 esac
331 do_package