Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active March 29, 2023 14:08
Show Gist options
  • Save ruario/a98005997f7c111ba44d908594f028dd to your computer and use it in GitHub Desktop.
Save ruario/a98005997f7c111ba44d908594f028dd to your computer and use it in GitHub Desktop.
A script to convert a Vivaldi rpm or deb into Appimage format.
#!/bin/sh
#
# appimage-vivaldi.sh (version 0.2)
#
# A script to convert a Vivaldi rpm or deb into Appimage format.
# Before you use this script, you may need to adjust the following
# variable, based on the name and location of AppImageAssistant on
# your system.
AppImageAssistant="$HOME/bin/AppImageAssistant_6-x86_64.AppImage"
# Use the most recent Vivaldi package in the current working
# directory or whatever the user has defined as the first option
# to this script.
if [ -n "$1" ]; then
PKG="$1"
else
PKG=`ls -t vivaldi*.rpm vivaldi*.deb 2>/dev/null | head -n 1`
fi
# Exit as soon as an error is encountered.
set -e
# Check that a suitable package has been specified.
VIVALDI_PKG_INFO=`echo "$PKG" | sed -n 's/.*\(vivaldi-[a-z]\+\)[_-]\(\([0-9]\+\.\)\{3\}[0-9]\+\)-[0-9]\+[_\.]\([a-z0-9_]\+\)\.\(deb\|rpm\)$/\1:\2:\4/p'`
if [ -z "$VIVALDI_PKG_INFO" ]; then
echo 'You must specify the path to a locally stored Vivaldi Linux package.' >&2
echo "Example usage: $0 vivaldi-stable-1.4.589.29-1.x86_64.rpm" >&2
exit 1
fi
if [ ! -r "$PKG" ]; then
echo "$PKG is either not present or cannot be read" >&2
exit 1
fi
# Define the various variables obtained from information in the
# original package name.
VIVALDI_STREAM=`echo "$VIVALDI_PKG_INFO" | cut -d: -f1`
case "$VIVALDI_STREAM" in
vivaldi-stable) VIVALDI_STREAM=vivaldi ;;
vivaldi-beta) VIVALDI_STREAM=vivaldi ;;
esac
VIVALDI_VERSION=`echo "$VIVALDI_PKG_INFO" | cut -d: -f2`
VIVALDI_ARCH=`echo "$VIVALDI_PKG_INFO" | cut -d: -f3`
case "$VIVALDI_ARCH" in
amd64) VIVALDI_ARCH=x86_64 ;;
esac
APPDIR="$VIVALDI_STREAM-$VIVALDI_VERSION-$VIVALDI_ARCH.AppDir"
APPIMAGE="$VIVALDI_STREAM-$VIVALDI_VERSION-$VIVALDI_ARCH.AppImage"
# Abort if an AppImage has been created for this version before.
if [ -e "$APPIMAGE" ]; then
echo "$APPIMAGE already exists" >&2
exit 1
fi
# Extract the package contents.
available () {
command -v "$1" >/dev/null 2>&1
}
extract_rpm () {
if available bsdtar; then
bsdtar xf "$1" -C "$APPDIR"
elif available cpio; then
tail -c+`grep -abom1 7zXZ "$1" | cut -d: -f1` "$1" | xz -d | (cd "$APPDIR"; cpio --quiet -id)
else
echo 'You must install BSD tar or GNU cpio to use this script' >&2
exit 1
fi
}
extract_deb () {
if available bsdtar; then
DEB_EXTRACT_COMMAND='bsdtar xOf'
elif available ar; then
DEB_EXTRACT_COMMAND='ar p'
else
echo 'You must install BSD tar or GNU binutils to use this script' >&2
exit 1
fi
$DEB_EXTRACT_COMMAND "$1" data.tar.xz | tar xJ -C "$APPDIR"
}
if [ -d "$APPDIR" ]; then
rm -r "$APPDIR"
fi
mkdir "$APPDIR"
case "$PKG" in
*deb) extract_deb "$PKG" ;;
*rpm) extract_rpm "$PKG" ;;
esac
# Cleanup the package contents.
cd "$APPDIR"
rm -r etc
sed -i 's,/usr/bin/,,' usr/share/applications/*.desktop
rm -fr usr/share/xfce4
mkdir -p usr/bin
(
cd usr/bin
for link in `find . -type l`; do
ln -fs ../../opt/$VIVALDI_STREAM/$VIVALDI_STREAM $link
done
)
## The following probably isn't required but let's get the usr/share
## icon layout correct, just in case.
for png in opt/$VIVALDI_STREAM/product_logo_*.png; do
pngsize="${png##*/product_logo_}"
mkdir -p usr/share/icons/hicolor/${pngsize%.png}x${pngsize%.png}/apps
(
cd usr/share/icons/hicolor/${pngsize%.png}x${pngsize%.png}/apps/
ln -s ../../../../../../opt/$VIVALDI_STREAM/product_logo_${pngsize} $VIVALDI_STREAM.png
)
done
# Setup some links for AppImage.
ln -s opt/$VIVALDI_STREAM/$VIVALDI_STREAM AppRun
ln -s opt/$VIVALDI_STREAM/product_logo_256.png $VIVALDI_STREAM.png
ln -s usr/share/applications/*.desktop $VIVALDI_STREAM.desktop
cd ..
# Create the AppImage.
$AppImageAssistant "$APPDIR" "$APPIMAGE"
# Cleanup (remove) working directory.
rm -r "$APPDIR"
@probonopd
Copy link

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