Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script allows you to extract and register with your Desktop Environment a Vivaldi Linux deb build with a unique keyword, to assist with multiple side-by-side installs
#!/bin/sh -eu
if [ "x${1:-}" = "x-n" ] && [ -n "${2:-}" ]; then
name="${2#vivaldi-}"
class="Vivaldi-$name"
echo "Using the name: vivaldi-$name"
shift 2
else
echo -e "You must supply a name like so:\n\n $0 -n keyword\n" >&2
exit 1
fi
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
echo "De-registering..."
rm -fv "${XDG_DATA_HOME:-$HOME/.local/share}/applications/vivaldi-$name.desktop"
find "${XDG_DATA_HOME:-$HOME/.local/share}/icons/hicolor"/*/apps -name vivaldi-$name.png -exec rm -v {} \;
update_dbs
if [ -h "$HOME/bin/vivaldi-$name" ]; then
rm -v "$HOME/bin/vivaldi-$name"
fi
if [ -h "${XDG_DATA_HOME:-$HOME/.local/share}/../bin/vivaldi-$name" ]; then
rm -v "$(cd "${XDG_DATA_HOME:-$HOME/.local/share}/../bin"; pwd)/vivaldi-$name"
fi
exit
fi
if [ -n "${1:-}" ]; then
if echo "$1" | grep -qE "vivaldi-(stable|snapshot)_(([0-9]+\.){3}[0-9]+)-[0-9]+_[a-z0-9]+" && [ -e "$1" ]; then
v="$(basename "$1")"
else
echo "$1 is not a Vivaldi package" >&2
exit 1
fi
else
echo "Supply the name of the Vivaldi .deb package you wish to register" >&2
exit 1
fi
cd "$(dirname "$1")"
d="${v%.deb}-$name"
if [ -d "$d" ]; then
rm -r "$d"
fi
mkdir "$d"
echo "Extracting: $v" >&2
ar p "$v" data.tar.xz | tar JxC "$d" ./opt ./usr/share/applications --strip 3
echo "Registering: $d" >&2
w="$(find "$d" -maxdepth 1 -type f \( -name vivaldi -o -name vivaldi-snapshot \))"
sed -i "/^exec -a/s,\"\$@\", --user-data-dir=\"${XDG_CONFIG_HOME:-$HOME/.config}/vivaldi-$name\" --class=\"$class\" \"\$@\"," "$w"
sed -i "s,^Exec=\(.*vivaldi[a-z0-9-]\+\) ,Exec=$PWD/$w ,;s,^Icon=${w#*/},Icon=vivaldi-$name,;0,/^Name=/s,^Name=.*,Name=Vivaldi ($name),;/^StartupNotify/ i StartupWMClass=$class" "$d/applications"/*.desktop
for p in "$d"/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 -fs "$PWD/$p" "$l/vivaldi-$name.png"
done
install -Dm644 "$PWD/$d/applications"/*.desktop "${XDG_DATA_HOME:-$HOME/.local/share}/applications/vivaldi-$name.desktop"
if [ -d "$HOME/bin" ]; then
ln -fs "$PWD/$w" "$HOME/bin/vivaldi-$name"
elif [ -d "${XDG_DATA_HOME:-$HOME/.local/share}/../bin" ]; then
ln -fs "$PWD/$w" "${XDG_DATA_HOME:-$HOME/.local/share}/../bin/vivaldi-$name"
fi
update_dbs
cat <<HELP
***
NOTE: You may need to re-login before vivaldi-$name shows up!
***
REMOVAL INSTRUCTIONS
Should you wish to "uninstall" in the future, you can de-register this build
like so:
$0 -n $name -d
Then delete the extracted directory:
rm -r "$(dirname "$1")/$d"
HELP
@acramall
Copy link

acramall commented Jul 10, 2020

Hi, is this script replaces rvp.sh?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment