Chrome on CL. Again

I know of a couple of threads devoted to installing Chrome on CL, but they are all pretty old, hence quite possibly obsolete. Anyway, I’ve looked into running Brave or some other browser, but I am much too deeply invested in Chrome at this point, and breaking away from it would call for major sacrifice. To make a long story short, I’ve identified two installation “methods” (aside from the Flatpak, that is):

curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
rpm2cpio google-chrome*.rpm | ( cd /; cpio -idv)
f=/etc/environment; s='export FONTCONFIG_PATH=/usr/share/defaults/fonts'; touch $f; if ! grep -q "$s" $f; then echo $s >> $f; fi

And:

curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
sudo rpm --import https://dl-ssl.google.com/linux/linux_signing_key.pub
rpm -U --nodeps google-chrome*.rpm
sed -i 's\/usr/bin/google-chrome-stable\env FONTCONFIG_PATH=/usr/share/defaults/fonts /usr/bin/google-chrome-stable\g' /usr/share/applications/google-chrome.desktop

What worked for me so far was a combination of the two:

curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
rpm2cpio google-chrome*.rpm | ( cd /; cpio -idv)
sed -i 's\/usr/bin/google-chrome-stable\env FONTCONFIG_PATH=/usr/share/defaults/fonts /usr/bin/google-chrome-stable\g' /usr/share/applications/google-chrome.desktop

The only thing that I cannot get in this manner is the Chrome icon. The .desktop file points to a google-chrome, which doesn’t exist, and changing that to google-chrome-stable or /opt/google/chrome/google-chrome still gives you nothing.

Any thoughts?

The “google-chrome” icon is installed via postinstall RPM scriptlet. On Clear Linux, one typically extracts the RPM contents and moves files into place. I check also the postinstall section, included in the RPM.

rpm -qp --scripts google-chrome-stable-117.0.5938.149-1.x86_64.rpm | more

Assuming you have Google Chrome installed, the following snippet installs the google-chrome icon in various sizes. Be sure to revert the icon change in your desktop file back to google-chrome.

# Add icons to the system icons; installs to /usr/share/icons/hicolor/.
for icon in \
   product_logo_32.png product_logo_48.png product_logo_256.png product_logo_128.png \
   product_logo_16.png product_logo_64.png product_logo_24.png
do 
   size=$(echo "$icon" | sed 's/[^0-9]//g')
   sudo xdg-icon-resource install --size "$size" /opt/google/chrome/${icon} "google-chrome"
done
2 Likes

Some time ago, I stopped sharing scripts due to time constraints maintaining them. This one installs Google Chrome the first time, otherwise updates on subsequent use. I run it periodically. At this moment, Google Chrome is current on my system.

$ ~/bin/upd-chrome-stable 
Google Chrome stable 117.0.5938.149 (current)

upd-chrome-stable - Installer/updater combo

#!/bin/bash
#-------------------------------------------------------------------------------
# Install and update script for Google Chrome stable.
# https://pkgs.org/search/?q=google%20chrome
#-------------------------------------------------------------------------------

# shellcheck disable=SC2001,SC2143,SC2164

URL1='https://www.ubuntuupdates.org/package/google_chrome/stable/main/base/google-chrome-stable'
URL2='https://dl.google.com/linux/chrome/rpm/stable/x86_64/google-chrome-stable'

NEW_VER=$(curl -s "$URL1" | awk -F'>' '/Version:/ { print $NF; exit }')
BROWSER_EXE="/opt/google/chrome/google-chrome"

if [[ -x "$BROWSER_EXE" ]]; then
   CUR_VER=$($BROWSER_EXE --version 2>/dev/null | awk '{ print $NF }')
else
   CUR_VER="not-installed"
fi

if [[ "$NEW_VER" =~ ^$CUR_VER ]]; then
   echo "Google Chrome stable $CUR_VER (current)"
   exit
elif [[ "$USER" == "root" ]]; then
   echo "Please run the script as a normal user, exiting..."
   exit 1
fi

# Test sudo, exit if wrong password or terminated.
sudo true >/dev/null || exit 2

# Install dependencies.
if [[ ! -x "/usr/bin/curl" || ! -x "/usr/bin/rpm2cpio" ]]; then
   echo "Installing dependencies."
   sudo swupd bundle-add curl package-utils --quiet
fi

#-------------------------------------------------------------------------------

if [[ ! -x "$BROWSER_EXE" ]]; then
   echo "Installing Google Chrome stable ${NEW_VER%%-*}"
else
   echo "Updating Google Chrome stable ${NEW_VER%%-*}"
   # remove older installation via rpm
   sudo rpm -e google-chrome-stable 2>/dev/null
