#!/bin/sh # # Copyright 2009 The Chromium Authors # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. set -e action="$1" # Only do complete clean-up on purge. if [ "$action" != "purge" ] ; then exit 0 fi # System-wide package configuration. DEFAULTS_FILE="/etc/default/google-chrome" # sources.list setting for google-chrome updates. REPOCONFIG="deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" REPOCONFIGREGEX="deb (\[arch=[^]]*\bamd64\b[^]]*\][[:space:]]*) https?://dl.google.com/linux/chrome/deb/ stable main" APT_GET="`command -v apt-get 2> /dev/null`" APT_CONFIG="`command -v apt-config 2> /dev/null`" SOURCES_PREAMBLE="### THIS FILE IS AUTOMATICALLY CONFIGURED ### # You may comment out this entry, but any other modifications may be lost.\n" # Set variables for the locations of the apt trusted keyrings. find_apt_trusted() { eval $("$APT_CONFIG" shell APT_TRUSTEDDIR 'Dir::Etc::trustedparts/d') } # Install the repository/package signing keys. # (see also: https://www.google.com/linuxrepositories/) install_key() { find_apt_trusted # ASCII-armored keyrings are only supported in apt 1.4 and later, but we must # continue supporting Trusty and Xenial which have older versions of apt, so # the keyring is installed as a binary blob. base64 is used to decode the # ASCII keyring, which should always be available since it comes from the # coreutils. (base64 -d > "$APT_TRUSTEDDIR/google-chrome.gpg") </dev/null) # Check if the correct repository configuration is in there. REPOMATCH=$(grep -E "^[[:space:]#]*\b$REPOCONFIGREGEX\b" "$SOURCELIST" \ 2>/dev/null) # Check if the correct repository is disabled. MATCH_DISABLED=$(echo "$REPOMATCH" | grep "^[[:space:]]*#" 2>/dev/null) # Now figure out if we need to fix things. BADCONFIG=1 if [ "$REPOMATCH" ]; then # If it's there and active, that's ideal, so nothing to do. if [ ! "$MATCH_DISABLED" ]; then BADCONFIG=0 else # If it's not active, but neither is anything else, that's fine too. if [ ! "$ACTIVECONFIGS" ]; then BADCONFIG=0 fi fi fi if [ $BADCONFIG -eq 0 ]; then return 0 fi # At this point, either the correct configuration is completely missing, or # the wrong configuration is active. In that case, just abandon the mess and # recreate the file with the correct configuration. If there were no active # configurations before, create the new configuration disabled. DISABLE="" if [ ! "$ACTIVECONFIGS" ]; then DISABLE="#" fi printf "$SOURCES_PREAMBLE" > "$SOURCELIST" printf "$DISABLE$REPOCONFIG\n" >> "$SOURCELIST" if [ $? -eq 0 ]; then return 0 fi return 2 } # Add the Google repository to the apt sources. # Returns: # 0 - sources list was created # 2 - error create_sources_lists() { if [ ! "$REPOCONFIG" ]; then return 0 fi find_apt_sources SOURCELIST="$APT_SOURCESDIR/google-chrome.list" if [ -d "$APT_SOURCESDIR" ]; then printf "$SOURCES_PREAMBLE" > "$SOURCELIST" printf "$REPOCONFIG\n" >> "$SOURCELIST" if [ $? -eq 0 ]; then return 0 fi fi return 2 } # Remove our custom sources list file. # Returns: # 0 - successfully removed, or not configured # !0 - failed to remove clean_sources_lists() { if [ ! "$REPOCONFIG" ]; then return 0 fi find_apt_sources rm -f "$APT_SOURCESDIR/google-chrome.list" } # Detect if the repo config was disabled by distro upgrade and enable if # necessary. handle_distro_upgrade() { if [ ! "$REPOCONFIG" ]; then return 0 fi find_apt_sources SOURCELIST="$APT_SOURCESDIR/google-chrome.list" if [ -r "$SOURCELIST" ]; then REPOLINE=$(grep -E "^[[:space:]]*#[[:space:]]*$REPOCONFIGREGEX[[:space:]]*# disabled on upgrade to .*" "$SOURCELIST") if [ $? -eq 0 ]; then sed -i -e "s,^[[:space:]]*#[[:space:]]*\(.*\)[[:space:]]*# disabled on upgrade to .*,\1," \ "$SOURCELIST" LOGGER=$(command -v logger 2> /dev/null) if [ "$LOGGER" ]; then "$LOGGER" -t "$0" "Reverted repository modification: $REPOLINE." fi fi fi } DEFAULT_ARCH="amd64" get_lib_dir() { if [ "$DEFAULT_ARCH" = "i386" ]; then LIBDIR=lib/i386-linux-gnu elif [ "$DEFAULT_ARCH" = "amd64" ]; then LIBDIR=lib/x86_64-linux-gnu elif [ "$DEFAULT_ARCH" = "armhf" ]; then LIBDIR=lib/arm-linux-gnueabihf elif [ "$DEFAULT_ARCH" = "arm64" ]; then LIBDIR=lib/aarch64-linux-gnu elif [ "$DEFAULT_ARCH" = "mipsel" ]; then LIBDIR=lib/mipsel-linux-gnu elif [ "$DEFAULT_ARCH" = "mips64el" ]; then LIBDIR=lib/mips64el-linux-gnuabi64 else echo Unknown CPU Architecture: "$DEFAULT_ARCH" exit 1 fi } NSS_FILES="libnspr4.so.0d libplds4.so.0d libplc4.so.0d libssl3.so.1d \ libnss3.so.1d libsmime3.so.1d libnssutil3.so.1d" add_nss_symlinks() { get_lib_dir for f in $NSS_FILES do target=$(echo $f | sed 's/\.[01]d$//') if [ -f "/$LIBDIR/$target" ]; then ln -snf "/$LIBDIR/$target" "/opt/google/chrome/$f" elif [ -f "/usr/$LIBDIR/$target" ]; then ln -snf "/usr/$LIBDIR/$target" "/opt/google/chrome/$f" else echo $f not found in "/$LIBDIR/$target" or "/usr/$LIBDIR/$target". exit 1 fi done } remove_nss_symlinks() { for f in $NSS_FILES do rm -rf "/opt/google/chrome/$f" done } remove_udev_symlinks() { rm -rf "/opt/google/chrome/libudev.so.0" } remove_udev_symlinks # Only remove the defaults file if it is not empty. An empty file was probably # put there by the sysadmin to disable automatic repository configuration, as # per the instructions on the package download page. if [ -s "$DEFAULTS_FILE" ]; then # Make sure the package defaults are removed before the repository config, # otherwise it could result in the repository config being removed, but the # package defaults remain and are set to not recreate the repository config. # In that case, future installs won't recreate it and won't get auto-updated. rm "$DEFAULTS_FILE" || exit 1 fi # Remove any Google repository added by the package. clean_sources_lists uninstall_key