Last active
September 20, 2024 22:09
-
-
Save ruario/d44cb29feb83c9191b1adfdfd318c617 to your computer and use it in GitHub Desktop.
This script allows you to extract and register a Vivaldi Linux deb or rpm package with your Desktop Environment using a unique keyword, to assist with multiple side-by-side "installs".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
a=off | |
if [ "x${1:-}" = "x-n" ] && [ -n "${2:-}" ]; then | |
n="${2#vivaldi-}" | |
c="Vivaldi-$n" | |
a=on | |
echo "Using the name: vivaldi-$n" | |
shift 2 | |
fi | |
if [ -n "${1:-}" ]; then | |
if echo "$1" | grep -qE "vivaldi-(stable|snapshot)[_-]([0-9]+\.){3}[0-9]+-[0-9]+[_\.][a-z0-9_]+\.(rpm|deb)" && [ -e "$1" ]; then | |
v="${1##*/}" | |
else | |
echo "$1 is not a Vivaldi package" >&2 | |
exit 1 | |
fi | |
else | |
echo -e "Supply the name of the Vivaldi .deb or .rpm package you wish to register like so:\n\n $0 vivaldi-stable-6.1.3035.84-1.x86_64.rpm\n" >&2 | |
exit 1 | |
fi | |
cd "$(dirname "$1")" | |
[ "$a" = on ] && d="${v%.*}-$n" || d="${v%.*}" | |
[ -d "$d" ] && rm -r "$d" | |
mkdir "$d" | |
cd "$d" | |
echo "Extracting: $v" >&2 | |
if [ "${v##*.}" = deb ]; then | |
ar p "../$v" data.tar.xz | tar Jx ./opt ./usr/share/applications --strip 3 | |
else | |
tail -c+"$(grep -Fabom1 7zXZ "../$v" | cut -d: -f1)" "../$v" | xz -d | cpio --quiet -id ./opt\* ./usr/share/applications\* | |
mv opt/vivaldi*/* . | |
mv usr/share/applications . | |
rm -r opt usr | |
fi | |
w="$(find . -maxdepth 1 -type f \( -name vivaldi -o -name vivaldi-snapshot \))" | |
x="$(echo applications/*.desktop)" | |
chmod 755 $x | |
if [ "$a" = on ]; then | |
f="vivaldi-$n" | |
sed -i "s,/${w#*/}/,/$f/,g;/^exec -a/s,\"\$@\", --user-data-dir=\"\${XDG_CONFIG_HOME:-\$HOME/.config}/$f\" --class=\"$c\" \"\$@\"," $w | |
sed -i "s,^Icon=${w#*/},Icon=$f,;0,/^Name=/s,^Name=.*,Name=Vivaldi ($n),;/^StartupNotify/ i StartupWMClass=$c" $x | |
if [ -x update-ffmpeg ]; then | |
sed -i "s,/${w#*/}/,/$f/,g" update-ffmpeg | |
fi | |
else | |
f="${w#*/}" | |
fi | |
cat <<REGISTER> register | |
#!/bin/sh -eu | |
update_dbs () { | |
touch -c "\${XDG_DATA_HOME:-\$HOME/.local/share}/icons/hicolor" 2>/dev/null ||: | |
if command -v gtk-update-icon-cache >/dev/null 2>&1; then | |
gtk-update-icon-cache -tq "\${XDG_DATA_HOME:-\$HOME/.local/share}/icons/hicolor" 2>/dev/null ||: | |
fi | |
if command -v update-desktop-database >/dev/null 2>&1; then | |
update-desktop-database -q "\${XDG_DATA_HOME:-\$HOME/.local/share}/applications" 2>/dev/null ||: | |
fi | |
} | |
if [ "x\${1:-}" = "x-d" ]; then | |
rm -fv "\${XDG_DATA_HOME:-\$HOME/.local/share}/applications/$f.desktop" "\${XDG_DATA_HOME:-\$HOME/.local/share}/icons/hicolor"/*/apps/$f.png | |
if [ -h "\$HOME/bin/$f" ]; then | |
rm -v "\$HOME/bin/$f" | |
elif [ -h "\${XDG_DATA_HOME:-\$HOME/.local/share}/../bin/$f" ]; then | |
rm -v "\$(cd "\${XDG_DATA_HOME:-\$HOME/.local/share}/../bin"; pwd)/$f" | |
fi | |
update_dbs | |
exit | |
fi | |
cd "\${0%/*}" | |
for p in product_logo_*.png; do | |
s="\$(echo \$p | grep -o '[0-9]\+')" | |
l="\${XDG_DATA_HOME:-\$HOME/.local/share}/icons/hicolor/\${s}x\$s/apps" | |
mkdir -p "\$l" | |
ln -vfs "\$PWD/\$p" "\$l/$f.png" | |
done | |
sed -i "s,^Exec=.*vivaldi\(-stable\|-snapshot\)* ,Exec=\$PWD/${w#*/} ," $x | |
mkdir -p "\${XDG_DATA_HOME:-\$HOME/.local/share}/applications" | |
ln -vfs "\$PWD/$x" "\${XDG_DATA_HOME:-\$HOME/.local/share}/applications/$f.desktop" | |
if [ -d "\$HOME/bin" ]; then | |
ln -vfs "\$PWD/${w#*/}" "\$HOME/bin/$f" | |
elif [ -d "\${XDG_DATA_HOME:-\$HOME/.local/share}/../bin" ]; then | |
ln -vfs "\$PWD/${w#*/}" "\$(cd "\${XDG_DATA_HOME:-\$HOME/.local/share}/../bin"; pwd)/$f" | |
fi | |
update_dbs | |
REGISTER | |
chmod 755 "register" | |
printf "Creating symlinks:\n\n" >&2 | |
cd - >/dev/null | |
if [ ! -e "$f" ] || [ -h "$f" ]; then | |
ln -fsT "$d" "$f" | |
d="$f" | |
fi | |
"$d/register" | |
cat <<HELP | |
NOTE: You may need to re-login before $f shows up! | |
*** | |
To remove symlinks and de-register $f issue: | |
'$PWD/$d/register' -d | |
HELP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running it with
-n
followed by your chosed name/keyword/stream (e.g.-n alt
) and then the Vivaldi package would result in something like the following:This version of Vivaldi would now be available from Gnome, KDE Plasma, Xfce, etc. menus and launcher as "Vivaldi (alt)". It will use its own settings and will not be touched when you upgrade other streams such as stable or snapshot.
Alternatively you can skip
-n keyword
and the script will just register the build as is, without changing the stream.It does not really matter so much if you choose an rpm or deb package, since an install is not taking place and thus neither the
rpm
nordpkg
commands need to be present.It may be slightly more reliable to use the rpm because the deb package needs
ar
for extraction and some distros do not install this by default. While the rpm package does rely oncpio
as part of its extraction, this is (almost always) preinstalled.In either case, if you found that
ar
orcpio
were not present, just install the "binutils" or "cpio" packages (respectively) via your package manager, before attempting to run the script again.