fi

FILE="google-chrome-stable-${NEW_VER}.x86_64.rpm"

cd ~/Downloads

if [[ ! -f "$FILE" ]]; then
   curl -LO "${URL2}-${NEW_VER}.x86_64.rpm"
   if [[ ! -f "$FILE" || -n $(grep "Error 404 (Not Found)" "$FILE") ]]; then
      rm -f "$FILE"
      echo "ERROR: $FILE (No such file at download URL)"
      echo "https://dl.google.com/linux/chrome/rpm/stable/x86_64/"
      exit 1
   fi
fi

mkdir -p /tmp/update.$$ && pushd /tmp/update.$$ >/dev/null
rpm2cpio ~/Downloads/"$FILE" | cpio -idm 2>/dev/null

sudo mkdir -p /opt/google
sudo rm -rf /opt/google/chrome
sudo cp -a usr/share/* /usr/share/.
sudo mv opt/google/chrome /opt/google/.

sudo sed -i 's!/usr/bin/google-chrome-stable!/opt/google/chrome/google-chrome!g' \
   /usr/share/applications/google-chrome.desktop
sudo sed -i 's!^\(Exec=\)\(.*\)!\1env FONTCONFIG_PATH=/usr/share/defaults/fonts \2!g' \
   /usr/share/applications/google-chrome.desktop

popd >/dev/null
rm -fr /tmp/update.$$

# Add icons to the system icons; installs to /usr/share/icons/hicolor/.
for icon in \
   product_logo_32.png product_logo_48.png product_logo_256.png product_logo_128.png \
   product_logo_16.png product_logo_64.png product_logo_24.png
do 
   size=$(echo "$icon" | sed 's/[^0-9]//g')
   sudo xdg-icon-resource install --size "$size" /opt/google/chrome/${icon} "google-chrome"
done

sync
echo "OK"
1 Like

Brave was mentioned above. This one scans up to 10 release pages at GitHub to determine the latest release, excluding pre-releases.

$ ~/bin/upd-brave-stable 
Brave Browser stable 117.1.58.137 (current)

upd-brave-stable - Installer/updater combo

#!/bin/bash
#-------------------------------------------------------------------------------
# Install and update script for Brave Browser stable.
# https://github.com/brave/brave-browser/releases
#-------------------------------------------------------------------------------

# shellcheck disable=SC2001,SC2143,SC2164

FILE="" URL="" VER=""

# Query for the latest release version for Linux, excluding pre-release.
for page in {1..10}; do
   RELVERs=$( curl -s "https://github.com/brave/brave-browser/releases?page=${page}" | awk '
      BEGIN {
         RS  = "<div "
         ret = ""
      }
      />Release v[0-9]/ && !/Pre-release/ && /\/brave\/brave-browser\/releases\/tag\// {
         gsub(/^.*\/tag\/v/, "", $0) # trim the left-right sides of version string
         gsub(/".*$/, "", $0)
         ret = ret " " $0
      }
      END {
         print ret
      }
   ')
   if [ "$RELVERs" ]; then
      for VER in $RELVERs; do
         FILE="brave-browser-${VER}-1.x86_64.rpm"
         URL="https://github.com/brave/brave-browser/releases/download/v${VER}/brave-browser-${VER}-1.x86_64.rpm"
         # Check if the remote resource is available (or found), particularly the Linux RPM file.
         http_code=$(curl -o /dev/null --silent -Iw '%{http_code}' "$URL")
         if [ "$http_code" -eq "302" ]; then
            break
         else
            FILE="" URL=""
         fi
      done
   fi
   [ -n "$FILE" ] && break
done

if [ -z "$FILE" ]; then
   echo "ERROR: Cannot determine the latest release version"
   echo "https://github.com/brave/brave-browser/releases"
   exit 1
fi

NEW_VER="$VER"
BROWSER_EXE="/opt/brave.com/brave/brave-browser"

if [[ -x "$BROWSER_EXE" ]]; then
   CUR_VER=$($BROWSER_EXE --version 2>/dev/null | awk '{ print $NF }')
else
   CUR_VER="not-installed"
fi

if [[ "${CUR_VER}" == *".${NEW_VER}"* ]]; then
   echo "Brave Browser stable $CUR_VER (current)"
   exit 0
elif [[ "$USER" == "root" ]]; then
   echo "Please run the script as a normal user, exiting..."
   exit 1
fi

# Test sudo, exit if wrong password or terminated.
sudo true >/dev/null || exit 2

# Install dependencies.
if [[ ! -x "/usr/bin/curl" || ! -x "/usr/bin/rpm2cpio" ]]; then
   echo "Installing dependencies."
   sudo swupd bundle-add curl package-utils --quiet
fi

#-------------------------------------------------------------------------------

if [[ ! -x "$BROWSER_EXE" ]]; then
   echo "Installing Brave Browser stable $NEW_VER"
else
   echo "Updating Brave Browser stable $NEW_VER"
   # remove older installation via rpm
   sudo rpm -e brave-browser 2>/dev/null
fi

cd ~/Downloads

if [[ ! -f "$FILE" ]]; then
   curl -LO "$URL"
   if [[ ! -f "$FILE" || -n $(grep "^Not Found" "$FILE") ]]; then
      rm -f "$FILE"
      echo "ERROR: $FILE (No such file at download URL)"
      echo "https://github.com/brave/brave-browser/releases"
      exit 1
   fi
fi

mkdir -p /tmp/update.$$ && pushd /tmp/update.$$ >/dev/null
rpm2cpio ~/Downloads/"$FILE" | cpio -idm 2>/dev/null

sudo mkdir -p /opt/brave.com
sudo rm -rf /opt/brave.com/brave
sudo cp -a usr/share/* /usr/share/.
sudo mv opt/brave.com/brave /opt/brave.com/.

sudo sed -i 's!/usr/bin/brave-browser-stable!/opt/brave.com/brave/brave-browser!g' \
   /usr/share/applications/brave-browser.desktop
sudo sed -i 's!^\(Exec=\)\(.*\)!\1env FONTCONFIG_PATH=/usr/share/defaults/fonts \2!g' \
   /usr/share/applications/brave-browser.desktop

popd >/dev/null
rm -fr /tmp/update.$$

# Add icons to the system icons; installs to /usr/share/icons/hicolor/.
for icon in \
   product_logo_64.png product_logo_48.png product_logo_16.png product_logo_32.png \
   product_logo_24.png product_logo_256.png product_logo_128.png
do 
   size=$(echo "$icon" | sed 's/[^0-9]//g')
   sudo xdg-icon-resource install --size "$size" /opt/brave.com/brave/${icon} "brave-browser"
done

sync
echo "OK"
1 Like
2 Likes

This flatpak works like a charm :

2 Likes

The script is awesome! Many thanks! I take it it doesn’t handle the fonts issue, right? Do you happen to have a solution that is more elegant than patching all the chrome-related .desktop files with this below?

sed -i 's\/opt/google/chrome/google-chrome\env FONTCONFIG_PATH=/usr/share/defaults/fonts /opt/google/chrome/google-chrome\g' $file

One can choose to set FONTCONFIG_PATH system-wide or inside the desktop file. I added an additional sed statement above, to upd-chrome-stable and upd-brave-stable. Here, for Google Chrome.

sudo sed -i 's!^\(Exec=\)\(.*\)!\1env FONTCONFIG_PATH=/usr/share/defaults/fonts \2!g' \
   /usr/share/applications/google-chrome.desktop

Likewise, for Brave Browser.

sudo sed -i 's!^\(Exec=\)\(.*\)!\1env FONTCONFIG_PATH=/usr/share/defaults/fonts \2!g' \
   /usr/share/applications/brave-browser.desktop
1 Like

At the time, I made also a combo installer/updater script for Vivaldi Browser. It has been a while since I ran the updater script. This is what it looks like.

$ ./upd-vivaldi-stable 
Password: 
Updating Vivaldi stable 6.2.3105.58
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 96.3M  100 96.3M    0     0  78.8M      0  0:00:01  0:00:01 --:--:-- 79.0M
OK

upd-vivaldi-stable - Installer/updater combo

#!/bin/bash
#-------------------------------------------------------------------------------
# Install and update script for Vivaldi stable.
# https://vivaldi.com/download/
#-------------------------------------------------------------------------------

# shellcheck disable=SC2001,SC2143,SC2164

URL=$(
   curl -s 'https://vivaldi.com/download/' |\
   awk 'BEGIN { RS = "href=" } /vivaldi-stable-.*\.x86_64\.rpm/ { print $1; exit }' |\
   cut -d'"' -f2
)

FILE="${URL##*/}"

