# Description: Web browser by Google (stable)
# URL: https://chromereleases.googleblog.com/
# Maintainer: Petar Petrov, slackalaxy at gmail dot com
# Depends on: brotli cups double-conversion gnutls graphite2 icu libidn2 lm_sensors nss qt5 qt6-base wayland

name=google-chrome
version=131.0.6778.85
#version=$(ar p $name-stable_current_amd64.deb control.tar.xz 2> /dev/null | tar JxO ./control 2> /dev/null | grep Version | awk '{print $2}' | cut -d- -f1)
release=1
source=(https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
	$name.fonts.conf)
renames=($name-stable-${version}_amd64.deb SKIP)

build() {
	bsdtar -xf $name-stable-${version}_amd64.deb
	bsdtar -xf data.tar.xz

	# Modified from google-chrome.SlackBuild for Slackware from /extra
	# http://slackware.uk/slackware/slackware64-current/extra/google-chrome/
	
	# The handbook explicitly states that packages should not place stuff in /opt
	mkdir -p $PKG/usr/lib/$name
	cp -a $SRC/opt/google/chrome/* $PKG/usr/lib/$name
	
	# Slackware says this needs to be setuid root:
	chmod 4711 $PKG/usr/lib/$name/chrome-sandbox
	
	# Link to the standard Mozilla library names:
	sed -i 's,libnss3.so.1d,libnss3.so\x00\x00\x00,g;
		s,libnssutil3.so.1d,libnssutil3.so\x00\x00\x00,g;
		s,libsmime3.so.1d,libsmime3.so\x00\x00\x00,g;
		s,libssl3.so.1d,libssl3.so\x00\x00\x00,g;
		s,libplds4.so.0d,libplds4.so\x00\x00\x00,g;
		s,libplc4.so.0d,libplc4.so\x00\x00\x00,g;
		s,libnspr4.so.0d,libnspr4.so\x00\x00\x00,g;' $PKG/usr/lib/$name/chrome
	
	# Copy data
	cp -a $SRC/usr/share $PKG/usr
	
	# Remove docs
	rm -rf $PKG/usr/share/{doc,menu}

	# Remove locales, except for en_US
	find $PKG/usr/lib/google-chrome/locales/ -type f -not -name "en-US.pak" -delete
	
	mkdir -p $PKG/usr/share/pixmaps/
	cp $PKG/usr/lib/$name/product_logo_48.png $PKG/usr/share/pixmaps/$name.png

	# Finally, create a new symlink
	mkdir -p $PKG/usr/bin
	cd $PKG/usr/bin
	ln -s ../lib/$name/$name .
        ln -s ../lib/$name/$name $name-stable
	cd -

	mkdir -p $PKG/etc/fonts
	cp -a $SRC/$name.fonts.conf $PKG/etc/fonts/$name.conf
	sed -i "3 i export FONTCONFIG_FILE=/etc/fonts/$name.conf" $PKG/usr/lib/$name/$name
}