diff --git a/.gclient b/.gclient index 45a8df31..53f5fefd 100644 --- a/.gclient +++ b/.gclient @@ -8,5 +8,5 @@ solutions = [ }, ] -target_os = [ 'linux', 'win' ] +target_os = [ 'linux', 'win', 'android' ] target_cpu = [ 'x64', 'x86', 'arm64', 'arm' ] diff --git a/.gitignore b/.gitignore index 5c85c8b5..d29e51e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .DS_Store API_KEYS.txt *.deb +*.rpm *.AppImage *.zip thorium_mini_installer.exe diff --git a/setup.sh b/setup.sh index 71944f4a..8a5eee69 100755 --- a/setup.sh +++ b/setup.sh @@ -34,11 +34,20 @@ case $1 in --help) displayHelp; exit 0;; esac +# chromium/src dir env variable +if [ -z "${CR_DIR}" ]; then + CR_SRC_DIR="${CR_SRC_DIR}" + export CR_SRC_DIR +else + CR_SRC_DIR="${CR_DIR}" + export CR_SRC_DIR +fi + printf "\n" && printf "${YEL}Creating build output directory...\n" && tput sgr0 && -mkdir -v -p $HOME/chromium/src/out/thorium/ && +mkdir -v -p ${CR_SRC_DIR}/out/thorium/ && printf "\n" && printf "\n" && @@ -47,46 +56,46 @@ tput sgr0 && # Copy libjxl src cd ~/thorium && -cp -r -v thorium-libjxl/src/. $HOME/chromium/src/ && +cp -r -v thorium-libjxl/src/. ${CR_SRC_DIR}/ && # Copy Thorium sources -cp -r -v src/BUILD.gn $HOME/chromium/src/ && -cp -r -v src/ash/. $HOME/chromium/src/ash/ && -cp -r -v src/build/. $HOME/chromium/src/build/ && -cp -r -v src/chrome/. $HOME/chromium/src/chrome/ && -cp -r -v src/chromeos/. $HOME/chromium/src/chromeos/ && -cp -r -v src/components/. $HOME/chromium/src/components/ && -cp -r -v src/extensions/. $HOME/chromium/src/extensions/ && -cp -r -v src/content/. $HOME/chromium/src/content/ && -cp -r -v src/media/. $HOME/chromium/src/media/ && -cp -r -v src/net/. $HOME/chromium/src/net/ && -cp -r -v src/sandbox/. $HOME/chromium/src/sandbox/ && -cp -r -v src/services/. $HOME/chromium/src/services/ && -cp -r -v src/third_party/. $HOME/chromium/src/third_party/ && -cp -r -v src/tools/. $HOME/chromium/src/tools/ && -cp -r -v src/ui/. $HOME/chromium/src/ui/ && -cp -r -v src/v8/. $HOME/chromium/src/v8/ && -cp -r -v thorium_shell/. $HOME/chromium/src/out/thorium/ && -cp -r -v pak_src/bin/pak $HOME/chromium/src/out/thorium/ && -cp -r -v pak_src/bin/pak-win/. $HOME/chromium/src/out/thorium/ && +cp -r -v src/BUILD.gn ${CR_SRC_DIR}/ && +cp -r -v src/ash/. ${CR_SRC_DIR}/ash/ && +cp -r -v src/build/. ${CR_SRC_DIR}/build/ && +cp -r -v src/chrome/. ${CR_SRC_DIR}/chrome/ && +cp -r -v src/chromeos/. ${CR_SRC_DIR}/chromeos/ && +cp -r -v src/components/. ${CR_SRC_DIR}/components/ && +cp -r -v src/extensions/. ${CR_SRC_DIR}/extensions/ && +cp -r -v src/content/. ${CR_SRC_DIR}/content/ && +cp -r -v src/media/. ${CR_SRC_DIR}/media/ && +cp -r -v src/net/. ${CR_SRC_DIR}/net/ && +cp -r -v src/sandbox/. ${CR_SRC_DIR}/sandbox/ && +cp -r -v src/services/. ${CR_SRC_DIR}/services/ && +cp -r -v src/third_party/. ${CR_SRC_DIR}/third_party/ && +cp -r -v src/tools/. ${CR_SRC_DIR}/tools/ && +cp -r -v src/ui/. ${CR_SRC_DIR}/ui/ && +cp -r -v src/v8/. ${CR_SRC_DIR}/v8/ && +cp -r -v thorium_shell/. ${CR_SRC_DIR}/out/thorium/ && +cp -r -v pak_src/bin/pak ${CR_SRC_DIR}/out/thorium/ && +cp -r -v pak_src/bin/pak-win/. ${CR_SRC_DIR}/out/thorium/ && # Add default_apps dir for Google Docs Offline extension. -mkdir -v -p $HOME/chromium/src/out/thorium/default_apps && -cp -r -v infra/default_apps/. $HOME/chromium/src/out/thorium/default_apps/ && +mkdir -v -p ${CR_SRC_DIR}/out/thorium/default_apps && +cp -r -v infra/default_apps/. ${CR_SRC_DIR}/out/thorium/default_apps/ && # Add initial preferences file to open Thorium welcome page on first run. -cp -v infra/initial_preferences $HOME/chromium/src/out/thorium/ && +cp -v infra/initial_preferences ${CR_SRC_DIR}/out/thorium/ && echo " # Workaround for DevTools" && -mkdir -v -p $HOME/chromium/src/out/thorium/gen/third_party/devtools-frontend/src/front_end/Images/ && -cp -r -v src/third_party/devtools-frontend/src/front_end/Images/src/chromeSelectDark.svg $HOME/chromium/src/out/thorium/gen/third_party/devtools-frontend/src/front_end/Images/ && +mkdir -v -p ${CR_SRC_DIR}/out/thorium/gen/third_party/devtools-frontend/src/front_end/Images/ && +cp -r -v src/third_party/devtools-frontend/src/front_end/Images/src/chromeSelectDark.svg ${CR_SRC_DIR}/out/thorium/gen/third_party/devtools-frontend/src/front_end/Images/ && # MacOS Widevine Workaround copyMacOS () { printf "\n" && printf "${YEL}Copying files for MacOS...${c0}\n" && - cp -r -v other/Mac/cdm_registration.cc $HOME/chromium/src/chrome/common/media/ && - cp -r -v arm/mac_arm.gni $HOME/chromium/src/build/config/arm.gni && + cp -r -v other/Mac/cdm_registration.cc ${CR_SRC_DIR}/chrome/common/media/ && + cp -r -v arm/mac_arm.gni ${CR_SRC_DIR}/build/config/arm.gni && printf "\n" } case $1 in @@ -97,7 +106,7 @@ esac copyRaspi () { printf "\n" && printf "${YEL}Copying Raspberry Pi build files...${c0}\n" && - cp -r -v arm/raspi/* $HOME/chromium/src/ && + cp -r -v arm/raspi/* ${CR_SRC_DIR}/ && printf "\n" } # Display raspi ascii art @@ -112,7 +121,7 @@ esac copyWOA () { printf "\n" && printf "${YEL}Copying Windows on ARM build files...${c0}\n" && - cp -r -v arm/build/config/* $HOME/chromium/src/build/config/ && + cp -r -v arm/build/config/* ${CR_SRC_DIR}/build/config/ && printf "\n" } case $1 in @@ -123,9 +132,9 @@ esac copyAVX2 () { printf "\n" && printf "${YEL}Copying AVX2 build files...${c0}\n" && - cp -r -v other/AVX2/build/config/* $HOME/chromium/src/build/config/ && - cp -r -v other/AVX2/v8/* $HOME/chromium/src/v8/ && - cp -r -v other/AVX2/third_party/* $HOME/chromium/src/third_party/ && + cp -r -v other/AVX2/build/config/* ${CR_SRC_DIR}/build/config/ && + cp -r -v other/AVX2/v8/* ${CR_SRC_DIR}/v8/ && + cp -r -v other/AVX2/third_party/* ${CR_SRC_DIR}/third_party/ && printf "\n" } case $1 in @@ -136,9 +145,9 @@ esac copySSE3 () { printf "\n" && printf "${YEL}Copying SSE3 build files...${c0}\n" && - cp -r -v other/SSE3/build/config/* $HOME/chromium/src/build/config/ && - cp -r -v other/SSE3/v8/* $HOME/chromium/src/v8/ && - cp -r -v other/SSE3/third_party/* $HOME/chromium/src/third_party/ && + cp -r -v other/SSE3/build/config/* ${CR_SRC_DIR}/build/config/ && + cp -r -v other/SSE3/v8/* ${CR_SRC_DIR}/v8/ && + cp -r -v other/SSE3/third_party/* ${CR_SRC_DIR}/third_party/ && printf "\n" } case $1 in @@ -149,8 +158,8 @@ esac copySSE2 () { printf "\n" && printf "${YEL}Copying SSE2 (32-bit) build files...${c0}\n" && - cp -r -v other/SSE2/build/config/* $HOME/chromium/src/build/config/ && - cp -r -v other/SSE2/third_party/* $HOME/chromium/src/third_party/ && + cp -r -v other/SSE2/build/config/* ${CR_SRC_DIR}/build/config/ && + cp -r -v other/SSE2/third_party/* ${CR_SRC_DIR}/third_party/ && printf "\n" } case $1 in @@ -161,9 +170,9 @@ esac copyAndroid () { printf "\n" && printf "${YEL}Copying Android (ARM64 and ARM32) build files...${c0}\n" && - cp -r -v arm/build/config/* $HOME/chromium/src/build/config/ && - cp -r -v arm/android/* $HOME/chromium/src/ && - cp -r -v arm/android/third_party/* $HOME/chromium/src/third_party/ && + cp -r -v arm/build/config/* ${CR_SRC_DIR}/build/config/ && + cp -r -v arm/android/* ${CR_SRC_DIR}/ && + cp -r -v arm/android/third_party/* ${CR_SRC_DIR}/third_party/ && printf "\n" } case $1 in diff --git a/src/chrome/installer/launcher_support/chrome_launcher_support.cc b/src/chrome/installer/launcher_support/chrome_launcher_support.cc new file mode 100644 index 00000000..076e1085 --- /dev/null +++ b/src/chrome/installer/launcher_support/chrome_launcher_support.cc @@ -0,0 +1,177 @@ +// Copyright 2023 The Chromium Authors and Alex313031 +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/installer/launcher_support/chrome_launcher_support.h" + +#include + +#include + +#include "base/files/file_util.h" +#include "base/strings/utf_string_conversions.h" +#include "base/win/registry.h" +#include "build/branding_buildflags.h" + +namespace chrome_launcher_support { + +namespace { + +// TODO(huangs) Refactor the constants: http://crbug.com/148538 +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) +const wchar_t kUpdateClientStateRegKey[] = + L"Software\\Google\\Update\\ClientState"; + +const wchar_t kUpdateClientsRegKey[] = L"Software\\Google\\Update\\Clients"; + +// Copied from google_chrome_install_modes.cc. +const wchar_t kBrowserAppGuid[] = L"{8A69D345-D564-463c-AFF1-A69D9E530F96}"; +const wchar_t kSxSBrowserAppGuid[] = L"{4ea16ac7-fd5a-47c3-875b-dbf4a2008c20}"; +#else +const wchar_t kInstallationRegKey[] = L"Software\\Chromium"; +#endif + +// Copied from util_constants.cc. +const wchar_t kChromeExe[] = L"thorium.exe"; +const wchar_t kUninstallStringField[] = L"UninstallString"; +const wchar_t kVersionStringField[] = L"pv"; + +// Returns the registry path to where Client state is stored. +std::wstring GetClientStateRegKey() { +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) + return kUpdateClientStateRegKey; +#else + return kInstallationRegKey; +#endif +} + +// Returns the registry path to where basic information about the Clients +// like name and version information are stored. +std::wstring GetClientsRegKey() { +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) + return kUpdateClientsRegKey; +#else + return kInstallationRegKey; +#endif +} + +// Reads a string value from the specified product's registry key. Returns true +// iff the value is present and successfully read. +bool GetValueFromRegistry(InstallationLevel level, + const std::wstring key_path, + const wchar_t* app_guid, + const wchar_t* value_name, + std::wstring* value) { + HKEY root_key = (level == USER_LEVEL_INSTALLATION) ? HKEY_CURRENT_USER + : HKEY_LOCAL_MACHINE; + std::wstring subkey(key_path); + if (app_guid) + subkey.append(1, L'\\').append(app_guid); + base::win::RegKey reg_key; + // Google Update always uses 32bit hive. + if (reg_key.Open(root_key, subkey.c_str(), + KEY_QUERY_VALUE | KEY_WOW64_32KEY) == ERROR_SUCCESS) { + if (reg_key.ReadValue(value_name, value) == ERROR_SUCCESS) { + return true; + } + } + return false; +} + +// Reads the path to setup.exe from the value "UninstallString" within the +// specified product's registry key. Returns an empty FilePath if an error +// occurs or the product is not installed at the specified level. +base::FilePath GetSetupExeFromRegistry(InstallationLevel level, + const wchar_t* app_guid) { + std::wstring uninstall; + if (GetValueFromRegistry(level, GetClientStateRegKey(), app_guid, + kUninstallStringField, &uninstall)) { + base::FilePath setup_exe_path(uninstall); + if (base::PathExists(setup_exe_path)) + return setup_exe_path; + } + return base::FilePath(); +} + +// Returns the path to an existing setup.exe at the specified level, if it can +// be found via the registry. +base::FilePath GetSetupExeForInstallationLevel(InstallationLevel level) { +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) + // Look in the registry for Chrome. + return GetSetupExeFromRegistry(level, kBrowserAppGuid); +#else + // For Chromium, there are no GUIDs. Just look in the Chromium registry key. + return GetSetupExeFromRegistry(level, nullptr); +#endif +} + +// Returns the path to an installed |exe_file| (e.g. chrome.exe) at the +// specified level, given |setup_exe_path| from the registry. Returns empty +// base::FilePath if none found, or if |setup_exe_path| is empty. +base::FilePath FindExeRelativeToSetupExe(const base::FilePath setup_exe_path, + const wchar_t* exe_file) { + if (!setup_exe_path.empty()) { + // The uninstall path contains the path to setup.exe, which is two levels + // down from |exe_file|. Move up two levels (plus one to drop the file + // name) and look for chrome.exe from there. + base::FilePath exe_path( + setup_exe_path.DirName().DirName().DirName().Append(exe_file)); + if (base::PathExists(exe_path)) + return exe_path; + // By way of mild future proofing, look up one to see if there's a + // |exe_file| in the version directory + exe_path = setup_exe_path.DirName().DirName().Append(exe_file); + if (base::PathExists(exe_path)) + return exe_path; + } + return base::FilePath(); +} + +} // namespace + +base::FilePath GetChromePathForInstallationLevel(InstallationLevel level, + bool is_sxs) { + if (is_sxs) { +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) + return FindExeRelativeToSetupExe( + GetSetupExeFromRegistry(level, kSxSBrowserAppGuid), kChromeExe); +#else + // There is no SxS build for Chromium. + return base::FilePath(); +#endif + } else { + return FindExeRelativeToSetupExe(GetSetupExeForInstallationLevel(level), + kChromeExe); + } +} + +base::FilePath GetAnyChromePath(bool is_sxs) { + base::FilePath path; + path = GetChromePathForInstallationLevel(SYSTEM_LEVEL_INSTALLATION, is_sxs); + if (path.empty()) + path = GetChromePathForInstallationLevel(USER_LEVEL_INSTALLATION, is_sxs); + return path; +} + +base::Version GetChromeVersionForInstallationLevel(InstallationLevel level, + bool is_sxs) { + const wchar_t* app_guid = nullptr; // Chromium doesn't use App GUIDs. +#if BUILDFLAG(GOOGLE_CHROME_BRANDING) + app_guid = is_sxs ? kSxSBrowserAppGuid : kBrowserAppGuid; +#else + // There is no SxS build for Chromium. + if (is_sxs) + return base::Version(); +#endif + + std::wstring version_str; + if (GetValueFromRegistry(level, GetClientsRegKey(), app_guid, + kVersionStringField, &version_str)) { + base::Version version(base::WideToASCII(version_str)); + if (version.IsValid()) + return version; + } + return base::Version(); +} + +} // namespace chrome_launcher_support diff --git a/src/chrome/installer/linux/BUILD.gn b/src/chrome/installer/linux/BUILD.gn index 464dc5ff..ddc47918 100644 --- a/src/chrome/installer/linux/BUILD.gn +++ b/src/chrome/installer/linux/BUILD.gn @@ -353,7 +353,7 @@ if (!is_chromeos_ash) { visibility = [ ":*" ] sources = [ "rpm/build.sh", - "rpm/chrome.spec.template", + "rpm/thorium.spec.template", ] outputs = [ "$root_out_dir/installer/rpm/{{source_file_part}}" ] } diff --git a/src/chrome/installer/linux/common/installer.include b/src/chrome/installer/linux/common/installer.include index 627c4ab8..712579f2 100644 --- a/src/chrome/installer/linux/common/installer.include +++ b/src/chrome/installer/linux/common/installer.include @@ -171,10 +171,10 @@ stage_install_common() { install -m 644 "${OUTPUTDIR}/resources/inspector_overlay/inspector_overlay_resources.grd" "${STAGEDIR}/${INSTALLDIR}/resources/inspector_overlay/" install -m 644 "${OUTPUTDIR}/resources/inspector_overlay/main.js" "${STAGEDIR}/${INSTALLDIR}/resources/inspector_overlay/" install -m 755 "${OUTPUTDIR}/thorium_shell" "${STAGEDIR}/${INSTALLDIR}/" - install -m 644 "${OUTPUTDIR}/libffmpeg.so" "${STAGEDIR}/${INSTALLDIR}/" - install -m 644 "${OUTPUTDIR}/libffmpeg.so" "${STAGEDIR}/${INSTALLDIR}/lib" - install -m 644 "${OUTPUTDIR}/libblink_test_plugin.so" "${STAGEDIR}/${INSTALLDIR}/lib" - install -m 644 "${OUTPUTDIR}/ClearKeyCdm/_platform_specific/linux_x64/libclearkeycdm.so" "${STAGEDIR}/${INSTALLDIR}/lib" + install -m ${SHLIB_PERMS} "${OUTPUTDIR}/libffmpeg.so" "${STAGEDIR}/${INSTALLDIR}/" + install -m ${SHLIB_PERMS} "${OUTPUTDIR}/libffmpeg.so" "${STAGEDIR}/${INSTALLDIR}/lib" + install -m ${SHLIB_PERMS} "${OUTPUTDIR}/libblink_test_plugin.so" "${STAGEDIR}/${INSTALLDIR}/lib" + install -m ${SHLIB_PERMS} "${OUTPUTDIR}/ClearKeyCdm/_platform_specific/linux_x64/libclearkeycdm.so" "${STAGEDIR}/${INSTALLDIR}/lib" install -m 644 "${OUTPUTDIR}/thorium_shell.png" "${STAGEDIR}/${INSTALLDIR}/" install -m 644 "${OUTPUTDIR}/thorium-shell.desktop" "${STAGEDIR}/usr/share/applications/" install -m 755 "${OUTPUTDIR}/thorium-shell" "${STAGEDIR}/usr/bin/" @@ -182,8 +182,8 @@ stage_install_common() { install -m 755 "${OUTPUTDIR}/pak" "${STAGEDIR}/usr/bin/" install -m 644 "${OUTPUTDIR}/initial_preferences" "${STAGEDIR}/${INSTALLDIR}/" else - install -m 644 "${OUTPUTDIR}/theme_resources_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/" install -m 644 "${OUTPUTDIR}/ui_resources_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/" + install -m 644 "${OUTPUTDIR}/theme_resources_100_percent.pak" "${STAGEDIR}/${INSTALLDIR}/" fi # ICU data file; Necessary when the GN icu_use_data_file flag is true. diff --git a/src/chrome/installer/linux/debian/build.sh b/src/chrome/installer/linux/debian/build.sh index 35072797..84825e1c 100755 --- a/src/chrome/installer/linux/debian/build.sh +++ b/src/chrome/installer/linux/debian/build.sh @@ -102,6 +102,9 @@ verify_package() { echo exit $BAD_DIFF fi + + # Rename package to match Thorium naming scheme + mv -v "${PACKAGE}_${VERSIONFULL}_${ARCHITECTURE}.deb" "${PACKAGE}_${DEBVERSIONNAME}_${ARCHITECTURE}.deb" } # Actually generate the package file. @@ -243,6 +246,7 @@ source ${OUTPUTDIR}/installer/common/installer.include get_version_info VERSIONFULL="${VERSION}-${PACKAGE_RELEASE}" +DEBVERSIONNAME="${VERSION}" if [ "$BRANDING" = "google_chrome" ]; then source "${OUTPUTDIR}/installer/common/google-chrome.info" diff --git a/src/chrome/installer/linux/rpm/build.sh b/src/chrome/installer/linux/rpm/build.sh new file mode 100755 index 00000000..222f1888 --- /dev/null +++ b/src/chrome/installer/linux/rpm/build.sh @@ -0,0 +1,224 @@ +#!/bin/bash +# +# Copyright 2023 The Chromium Authors and Alex313031 +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set -e +if [ "$VERBOSE" ]; then + set -x +fi +set -u + +gen_spec() { + rm -f "${SPEC}" + # Different channels need to install to different locations so they + # don't conflict with each other. + local PACKAGE_ORIG="${PACKAGE}" + local PACKAGE_FILENAME="${PACKAGE}" + if [ "$CHANNEL" != "stable" ]; then + local INSTALLDIR="${INSTALLDIR}" + local PACKAGE="${PACKAGE}" + local MENUNAME="${MENUNAME}" + fi + process_template "${SCRIPTDIR}/thorium.spec.template" "${SPEC}" +} + +# Setup the installation directory hierarchy in the package staging area. +prep_staging_rpm() { + prep_staging_common + install -m 755 -d "${STAGEDIR}/etc/cron.daily" +} + +# Put the package contents in the staging area. +stage_install_rpm() { + # TODO(phajdan.jr): Deduplicate this and debian/build.sh . + # For now duplication is going to help us avoid merge conflicts + # as changes are frequently merged to older branches related to SxS effort. + local PACKAGE_ORIG="${PACKAGE}" + if [ "$CHANNEL" != "stable" ]; then + # Avoid file collisions between channels. + local PACKAGE="${PACKAGE}" + local INSTALLDIR="${INSTALLDIR}" + + # Make it possible to distinguish between menu entries + # for different channels. + local MENUNAME="${MENUNAME}" + fi + prep_staging_rpm + SHLIB_PERMS=755 + stage_install_common + log_cmd echo "Staging RPM install files in '${STAGEDIR}'..." + process_template "${OUTPUTDIR}/installer/common/rpmrepo.cron" \ + "${STAGEDIR}/etc/cron.daily/${PACKAGE}" + chmod 755 "${STAGEDIR}/etc/cron.daily/${PACKAGE}" +} + +verify_package() { + local DEPENDS="$1" + local EXPECTED_DEPENDS="${TMPFILEDIR}/expected_rpm_depends" + local ACTUAL_DEPENDS="${TMPFILEDIR}/actual_rpm_depends" + local ADDITIONAL_RPM_DEPENDS="/bin/sh, \ + rpmlib(CompressedFileNames) <= 3.0.4-1, \ + rpmlib(FileDigests) <= 4.6.0-1, \ + rpmlib(PayloadFilesHavePrefix) <= 4.0-1, \ + /usr/sbin/update-alternatives" + if [ ${IS_OFFICIAL_BUILD} -ne 0 ]; then + ADDITIONAL_RPM_DEPENDS="${ADDITIONAL_RPM_DEPENDS}, \ + rpmlib(PayloadIsXz) <= 5.2-1" + fi + echo "${DEPENDS}" "${ADDITIONAL_RPM_DEPENDS}" | sed 's/,/\n/g' | \ + sed 's/^ *//' | LANG=C sort | uniq > "${EXPECTED_DEPENDS}" + rpm -qpR "${OUTPUTDIR}/${PKGNAME}.${ARCHITECTURE}.rpm" | LANG=C sort | uniq \ + > "${ACTUAL_DEPENDS}" + BAD_DIFF=0 + diff -u "${EXPECTED_DEPENDS}" "${ACTUAL_DEPENDS}" || BAD_DIFF=1 + if [ $BAD_DIFF -ne 0 ] && [ -z "${IGNORE_DEPS_CHANGES:-}" ]; then + echo + echo "ERROR: bad rpm dependencies!" + echo + exit $BAD_DIFF + fi +} + +# Actually generate the package file. +do_package() { + log_cmd echo "Packaging ${ARCHITECTURE}..." + PROVIDES="${PACKAGE}" + RPM_COMMON_DEPS="${OUTPUTDIR}/rpm_common.deps" + DEPENDS=$(cat "${RPM_COMMON_DEPS}" | tr '\n' ',') + gen_spec + + # Create temporary rpmbuild dirs. + mkdir -p "$RPMBUILD_DIR/BUILD" + mkdir -p "$RPMBUILD_DIR/RPMS" + + if [ ${IS_OFFICIAL_BUILD} -ne 0 ]; then + local COMPRESSION_OPT="_binary_payload w9.xzdio" + else + local COMPRESSION_OPT="_binary_payload w0.gzdio" + fi + + # '__os_install_post ${nil}' disables a bunch of automatic post-processing + # (brp-compress, etc.), which by default appears to only be enabled on 32-bit, + # and which doesn't gain us anything since we already explicitly do all the + # compression, symbol stripping, etc. that we want. + log_cmd fakeroot rpmbuild -bb --target="$ARCHITECTURE" --rmspec \ + --define "_topdir $RPMBUILD_DIR" \ + --define "${COMPRESSION_OPT}" \ + --define "__os_install_post %{nil}" \ + --define "_build_id_links none" \ + "${SPEC}" + PKGNAME="${PACKAGE}-${VERSION}-${PACKAGE_RELEASE}" + mv "$RPMBUILD_DIR/RPMS/$ARCHITECTURE/${PKGNAME}.${ARCHITECTURE}.rpm" \ + "${OUTPUTDIR}" + # Make sure the package is world-readable, otherwise it causes problems when + # copied to share drive. + chmod a+r "${OUTPUTDIR}/${PKGNAME}.${ARCHITECTURE}.rpm" + + verify_package "$DEPENDS" + + # Rename package to match Thorium naming scheme + mv "${OUTPUTDIR}/${PKGNAME}.${ARCHITECTURE}.rpm" "${OUTPUTDIR}/${PACKAGE}_${VERSION}.${ARCHITECTURE}.rpm" +} + +# Remove temporary files and unwanted packaging output. +cleanup() { + rm -rf "${STAGEDIR}" + rm -rf "${TMPFILEDIR}" + rm -rf "${RPMBUILD_DIR}" +} + +usage() { + echo "usage: $(basename $0) [-a target_arch] -c channel -d branding" + echo " [-f] [-o 'dir'] -t target_os" + echo "-a arch rpm package architecture" + echo "-c channel the package channel (unstable, beta, stable)" + echo "-d brand either chromium or google_chrome" + echo "-f indicates that this is an official build" + echo "-h this help message" + echo "-o dir package output directory [${OUTPUTDIR}]" + echo "-t platform target platform" +} + +CHANNEL=stable + +process_opts() { + while getopts ":a:b:c:d:fho:t:" OPTNAME + do + case $OPTNAME in + a ) + ARCHITECTURE="$OPTARG" + ;; + c ) + CHANNEL="$OPTARG" + ;; + d ) + BRANDING="$OPTARG" + ;; + f ) + IS_OFFICIAL_BUILD=1 + ;; + h ) + usage + exit 0 + ;; + o ) + OUTPUTDIR=$(readlink -f "${OPTARG}") + mkdir -p "${OUTPUTDIR}" + ;; + t ) + TARGET_OS="$OPTARG" + ;; + \: ) + echo "'-$OPTARG' needs an argument." + usage + exit 1 + ;; + * ) + echo "invalid command-line option: $OPTARG" + usage + exit 1 + ;; + esac + done +} + +#========= +# MAIN +#========= + +SCRIPTDIR=$(readlink -f "$(dirname "$0")") +OUTPUTDIR="${PWD}" + +# call cleanup() on exit +trap cleanup 0 +process_opts "$@" +export ARCHITECTURE="${ARCHITECTURE}" +IS_OFFICIAL_BUILD=1 + +STAGEDIR="${OUTPUTDIR}/rpm-staging" +mkdir -p "${STAGEDIR}" +TMPFILEDIR="${OUTPUTDIR}/rpm-tmp" +mkdir -p "${TMPFILEDIR}" +RPMBUILD_DIR="${OUTPUTDIR}/rpm-build" +mkdir -p "${RPMBUILD_DIR}" +SPEC="${TMPFILEDIR}/chrome.spec" + +source ${OUTPUTDIR}/installer/common/installer.include + +get_version_info + +if [ "$BRANDING" = "google_chrome" ]; then + source "${OUTPUTDIR}/installer/common/google-chrome.info" +else + source "${OUTPUTDIR}/installer/common/chromium-browser.info" +fi +eval $(sed -e "s/^\([^=]\+\)=\(.*\)$/export \1='\2'/" \ + "${OUTPUTDIR}/installer/theme/BRANDING") + +REPOCONFIG="https://dl.google.com/linux/${PACKAGE#google-}/rpm/stable" +export USR_BIN_SYMLINK_NAME="${PACKAGE}" + +stage_install_rpm +do_package diff --git a/src/chrome/installer/linux/rpm/thorium.spec.template b/src/chrome/installer/linux/rpm/thorium.spec.template new file mode 100644 index 00000000..cf835954 --- /dev/null +++ b/src/chrome/installer/linux/rpm/thorium.spec.template @@ -0,0 +1,226 @@ +#------------------------------------------------------------------------------ +# Thorium RPM spec +# chrome.spec +#------------------------------------------------------------------------------ + +#------------------------------------------------------------------------------ +# Prologue information +#------------------------------------------------------------------------------ +Summary : @@MENUNAME@@ +License : Multiple, see @@PRODUCTURL@@ +Name : @@PACKAGE_FILENAME@@ +Version : @@VERSION@@ +Release : @@PACKAGE_RELEASE@@ +Group : Applications/Internet +Vendor : @@COMPANY_FULLNAME@@ +Url : @@PRODUCTURL@@ +Packager : @@MAINTNAME@@ <@@MAINTMAIL@@> + +Provides : @@PROVIDES@@ = %{version} +Requires : @@DEPENDS@@ +Requires(post) : %{_sbindir}/update-alternatives +Requires(preun) : %{_sbindir}/update-alternatives +Autoreqprov : No + +BuildRoot : %{_tmppath}/%{name}-%{version}-root + +# The prefix is pretty important; RPM uses this to figure out +# how to make a package relocatable +prefix : /opt + +#------------------------------------------------------------------------------ +# Description +#------------------------------------------------------------------------------ +%Description +@@SHORTDESC@@ + +@@FULLDESC@@ + +#------------------------------------------------------------------------------ +# Build rule - How to make the package +#------------------------------------------------------------------------------ +%build + +#------------------------------------------------------------------------------ +# Installation rule - how to install it (note that it +# gets installed into a temp directory given by $RPM_BUILD_ROOT) +#------------------------------------------------------------------------------ +%install +rm -rf "$RPM_BUILD_ROOT" + +if [ -z "@@STAGEDIR@@" -o ! -d "@@STAGEDIR@@" ] ; then + echo "@@STAGEDIR@@ appears to be incorrectly set - aborting" + exit 1 +fi + +if [ -z "@@INSTALLDIR@@" -o ! -d "@@STAGEDIR@@/@@INSTALLDIR@@" ] ; then + echo "@@INSTALLDIR@@ appears to be incorrectly set - aborting" + exit 1 +fi + +install -m 755 -d \ + "$RPM_BUILD_ROOT/etc" \ + "$RPM_BUILD_ROOT/opt" \ + "$RPM_BUILD_ROOT/usr" +# This is hard coded for now +cp -a "@@STAGEDIR@@/etc/" "$RPM_BUILD_ROOT/" +cp -a "@@STAGEDIR@@/opt/" "$RPM_BUILD_ROOT/" +cp -a "@@STAGEDIR@@/usr/" "$RPM_BUILD_ROOT/" + +#------------------------------------------------------------------------------ +# Rule to clean up a build +#------------------------------------------------------------------------------ +%clean +rm -rf "$RPM_BUILD_ROOT" + +#------------------------------------------------------------------------------ +# Files listing. +#------------------------------------------------------------------------------ +%files +%defattr(-,root,root) +#%doc README + +# We cheat and just let RPM figure it out for us; everything we install +# should go under this prefix anyways. +@@INSTALLDIR@@ + +# Be explicit about the files we scatter throughout the system we don't +# accidentally "own" stuff that's not ours (crbug.com/123990). +/etc/cron.daily/@@PACKAGE@@ +%ghost %attr(755,root,root) /usr/bin/@@PACKAGE_ORIG@@ +/usr/bin/@@USR_BIN_SYMLINK_NAME@@ +# Extra Thorium stuff +/usr/bin/pak +/usr/bin/thorium-shell +/usr/share/applications/thorium-shell.desktop +/usr/share/appdata/@@PACKAGE@@.appdata.xml +/usr/share/applications/@@PACKAGE@@.desktop +/usr/share/gnome-control-center/default-apps/@@PACKAGE@@.xml +%docdir /usr/share/man/man1 +# These two files will be the same on non-stable channels. +/usr/share/man/man1/@@PACKAGE@@.1.gz +/usr/share/man/man1/@@USR_BIN_SYMLINK_NAME@@.1.gz + +#------------------------------------------------------------------------------ +# Pre install script +#------------------------------------------------------------------------------ +%pre + +exit 0 + + + + +#------------------------------------------------------------------------------ +# Post install script +#------------------------------------------------------------------------------ +%post + +@@include@@../common/variables.include + +@@include@@../common/postinst.include + +@@include@@../common/rpm.include + +@@include@@../common/symlinks.include + +remove_nss_symlinks +add_nss_symlinks + +remove_udev_symlinks + +if [ ! -e "$DEFAULTS_FILE" ]; then + echo 'repo_add_once="true"' > "$DEFAULTS_FILE" +fi + +. "$DEFAULTS_FILE" + +if [ "$repo_add_once" = "true" ]; then + determine_rpm_package_manager + + for PACKAGEMANAGER in ${PACKAGEMANAGERS[*]} + do + case $PACKAGEMANAGER in + "yum") + install_yum + ;; + "zypp") + install_zypp + ;; + esac + done +fi + +CHANNEL=@@CHANNEL@@ +case $CHANNEL in + stable ) + PRIORITY=200 + ;; + beta ) + PRIORITY=150 + ;; + unstable ) + PRIORITY=120 + ;; + * ) + PRIORITY=0 + ;; +esac + +%{_sbindir}/update-alternatives --install /usr/bin/@@PACKAGE_ORIG@@ \ + @@PACKAGE_ORIG@@ /usr/bin/@@USR_BIN_SYMLINK_NAME@@ $PRIORITY + +exit 0 + + +#------------------------------------------------------------------------------ +# Pre uninstallation script +#------------------------------------------------------------------------------ +%preun + +if [ "$1" -eq "0" ]; then + mode="uninstall" +elif [ "$1" -eq "1" ]; then + mode="upgrade" +fi + +@@include@@../common/rpm.include + +@@include@@../common/symlinks.include + +# Only remove menu items and symlinks on uninstall. When upgrading, +# old_pkg's %preun runs after new_pkg's %post. +if [ "$mode" = "uninstall" ]; then +@@include@@../common/prerm.include + remove_nss_symlinks + remove_udev_symlinks + + %{_sbindir}/update-alternatives --remove @@PACKAGE_ORIG@@ \ + /usr/bin/@@USR_BIN_SYMLINK_NAME@@ +fi + +# On Debian we only remove when we purge. However, RPM has no equivalent to +# dpkg --purge, so this is all disabled. +# +#determine_rpm_package_manager +# +#for PACKAGEMANAGER in ${PACKAGEMANAGERS[*]} +#do +# case $PACKAGEMANAGER in +# "yum") +# remove_yum +# ;; +# "zypp") +# remove_zypp +# ;; +# esac +#done + +exit 0 + +#------------------------------------------------------------------------------ +# Post uninstallation script +#------------------------------------------------------------------------------ +%postun + +exit 0