if [[ -z "$FILE" ]]; then
   echo "ERROR: vivaldi-stable-*.rpm (No such file at download URL)"
   echo "https://vivaldi.com/download/"
   exit 1
fi

NEW_VER=$(echo "$FILE" | cut -d- -f3)
BROWSER_EXE="/opt/vivaldi/vivaldi"

if [[ -x "$BROWSER_EXE" ]]; then
   CUR_VER=$($BROWSER_EXE --version 2>/dev/null | awk '{ print $2 }')
else
   CUR_VER="not-installed"
fi

if [[ "$NEW_VER" == "$CUR_VER" ]]; then
   echo "Vivaldi stable $CUR_VER (current)"
   exit 0
elif [[ "$USER" == "root" ]]; then
   echo "Please run the script as a normal user, exiting..."
   exit 1
fi

# Test sudo, exit if wrong password or terminated.
sudo true >/dev/null || exit 2

# Install dependencies.
if [[ ! -x "/usr/bin/curl" || ! -x "/usr/bin/rpm2cpio" ]]; then
   echo "Installing dependencies."
   sudo swupd bundle-add curl package-utils --quiet
fi

#-------------------------------------------------------------------------------

if [[ ! -x "$BROWSER_EXE" ]]; then
   echo "Installing Vivaldi stable $NEW_VER"
