1868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#!/bin/bash
2868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#
3868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Copyright (c) 2012 The Chromium Authors. All rights reserved.
4868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Use of this source code is governed by a BSD-style license that can be
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# found in the LICENSE file.
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# TODO(mmoss) This currently only works with official builds, since non-official
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# builds don't add the "${BUILDDIR}/installer/" files needed for packaging.
9868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)set -e
11868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)if [ "$VERBOSE" ]; then
12868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  set -x
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)fi
14868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)set -u
15868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
16868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)gen_spec() {
17868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  rm -f "${SPEC}"
18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # Trunk packages need to install to a custom path so they don't conflict with
19868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # release channel packages.
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  local PACKAGE_FILENAME="${PACKAGE}"
21f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  if [ "$CHANNEL" != "stable" ]; then
22868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    local INSTALLDIR="${INSTALLDIR}-${CHANNEL}"
23868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    PACKAGE_FILENAME="${PACKAGE}-${CHANNEL}"
24868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    local MENUNAME="${MENUNAME} (${CHANNEL})"
25868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  fi
26868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  process_template "${SCRIPTDIR}/chrome.spec.template" "${SPEC}"
27868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
29868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Setup the installation directory hierachy in the package staging area.
30868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)prep_staging_rpm() {
31868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  prep_staging_common
32868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  install -m 755 -d "${STAGEDIR}/etc/cron.daily"
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
34868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
35868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Put the package contents in the staging area.
36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)stage_install_rpm() {
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  # TODO(phajdan.jr): Deduplicate this and debian/build.sh .
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  # For now duplication is going to help us avoid merge conflicts
394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  # as changes are frequently merged to older branches related to SxS effort.
404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  if [ "$CHANNEL" != "stable" ]; then
41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    # This would ideally be compiled into the app, but that's a bit too
42868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    # intrusive of a change for these limited use channels, so we'll just hack
43868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    # it into the wrapper script. The user can still override since it seems to
44868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    # work to specify --user-data-dir multiple times on the command line, with
45868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    # the last occurrence winning.
464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    local SXS_USER_DATA_DIR="\${XDG_CONFIG_HOME:-\${HOME}/.config}/${PACKAGE}-${CHANNEL}"
474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    local DEFAULT_FLAGS="--user-data-dir=\"${SXS_USER_DATA_DIR}\""
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    # Avoid file collisions between channels.
50f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    local PACKAGE="${PACKAGE}-${CHANNEL}"
51f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    local INSTALLDIR="${INSTALLDIR}-${CHANNEL}"
524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    # Make it possible to distinguish between menu entries
544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    # for different channels.
55868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    local MENUNAME="${MENUNAME} (${CHANNEL})"
56868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  fi
57868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  prep_staging_rpm
58868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  stage_install_common
59868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "Staging RPM install files in '${STAGEDIR}'..."
60868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  process_template "${BUILDDIR}/installer/common/rpmrepo.cron" \
61868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "${STAGEDIR}/etc/cron.daily/${PACKAGE}"
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  chmod 755 "${STAGEDIR}/etc/cron.daily/${PACKAGE}"
63868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
64868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
65868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Actually generate the package file.
66868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)do_package() {
67868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "Packaging ${ARCHITECTURE}..."
68868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PROVIDES="${PACKAGE}"
69868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  local REPS="$REPLACES"
70868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  REPLACES=""
71868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  for rep in $REPS; do
72868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    if [ -z "$REPLACES" ]; then
73868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      REPLACES="$PACKAGE-$rep"
74868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    else
75868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      REPLACES="$REPLACES $PACKAGE-$rep"
76868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    fi
77868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  done
78868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
79868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # The symbols in libX11.so are not versioned, so when a newer version has new
80868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # symbols like _XGetRequest, RPM's find-requires tool does not detect it, and
81868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # there is no way to specify a libX11.so version number to prevent
82868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # installation on affected distros like OpenSUSE 12.1 and Fedora 16.
83868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # Thus there has to be distro-specific conflict here.
84868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # TODO(thestig) Remove these in the future when other requirements prevent
85868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # installation on affected distros.
86868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ADDITIONAL_CONFLICTS="xorg-x11-libX11 < 7.6_1 libX11 < 1.4.99"
87868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  REPLACES="$REPLACES $ADDITIONAL_CONFLICTS"
88868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
89868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # If we specify a dependecy of foo.so below, we would depend on both the
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # 32 and 64-bit versions on a 64-bit machine. The current version of RPM
91868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # we use is too old and doesn't provide %{_isa}, so we do this manually.
92868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if [ "$ARCHITECTURE" = "x86_64" ] ; then
93868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    local EMPTY_VERSION="()"
94868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    local PKG_ARCH="(64bit)"
95868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  elif [ "$ARCHITECTURE" = "i386" ] ; then
96868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    local EMPTY_VERSION=""
97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    local PKG_ARCH=""
98868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  fi
99868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
100868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # Use find-requires script to make sure the dependencies are complete
101effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  # (especially libc and libstdc++ versions).
102effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  # - Filter out udev to avoid libudev.so.0 vs. libudev.so.1 mismatches.
103868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DETECTED_DEPENDS="$(echo "${BUILDDIR}/chrome" | /usr/lib/rpm/find-requires |
104e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch      grep -v udev)"
105868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
106868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # Compare the expected dependency list to the generated list.
107868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  BAD_DIFF=0
108868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  diff "$SCRIPTDIR/expected_deps_$ARCHITECTURE" \
109868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      <(echo "${DETECTED_DEPENDS}") || BAD_DIFF=1
110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  if [ $BAD_DIFF -ne 0 ] && [ -z "${IGNORE_DEPS_CHANGES:-}" ]; then
111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo "ERROR: Shared library dependencies changed!"
113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo "If this is intentional, please update:"
114f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    echo "chrome/installer/linux/rpm/expected_deps_i386"
115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo "chrome/installer/linux/rpm/expected_deps_x86_64"
116868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo
117868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    exit $BAD_DIFF
118868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  fi
119868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
120868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # libgdk_pixbuf is added in LSB 3.2 and no longer explicitly required.
121868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # libcairo, libpangocairo, libasound are in LSB 4. and no longer explicitly
122868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # required.
123868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # xdg-utils is still optional in LSB 4.0.
124868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # nss (bundled) is optional in LSB 4.0.
125868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  #
126868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # We want to depend on the system SSL certs so wget can upload crash reports
127868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # securely, but there's no common capability between the distros. Bugs filed:
128868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # https://qa.mandriva.com/show_bug.cgi?id=55714
129868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # https://bugzilla.redhat.com/show_bug.cgi?id=538158
130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # https://bugzilla.novell.com/show_bug.cgi?id=556248
131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  DEPENDS="lsb >= 4.0, \
132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  libcurl.so.4${EMPTY_VERSION}${PKG_ARCH}, \
133bb1529ce867d8845a77ec7cdf3e3003ef1771a40Ben Murdoch  libnss3.so(NSS_3.14.3)${PKG_ARCH}, \
134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  wget, \
135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  xdg-utils, \
136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  zlib, \
137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  $(echo "${DETECTED_DEPENDS}" | tr '\n' ',')"
138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  gen_spec
139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # Create temporary rpmbuild dirs.
141868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  RPMBUILD_DIR=$(mktemp -d -t rpmbuild.XXXXXX) || exit 1
142868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  mkdir -p "$RPMBUILD_DIR/BUILD"
143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  mkdir -p "$RPMBUILD_DIR/RPMS"
144868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
145868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # '__os_install_post ${nil}' disables a bunch of automatic post-processing
146868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # (brp-compress, etc.), which by default appears to only be enabled on 32-bit,
147868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # and which doesn't gain us anything since we already explicitly do all the
148868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # compression, symbol stripping, etc. that we want.
149868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  fakeroot rpmbuild -bb --target="$ARCHITECTURE" --rmspec \
150868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    --define "_topdir $RPMBUILD_DIR" \
151868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    --define "_binary_payload w9.bzdio" \
152868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    --define "__os_install_post  %{nil}" \
153868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    "${SPEC}"
154eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PKGNAME="${PACKAGE}-${CHANNEL}-${VERSION}-${PACKAGE_RELEASE}"
155868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  mv "$RPMBUILD_DIR/RPMS/$ARCHITECTURE/${PKGNAME}.${ARCHITECTURE}.rpm" \
156868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)     "${OUTPUTDIR}"
157868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # Make sure the package is world-readable, otherwise it causes problems when
158868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  # copied to share drive.
159868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  chmod a+r "${OUTPUTDIR}/${PKGNAME}.$ARCHITECTURE.rpm"
160868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  rm -rf "$RPMBUILD_DIR"
161868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
162868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
163868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Remove temporary files and unwanted packaging output.
164868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)cleanup() {
165868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  rm -rf "${STAGEDIR}"
166868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  rm -rf "${TMPFILEDIR}"
167868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
168868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
169868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)usage() {
170868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "usage: $(basename $0) [-c channel] [-a target_arch] [-o 'dir']"
171868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "                      [-b 'dir']"
172868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "-c channel the package channel (trunk, asan, unstable, beta, stable)"
173868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "-a arch    package architecture (ia32 or x64)"
174868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "-o dir     package output directory [${OUTPUTDIR}]"
175868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "-b dir     build input directory    [${BUILDDIR}]"
176868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  echo "-h         this help message"
177868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
178868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
179868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Check that the channel name is one of the allowable ones.
180868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)verify_channel() {
181868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  case $CHANNEL in
182868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    stable )
183868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      CHANNEL=stable
184f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      # TODO(phajdan.jr): Remove REPLACES completely.
185f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      REPLACES="dummy"
186868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ;;
187868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    unstable|dev|alpha )
188868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      CHANNEL=unstable
189f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      # TODO(phajdan.jr): Remove REPLACES completely.
190f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      REPLACES="dummy"
191868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ;;
192868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    testing|beta )
193868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      CHANNEL=beta
194f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      # TODO(phajdan.jr): Remove REPLACES completely.
195f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      REPLACES="dummy"
196868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ;;
197868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    trunk|asan )
198868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      # This is a special package, mostly for development testing, so don't make
199868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      # it replace any installed release packages.
200f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)      # TODO(phajdan.jr): Remove REPLACES completely.
201868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      REPLACES="dummy"
202868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      # Setting this to empty will prevent it from updating any existing configs
203868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      # from release packages.
204868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      REPOCONFIG=""
205868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ;;
206868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    * )
207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      echo
208868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      echo "ERROR: '$CHANNEL' is not a valid channel type."
209868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      echo
210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      exit 1
211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      ;;
212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  esac
213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)process_opts() {
216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  while getopts ":o:b:c:a:h" OPTNAME
217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  do
218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    case $OPTNAME in
219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      o )
220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        OUTPUTDIR=$(readlink -f "${OPTARG}")
221868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        mkdir -p "${OUTPUTDIR}"
222868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ;;
223868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      b )
224868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        BUILDDIR=$(readlink -f "${OPTARG}")
225868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ;;
226868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      c )
227868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        CHANNEL="$OPTARG"
228868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        verify_channel
229868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ;;
230868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      a )
231868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        TARGETARCH="$OPTARG"
232868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ;;
233868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      h )
234868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        usage
235868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        exit 0
236868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ;;
237868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      \: )
238868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        echo "'-$OPTARG' needs an argument."
239868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        usage
240868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        exit 1
241868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ;;
242868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      * )
243868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        echo "invalid command-line option: $OPTARG"
244868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        usage
245868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        exit 1
246868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        ;;
247868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    esac
248868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  done
249868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)}
250868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
251868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#=========
252868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# MAIN
253868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#=========
254868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
255868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)SCRIPTDIR=$(readlink -f "$(dirname "$0")")
256868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)OUTPUTDIR="${PWD}"
257868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)STAGEDIR=$(mktemp -d -t rpm.build.XXXXXX) || exit 1
258868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)TMPFILEDIR=$(mktemp -d -t rpm.tmp.XXXXXX) || exit 1
259868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)CHANNEL="trunk"
260868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Default target architecture to same as build host.
261868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)if [ "$(uname -m)" = "x86_64" ]; then
262868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TARGETARCH="x64"
263868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)else
264868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  TARGETARCH="ia32"
265868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)fi
266868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)SPEC="${TMPFILEDIR}/chrome.spec"
267868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
268868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# call cleanup() on exit
269868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)trap cleanup 0
270868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)process_opts "$@"
2715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)BUILDDIR=${BUILDDIR:=$(readlink -f "${SCRIPTDIR}/../../../../out/Release")}
272868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
273868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)source ${BUILDDIR}/installer/common/installer.include
274868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
275868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)get_version_info
276868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
277868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)if [ "$CHROMIUM_BUILD" = "_google_chrome" ]; then
278868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  source "${BUILDDIR}/installer/common/google-chrome.info"
279868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)else
280868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  source "${BUILDDIR}/installer/common/chromium-browser.info"
281868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)fi
282868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)eval $(sed -e "s/^\([^=]\+\)=\(.*\)$/export \1='\2'/" \
283868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  "${BUILDDIR}/installer/theme/BRANDING")
284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
285868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)REPOCONFIG="http://dl.google.com/linux/${PACKAGE#google-}/rpm/stable"
286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)verify_channel
2874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)export USR_BIN_SYMLINK_NAME="${PACKAGE}-${CHANNEL}"
288868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
289868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)# Make everything happen in the OUTPUTDIR.
290868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)cd "${OUTPUTDIR}"
291868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
292868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)case "$TARGETARCH" in
293868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  ia32 )
294868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    export ARCHITECTURE="i386"
295868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    stage_install_rpm
296868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ;;
297868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  x64 )
298868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    export ARCHITECTURE="x86_64"
299868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    stage_install_rpm
300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ;;
301868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  * )
302868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo
303868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo "ERROR: Don't know how to build RPMs for '$TARGETARCH'."
304868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    echo
305868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    exit 1
306868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    ;;
307868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)esac
308868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
309868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)do_package
310