installer.include revision 868fa2fe829687343ffae624259930155e16dbd8
1# Recursively replace @@include@@ template variables with the referenced file,
2# and write the resulting text to stdout.
3process_template_includes() {
4  INCSTACK+="$1->"
5  # Includes are relative to the file that does the include.
6  INCDIR=$(dirname $1)
7  # Clear IFS so 'read' doesn't trim whitespace
8  local OLDIFS="$IFS"
9  IFS=''
10  while read -r LINE
11  do
12    INCLINE=$(sed -e '/^[[:space:]]*@@include@@/!d' <<<$LINE)
13    if [ -n "$INCLINE" ]; then
14      INCFILE=$(echo $INCLINE | sed -e "s#@@include@@\(.*\)#\1#")
15      # Simple filename match to detect cyclic includes.
16      CYCLE=$(sed -e "\#$INCFILE#"'!d' <<<$INCSTACK)
17      if [ "$CYCLE" ]; then
18        echo "ERROR: Possible cyclic include detected." 1>&2
19        echo "$INCSTACK$INCFILE" 1>&2
20        exit 1
21      fi
22      if [ ! -r "$INCDIR/$INCFILE" ]; then
23        echo "ERROR: Couldn't read include file: $INCDIR/$INCFILE" 1>&2
24        exit 1
25      fi
26      process_template_includes "$INCDIR/$INCFILE"
27    else
28      echo "$LINE"
29    fi
30  done < "$1"
31  IFS="$OLDIFS"
32  INCSTACK=${INCSTACK%"$1->"}
33}
34
35# Replace template variables (@@VARNAME@@) in the given template file. If a
36# second argument is given, save the processed text to that filename, otherwise
37# modify the template file in place.
38process_template() (
39  # Don't worry if some of these substitution variables aren't set.
40  # Note that this function is run in a sub-shell so we don't leak this
41  # setting, since we still want unbound variables to be an error elsewhere.
42  set +u
43
44  local TMPLIN="$1"
45  if [ -z "$2" ]; then
46    local TMPLOUT="$TMPLIN"
47  else
48    local TMPLOUT="$2"
49  fi
50  # Process includes first so included text also gets substitutions.
51  TMPLINCL="$(process_template_includes "$TMPLIN")"
52  sed \
53    -e "s#@@PACKAGE@@#${PACKAGE}#g" \
54    -e "s#@@PACKAGE_FILENAME@@#${PACKAGE_FILENAME}#g" \
55    -e "s#@@PROGNAME@@#${PROGNAME}#g" \
56    -e "s#@@CHANNEL@@#${CHANNEL}#g" \
57    -e "s#@@COMPANY_FULLNAME@@#${COMPANY_FULLNAME}#g" \
58    -e "s#@@VERSION@@#${VERSION}#g" \
59    -e "s#@@REVISION@@#${REVISION}#g" \
60    -e "s#@@VERSIONFULL@@#${VERSIONFULL}#g" \
61    -e "s#@@INSTALLDIR@@#${INSTALLDIR}#g" \
62    -e "s#@@BUILDDIR@@#${BUILDDIR}#g" \
63    -e "s#@@STAGEDIR@@#${STAGEDIR}#g" \
64    -e "s#@@SCRIPTDIR@@#${SCRIPTDIR}#g" \
65    -e "s#@@MENUNAME@@#${MENUNAME}#g" \
66    -e "s#@@PRODUCTURL@@#${PRODUCTURL}#g" \
67    -e "s#@@PREDEPENDS@@#${PREDEPENDS}#g" \
68    -e "s#@@DEPENDS@@#${DEPENDS}#g" \
69    -e "s#@@PROVIDES@@#${PROVIDES}#g" \
70    -e "s#@@REPLACES@@#${REPLACES}#g" \
71    -e "s#@@CONFLICTS@@#${CONFLICTS}#g" \
72    -e "s#@@ARCHITECTURE@@#${ARCHITECTURE}#g" \
73    -e "s#@@MAINTNAME@@#${MAINTNAME}#g" \
74    -e "s#@@MAINTMAIL@@#${MAINTMAIL}#g" \
75    -e "s#@@REPOCONFIG@@#${REPOCONFIG}#g" \
76    -e "s#@@SHORTDESC@@#${SHORTDESC}#g" \
77    -e "s#@@FULLDESC@@#${FULLDESC}#g" \
78    -e "s#@@DEFAULT_FLAGS@@#${DEFAULT_FLAGS:-}#g" \
79    > "$TMPLOUT" <<< "$TMPLINCL"
80)
81
82# Setup the installation directory hierachy in the package staging area.
83prep_staging_common() {
84  install -m 755 -d "${STAGEDIR}/${INSTALLDIR}" \
85    "${STAGEDIR}/usr/bin" \
86    "${STAGEDIR}/usr/share/applications" \
87    "${STAGEDIR}/usr/share/gnome-control-center/default-apps" \
88    "${STAGEDIR}/usr/share/man/man1"
89}
90
91get_version_info() {
92  # Default to a bogus low version, so if somebody creates and installs
93  # a package with no version info, it won't prevent upgrading when
94  # trying to install a properly versioned package (i.e. a proper
95  # package will always be "newer").
96  VERSION="0.0.0.0"
97  # Use epoch timestamp so packages with bogus versions still increment
98  # and will upgrade older bogus-versioned packages.
99  REVISION=$(date +"%s")
100  # Default to non-official build since official builds set this
101  # properly.
102  OFFICIAL_BUILD=0
103
104  VERSIONFILE="${BUILDDIR}/installer/version.txt"
105  if [ -f "${VERSIONFILE}" ]; then
106    source "${VERSIONFILE}"
107    VERSION="${MAJOR}.${MINOR}.${BUILD}.${PATCH}"
108    REVISION="${LASTCHANGE}"
109  fi
110}
111
112stage_install_common() {
113  echo "Staging common install files in '${STAGEDIR}'..."
114
115  # TODO(mmoss) This assumes we built the static binaries. To support shared
116  # builds, we probably want an install target in scons so it can give us all
117  # the right files. See also:
118  # http://code.google.com/p/chromium/issues/detail?id=4451
119  #
120  # app
121  # We need to add the debug link so gdb knows to look for the symbols.
122  DEBUGFILE="${BUILDDIR}/${PROGNAME}.debug"
123  STRIPPEDFILE="${BUILDDIR}/${PROGNAME}.stripped"
124  eu-strip -o "${STRIPPEDFILE}" -f "${DEBUGFILE}" "${BUILDDIR}/${PROGNAME}"
125  install -m 755 "${STRIPPEDFILE}" "${STAGEDIR}/${INSTALLDIR}/${PROGNAME}"
126  rm "${DEBUGFILE}" "${STRIPPEDFILE}"
127
128  # resources
129  install -m 644 "${BUILDDIR}/${PROGNAME}.pak" "${STAGEDIR}/${INSTALLDIR}/"
130  install -m 644 "${BUILDDIR}/resources.pak" "${STAGEDIR}/${INSTALLDIR}/"
131  # TODO(mmoss): This has broken a couple times on adding new .pak files. Maybe
132  # we should flag all installer files in FILES.cfg and get them from there, so
133  # there's only one place people need to keep track of such things (and in
134  # only the public repository).
135  if [ -r "${BUILDDIR}/chrome_100_percent.pak" ]; then
136    install -m 644 "${BUILDDIR}/chrome_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/"
137  else
138    install -m 644 "${BUILDDIR}/theme_resources_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/"
139    install -m 644 "${BUILDDIR}/ui_resources_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/"
140  fi
141
142  # sandbox
143  # Rename sandbox binary with hyphen instead of underscore because that's what
144  # the code looks for, but the build targets can't use hyphens (scons bug?)
145  install -m 4755 -s "${BUILDDIR}/${PROGNAME}_sandbox" \
146    "${STAGEDIR}/${INSTALLDIR}/${PROGNAME}-sandbox"
147
148  # l10n paks
149  cp -a "${BUILDDIR}/locales" "${STAGEDIR}/${INSTALLDIR}/"
150  find "${STAGEDIR}/${INSTALLDIR}/locales" -type f -exec chmod 644 '{}' \;
151  find "${STAGEDIR}/${INSTALLDIR}/locales" -type d -exec chmod 755 '{}' \;
152
153  # ffmpeg libs
154  install -m 644 -s "${BUILDDIR}/libffmpegsumo.so" "${STAGEDIR}/${INSTALLDIR}/"
155
156  # Widevine CDM.
157  if [ -f "${BUILDDIR}/libwidevinecdmadapter.so" ]; then
158    install -m 644 -s "${BUILDDIR}/libwidevinecdmadapter.so" "${STAGEDIR}/${INSTALLDIR}/"
159    install -m 644 "${BUILDDIR}/libwidevinecdm.so" "${STAGEDIR}/${INSTALLDIR}/"
160  fi
161
162  # Pepper Flash.
163  PEPPERFLASH_SRCDIR="${BUILDDIR}/PepperFlash"
164  PEPPERFLASH_DESTDIR="${STAGEDIR}/${INSTALLDIR}/PepperFlash"
165  install -m 755 -d "${PEPPERFLASH_DESTDIR}"
166  install -m 644 -s "${PEPPERFLASH_SRCDIR}/libpepflashplayer.so" \
167    "${PEPPERFLASH_DESTDIR}/"
168  install -m 644 "${PEPPERFLASH_SRCDIR}/manifest.json" \
169    "${PEPPERFLASH_DESTDIR}/"
170
171  # pdf plugin
172  if [ -f "${BUILDDIR}/libpdf.so" ]; then
173    install -m 644 -s "${BUILDDIR}/libpdf.so" "${STAGEDIR}/${INSTALLDIR}/"
174  fi
175
176  # peerconnection shared library
177  if [ -f "${BUILDDIR}/lib/libpeerconnection.so" ]; then
178    install -m 755 -d "${STAGEDIR}/${INSTALLDIR}/lib/"
179    install -m 644 -s "${BUILDDIR}/lib/libpeerconnection.so" "${STAGEDIR}/${INSTALLDIR}/lib/"
180  fi
181
182  # nacl pepper plugin
183  if [ -f "${BUILDDIR}/libppGoogleNaClPluginChrome.so" ]; then
184    install -m 644 -s "${BUILDDIR}/libppGoogleNaClPluginChrome.so" "${STAGEDIR}/${INSTALLDIR}/"
185  fi
186
187  # nacl_helper and nacl_helper_bootstrap
188  # Don't use "-s" (strip) because this runs binutils "strip", which
189  # mangles the special ELF program headers of nacl_helper_bootstrap.
190  # Explicitly use eu-strip instead, because it doesn't have that problem.
191  for file in nacl_helper nacl_helper_bootstrap; do
192    buildfile="${BUILDDIR}/${file}"
193    if [ -f "${buildfile}" ]; then
194      strippedfile="${buildfile}.stripped"
195      debugfile="${buildfile}.debug"
196      eu-strip -o "${strippedfile}" -f "${debugfile}" "${buildfile}"
197      install -m 755 "${strippedfile}" "${STAGEDIR}/${INSTALLDIR}/${file}"
198    fi
199  done
200  # Don't use "-s" (strip) because this would use the Linux toolchain to
201  # strip the NaCl binary, which has the potential to break it.  It
202  # certainly resets the OSABI and ABIVERSION fields to non-NaCl values,
203  # although the NaCl IRT loader doesn't care about these fields.  In any
204  # case, the IRT binaries are already stripped by NaCl's build process.
205  for filename in ${BUILDDIR}/nacl_irt_*.nexe; do
206    # Re-check the filename in case globbing matched nothing.
207    if [ -f "$filename" ]; then
208      install -m 644 "$filename" "${STAGEDIR}/${INSTALLDIR}/`basename "$filename"`"
209    fi
210  done
211
212  # default apps
213  if [ -d "${BUILDDIR}/default_apps" ]; then
214    cp -a "${BUILDDIR}/default_apps" "${STAGEDIR}/${INSTALLDIR}/"
215    find "${STAGEDIR}/${INSTALLDIR}/default_apps" -type d -exec chmod 755 '{}' \;
216    find "${STAGEDIR}/${INSTALLDIR}/default_apps" -type f -exec chmod 644 '{}' \;
217  fi
218
219  # launcher script and symlink
220  process_template "${BUILDDIR}/installer/common/wrapper" \
221    "${STAGEDIR}/${INSTALLDIR}/${PACKAGE}"
222  chmod 755 "${STAGEDIR}/${INSTALLDIR}/${PACKAGE}"
223  pushd "${STAGEDIR}/usr/bin/"
224  ln -snf "${INSTALLDIR}/${PACKAGE}" "${PACKAGE}"
225  popd
226
227  # app icons
228  install -m 644 \
229    "${BUILDDIR}/installer/theme/product_logo_"*.png \
230    "${BUILDDIR}/installer/theme/product_logo_32.xpm" \
231    "${STAGEDIR}/${INSTALLDIR}/"
232
233  # desktop integration
234  install -m 755 "${BUILDDIR}/xdg-mime" "${STAGEDIR}${INSTALLDIR}/"
235  install -m 755 "${BUILDDIR}/xdg-settings" "${STAGEDIR}${INSTALLDIR}/"
236  process_template "${BUILDDIR}/installer/common/desktop.template" \
237    "${STAGEDIR}/${INSTALLDIR}/${PACKAGE}.desktop"
238  chmod 644 "${STAGEDIR}/${INSTALLDIR}/${PACKAGE}.desktop"
239  process_template "${BUILDDIR}/installer/common/default-app.template" \
240    "${STAGEDIR}/usr/share/gnome-control-center/default-apps/${PACKAGE}.xml"
241  chmod 644 "${STAGEDIR}/usr/share/gnome-control-center/default-apps/${PACKAGE}.xml"
242  process_template "${BUILDDIR}/installer/common/default-app-block.template" \
243    "${STAGEDIR}${INSTALLDIR}/default-app-block"
244  chmod 644 "${STAGEDIR}${INSTALLDIR}/default-app-block"
245
246  # documentation
247  install -m 755 "${BUILDDIR}/${PROGNAME}.1" \
248    "${STAGEDIR}/usr/share/man/man1/${PACKAGE}.1"
249}
250