else
   echo "Updating Vivaldi stable $NEW_VER"
   # remove older installation via rpm
   sudo rpm -e vivaldi-stable 2>/dev/null
fi

cd ~/Downloads

if [[ ! -f "$FILE" ]]; then
   curl -LO "$URL"
   if [[ ! -f "$FILE" || -n $(grep "404 Not Found" "$FILE") ]]; then
      rm -f "$FILE"
      echo "ERROR: $FILE (No such file at download URL)"
      echo "https://vivaldi.com/download/"
      exit 1
   fi
fi

mkdir -p /tmp/update.$$ && pushd /tmp/update.$$ >/dev/null
rpm2cpio ~/Downloads/"$FILE" | cpio -idm 2>/dev/null

sudo mkdir -p /opt
sudo rm -rf /opt/vivaldi
sudo cp -a usr/share/* /usr/share/.
sudo mv opt/vivaldi /opt/.

sudo sed -i 's!/usr/bin/vivaldi-stable!/opt/vivaldi/vivaldi!g' \
   /usr/share/applications/vivaldi-stable.desktop
sudo sed -i 's!^\(Exec=\)\(.*\)!\1env FONTCONFIG_PATH=/usr/share/defaults/fonts \2!g' \
   /usr/share/applications/vivaldi-stable.desktop

popd >/dev/null
rm -fr /tmp/update.$$

# Add icons to the system icons; installs to /usr/share/icons/hicolor/.
for icon in \
   product_logo_16.png product_logo_256.png product_logo_24.png product_logo_64.png \
   product_logo_32.png product_logo_128.png product_logo_22.png product_logo_48.png
do 
   size=$(echo "$icon" | sed 's/[^0-9]//g')
   sudo xdg-icon-resource install --size "$size" /opt/vivaldi/${icon} --novendor "vivaldi"
done

sync
echo "OK"
2 Likes

Many thanks! Interestingly, this does not fix the fonts on Chrome-based PWAs, which means that all of those will have to be handled separately:

#!/bin/bash

# Do NOT run as root!
if [ $(id -u) == 0 ]
then
  echo "This script should NOT be run as root! Exiting ..."
  exit
fi

echo "Fixing PWA fonts ... "
for file in /home/$USER/.local/share/applications/chrome-*.desktop; do
  if [[ $(grep -c "env FONTCONFIG_PATH=/usr/share/defaults/fonts" $file) -eq 0 ]]
  then
    sed -i 's\/opt/google/chrome/google-chrome\env FONTCONFIG_PATH=/usr/share/defaults/fonts /opt/google/chrome/google-chrome\g' $file
  fi
done
echo "Done!"

I removed my post due to unsure if setting system-wide will break Flatpak applications.

Alright, there’s some confusion going on regarding the fonts issue, and I’m afraid I am responsible for that. So let me clear it out:

  1. You, @marioroy, did not post any system-wide fix, but merely a patch to the .desktop file. Again, apologies for reading your post sloppily;
  2. Doing a system-wide fix (meaning setting the FONTCONFIG_PATH variable system-wide) might be dangerous, hence one should abstain from doing that;
  3. The FONTCONFIG_PATH variable needs to be set in each Chrome-related .desktop file in part. The code for doing that for PWAs has been posted above.
1 Like

Hi @Aqua1ung , I am just curious why you don’t want to use the flatpak from flathub.

I did run the flatpak for a while, and it wasn’t all that bad, though I recall running into some issues with PWA icons, and it also seemed to have some lag when using many windows open etc. (which I now notice happening with the non-flatpak version as well). Anyway, at the time I sorta figured that running the native Linux non-Flatpak version might suit me better and all, though I do not exclude going back to the Flatpak package again in the future.

1 Like