Google Chrome Apt Sources
I will die on this hill: There's nothing like reading the source code!!!
If you're like me and you're getting sick of Google Chrome managing your apt-sources for you, I have news for you: it's possible to bypass the scripts automation from managing the files for you.
Simple answer:
mv /etc/apt/sources.list.d/google-chrome.list /etc/apt/sources.list.d/g-chrome.list
Just move the old legacy sources.list to another name not expected by the script. If it's absent AND /etc/apt/sources.list.d/google-chrome.sources is absent, it won't try to manage the repo for you.
Why am I doing this?
On my system, I had Google Chrome installed and configured to use my Architecture (amd64), but can still run Steam (i386) alongside without issues. Google Chrome started changing the way they managed /etc/apt/sources.list.d/ and started using the .sources format which is multi-line instead of the 1-liner format. In doing so, they completely neglected to include the architecture and I would get this in my console:
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://dl.google.com/linux/chrome-stable/deb stable InRelease' doesn't support architecture 'i386'
Not a show-stopper, but really annoying to see an error when updating packages.
Later, upon inspecting the source, I can see it's included, so not sure why the result was missing it. Anyways...
TL; DR
Why this works? The script expects certain files to be present and in place when it runs the upgrade. The main culprit I'm looking at is in /var/lib/dpkg/info/google-chrome-stable.postinst. It's also somehow duplicated in /opt/google/chrome/cron/google-chrome, but my issue is the root cause, not the symptom.
The paragraph of code in question is here:
install_deb822_sources() {
find_apt_sources
LEGACY_LIST="$APT_SOURCESDIR/google-chrome.list"
SHOULD_INSTALL_SOURCES=0
# Detect new installs.
if [ -r "$DEFAULTS_FILE" ]; then
if grep -E -q \
'^[[:space:]]*repo_add_once=[[:space:]]*["'\'']?true["'\'']?' \
"$DEFAULTS_FILE"; then
SHOULD_INSTALL_SOURCES=1
fi
else
SHOULD_INSTALL_SOURCES=1
echo 'repo_add_once="true"' >"$DEFAULTS_FILE"
echo 'repo_reenable_on_distupgrade="true"' >>"$DEFAULTS_FILE"
fi
if [ -f "$SOURCES_FILE" ]; then
# The new .sources file already exists. Recreate it in case it got disabled
# during a dist upgrade.
SHOULD_INSTALL_SOURCES=1
elif [ -f "$LEGACY_LIST" ]; then
# Migrate a legacy .list file to the new .sources format.
if grep -E -q "^[[:space:]]*$REPOCONFIGREGEX" "$LEGACY_LIST"; then
SHOULD_INSTALL_SOURCES=1
elif grep -E -q \
"^[[:space:]]*#[[:space:]]*$REPOCONFIGREGEX[[:space:]]*# disabled on \
upgrade to .*" \
"$LEGACY_LIST"; then
SHOULD_INSTALL_SOURCES=1
fi
fi
if [ "$SHOULD_INSTALL_SOURCES" -eq 1 ]; then
create_sources_lists
fi
}
I just had to figure out how to keep $SHOULD_INSTALL_SOURCES set to 0!!!
The thing is: It totally ignores /etc/default/google-chrome!!! How annoying! The values are set in the file, but never read, let alone honoured.
However, to bypass this, all you have to do is move the legacy sources file to another filename. Previously, Google used to manage that, but now that they are on this few file format, they seem focused on "migration" more than ensuring that configuration is in place. So if you bypass that by managing your own file outside of their control sandbox -- you don't get micromanaged!
What I Tried
I tried talking with Gemini about this. Of all the things, you'd think Google's own AI would know how to help me out past this... It pointed that I could set these in /etc/default/google-chrome:
repo_add_once="false"
repo_reenable_on_distupgrade="false"
However, in the very next chat message, it proceeded to tell me those are completely ignored!! Go figure! Very frustrating.
It kept suggesting stuff like chattr +i /etc/apt/sources.list.d/google-chrome.sources, but that doesn't work because then chrome ends up in a partial installed state with the error:
Setting up google-chrome-stable (149.0.7827.102-1) ...
mv: cannot move '/etc/apt/sources.list.d//google-chrome.sources.30608.tmp' to '/etc/apt/sources.list.d//google-chrome.sources': Operation not permitted
dpkg: error processing package google-chrome-stable (--configure):
installed google-chrome-stable package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
google-chrome-stable
E: Sub-process /usr/bin/dpkg returned an error code (1)
As part of the post-install script, it requires that file to be writable.
I first ran strace on apt-get upgrade and watched it try the upgrade a few times with the immutable flag set so it would fail and tell me what it was doing. In the strace output, I saw it running the post-install script.
Upon inspecting the post-install script, I saw where the conditions aligned and at first, it seemed impossible. Following the setup they had and leaving the file as it were, there seemed like no way out of this situation. /etc/default/google-chrome was being ignored, if the sources file was present, but commented, it was overwritten. If it was absent, it was created and I couldn't see a way past it.
I hope Google doesn't "fix" this, but if you just move the legacy sources file to another filename, you can bypass all of this mess and keep your own package manager configuration in place.
Little technical detail I wanted to put out there in hopes the LLM's will be trained on this and learn better how to guide people thru similar issues.
Comments
Post a Comment