1 # Recursively replace @@include@@ template variables with the referenced file, 2 # and write the resulting text to stdout. 3 process_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. 38 process_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#@@PACKAGE_RELEASE@@#${PACKAGE_RELEASE}#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 -e "s#@@SXS_USER_DATA_DIR@@#${SXS_USER_DATA_DIR:-}#g" \ 80 -e "s#@@USR_BIN_SYMLINK_NAME@@#${USR_BIN_SYMLINK_NAME:-}#g" \ 81 > "$TMPLOUT" <<< "$TMPLINCL" 82 ) 83 84 # Setup the installation directory hierachy in the package staging area. 85 prep_staging_common() { 86 install -m 755 -d "${STAGEDIR}/${INSTALLDIR}" \ 87 "${STAGEDIR}/usr/bin" \ 88 "${STAGEDIR}/usr/share/applications" \ 89 "${STAGEDIR}/usr/share/gnome-control-center/default-apps" \ 90 "${STAGEDIR}/usr/share/man/man1" 91 } 92 93 get_version_info() { 94 source "${BUILDDIR}/installer/version.txt" 95 VERSION="${MAJOR}.${MINOR}.${BUILD}.${PATCH}" 96 # TODO(phajdan.jr): Provide a mechanism to pass a different package 97 # release number if needed. The meaning of it is to bump it for 98 # packaging-only changes while the underlying software has the same version. 99 # This corresponds to the Release field in RPM spec files and debian_revision 100 # component of the Version field for DEB control file. 101 # Generally with Chrome's fast release cycle it'd be more hassle to try 102 # to bump this number between releases. 103 PACKAGE_RELEASE="1" 104 } 105 106 stage_install_common() { 107 echo "Staging common install files in '${STAGEDIR}'..." 108 109 # TODO(mmoss) This assumes we built the static binaries. To support shared 110 # builds, we probably want an install target in scons so it can give us all 111 # the right files. See also: 112 # http://code.google.com/p/chromium/issues/detail?id=4451 113 # 114 # app 115 # We need to add the debug link so gdb knows to look for the symbols. 116 DEBUGFILE="${BUILDDIR}/${PROGNAME}.debug" 117 STRIPPEDFILE="${BUILDDIR}/${PROGNAME}.stripped" 118 eu-strip -o "${STRIPPEDFILE}" -f "${DEBUGFILE}" "${BUILDDIR}/${PROGNAME}" 119 install -m 755 "${STRIPPEDFILE}" "${STAGEDIR}/${INSTALLDIR}/${PROGNAME}" 120 rm "${DEBUGFILE}" "${STRIPPEDFILE}" 121 122 # resources 123 install -m 644 "${BUILDDIR}/resources.pak" "${STAGEDIR}/${INSTALLDIR}/" 124 # TODO(mmoss): This has broken a couple times on adding new .pak files. Maybe 125 # we should flag all installer files in FILES.cfg and get them from there, so 126 # there's only one place people need to keep track of such things (and in 127 # only the public repository). 128 if [ -r "${BUILDDIR}/chrome_100_percent.pak" ]; then 129 install -m 644 "${BUILDDIR}/chrome_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/" 130 else 131 install -m 644 "${BUILDDIR}/theme_resources_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/" 132 install -m 644 "${BUILDDIR}/ui_resources_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/" 133 fi 134 135 # sandbox 136 # Rename sandbox binary with hyphen instead of underscore because that's what 137 # the code looks for, but the build targets can't use hyphens (scons bug?) 138 install -m 4755 -s "${BUILDDIR}/${PROGNAME}_sandbox" \ 139 "${STAGEDIR}/${INSTALLDIR}/${PROGNAME}-sandbox" 140 141 # l10n paks 142 cp -a "${BUILDDIR}/locales" "${STAGEDIR}/${INSTALLDIR}/" 143 find "${STAGEDIR}/${INSTALLDIR}/locales" -type f -exec chmod 644 '{}' \; 144 find "${STAGEDIR}/${INSTALLDIR}/locales" -type d -exec chmod 755 '{}' \; 145 146 # ffmpeg libs 147 install -m 644 -s "${BUILDDIR}/libffmpegsumo.so" "${STAGEDIR}/${INSTALLDIR}/" 148 149 # Widevine CDM. 150 if [ -f "${BUILDDIR}/libwidevinecdmadapter.so" ]; then 151 install -m 644 -s "${BUILDDIR}/libwidevinecdmadapter.so" "${STAGEDIR}/${INSTALLDIR}/" 152 install -m 644 "${BUILDDIR}/libwidevinecdm.so" "${STAGEDIR}/${INSTALLDIR}/" 153 fi 154 155 # Pepper Flash. 156 PEPPERFLASH_SRCDIR="${BUILDDIR}/PepperFlash" 157 PEPPERFLASH_DESTDIR="${STAGEDIR}/${INSTALLDIR}/PepperFlash" 158 install -m 755 -d "${PEPPERFLASH_DESTDIR}" 159 install -m 644 -s "${PEPPERFLASH_SRCDIR}/libpepflashplayer.so" \ 160 "${PEPPERFLASH_DESTDIR}/" 161 install -m 644 "${PEPPERFLASH_SRCDIR}/manifest.json" \ 162 "${PEPPERFLASH_DESTDIR}/" 163 164 # pdf plugin 165 if [ -f "${BUILDDIR}/libpdf.so" ]; then 166 install -m 644 -s "${BUILDDIR}/libpdf.so" "${STAGEDIR}/${INSTALLDIR}/" 167 fi 168 169 # peerconnection shared library 170 if [ -f "${BUILDDIR}/lib/libpeerconnection.so" ]; then 171 install -m 755 -d "${STAGEDIR}/${INSTALLDIR}/lib/" 172 install -m 644 -s "${BUILDDIR}/lib/libpeerconnection.so" "${STAGEDIR}/${INSTALLDIR}/lib/" 173 fi 174 175 # nacl pepper plugin 176 if [ -f "${BUILDDIR}/libppGoogleNaClPluginChrome.so" ]; then 177 install -m 644 -s "${BUILDDIR}/libppGoogleNaClPluginChrome.so" "${STAGEDIR}/${INSTALLDIR}/" 178 fi 179 180 # nacl_helper and nacl_helper_bootstrap 181 # Don't use "-s" (strip) because this runs binutils "strip", which 182 # mangles the special ELF program headers of nacl_helper_bootstrap. 183 # Explicitly use eu-strip instead, because it doesn't have that problem. 184 for file in nacl_helper nacl_helper_bootstrap; do 185 buildfile="${BUILDDIR}/${file}" 186 if [ -f "${buildfile}" ]; then 187 strippedfile="${buildfile}.stripped" 188 debugfile="${buildfile}.debug" 189 eu-strip -o "${strippedfile}" -f "${debugfile}" "${buildfile}" 190 install -m 755 "${strippedfile}" "${STAGEDIR}/${INSTALLDIR}/${file}" 191 fi 192 done 193 # Don't use "-s" (strip) because this would use the Linux toolchain to 194 # strip the NaCl binary, which has the potential to break it. It 195 # certainly resets the OSABI and ABIVERSION fields to non-NaCl values, 196 # although the NaCl IRT loader doesn't care about these fields. In any 197 # case, the IRT binaries are already stripped by NaCl's build process. 198 for filename in ${BUILDDIR}/nacl_irt_*.nexe; do 199 # Re-check the filename in case globbing matched nothing. 200 if [ -f "$filename" ]; then 201 install -m 644 "$filename" "${STAGEDIR}/${INSTALLDIR}/`basename "$filename"`" 202 fi 203 done 204 205 # default apps 206 if [ -d "${BUILDDIR}/default_apps" ]; then 207 cp -a "${BUILDDIR}/default_apps" "${STAGEDIR}/${INSTALLDIR}/" 208 find "${STAGEDIR}/${INSTALLDIR}/default_apps" -type d -exec chmod 755 '{}' \; 209 find "${STAGEDIR}/${INSTALLDIR}/default_apps" -type f -exec chmod 644 '{}' \; 210 fi 211 212 # launcher script and symlink 213 process_template "${BUILDDIR}/installer/common/wrapper" \ 214 "${STAGEDIR}/${INSTALLDIR}/${PACKAGE}" 215 chmod 755 "${STAGEDIR}/${INSTALLDIR}/${PACKAGE}" 216 ln -snf "${INSTALLDIR}/${PACKAGE}" \ 217 "${STAGEDIR}/usr/bin/${USR_BIN_SYMLINK_NAME}" 218 219 # app icons 220 install -m 644 \ 221 "${BUILDDIR}/installer/theme/product_logo_"*.png \ 222 "${BUILDDIR}/installer/theme/product_logo_32.xpm" \ 223 "${STAGEDIR}/${INSTALLDIR}/" 224 225 # desktop integration 226 install -m 755 "${BUILDDIR}/xdg-mime" "${STAGEDIR}${INSTALLDIR}/" 227 install -m 755 "${BUILDDIR}/xdg-settings" "${STAGEDIR}${INSTALLDIR}/" 228 process_template "${BUILDDIR}/installer/common/desktop.template" \ 229 "${STAGEDIR}/usr/share/applications/${PACKAGE}.desktop" 230 chmod 644 "${STAGEDIR}/usr/share/applications/${PACKAGE}.desktop" 231 process_template "${BUILDDIR}/installer/common/default-app.template" \ 232 "${STAGEDIR}/usr/share/gnome-control-center/default-apps/${PACKAGE}.xml" 233 chmod 644 "${STAGEDIR}/usr/share/gnome-control-center/default-apps/${PACKAGE}.xml" 234 process_template "${BUILDDIR}/installer/common/default-app-block.template" \ 235 "${STAGEDIR}${INSTALLDIR}/default-app-block" 236 chmod 644 "${STAGEDIR}${INSTALLDIR}/default-app-block" 237 238 # documentation 239 install -m 755 "${BUILDDIR}/${PROGNAME}.1" \ 240 "${STAGEDIR}/usr/share/man/man1/${PACKAGE}.1" 241 } 242