Skip to content

Instantly share code, notes, and snippets.

@probonopd
Last active April 8, 2023 01:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save probonopd/3d5d045619e3ff239b0a43406d75cd2e to your computer and use it in GitHub Desktop.
Save probonopd/3d5d045619e3ff239b0a43406d75cd2e to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script converts the Firefox .tar.bz2 into a Firefox AppImage
# NOTE: This is for demonstration only. For a real production AppImage, one would add
# * update information (for binary delta updates)
# * embedded digital signature (to validate authorship)
# * possibly additional dependencies (if needed)
# * additional metadata to help desktop integration
# Download and extract Firefox .tar.bz2
DLD=$(wget -q "https://www.mozilla.org/en-US/firefox/all/" -O - | grep -E "os=linux64&lang=en-US" | cut -d'"' -f2 | head -n 1)
wget -c "$DLD" --trust-server-names
export VERSION=$(ls firefox-*.tar.bz2 | cut -d "-" -f 2 | sed -e 's|.tar.bz2||g')
tar xf firefox*.tar.bz2
# Create AppDir
mkdir -p appdir/usr/bin
cd appdir/
cp -r ../firefox/* usr/bin/
find . -name default128.png -exec cp {} firefox.png \;
mkdir -p usr/share/icons/hicolor/128x128/apps
find . -name default128.png -exec cp {} usr/share/icons/hicolor/128x128/apps/firefox.png \;
# Add desktop file
cat > firefox.desktop <<EOF
[Desktop Entry]
Type=Application
Name=Firefox
Icon=firefox
Exec=firefox %u
Categories=GNOME;GTK;Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;x-scheme-handler/ftp;x-scheme-handler/chrome;video/webm;application/x-xpinstall;
StartupNotify=true
EOF
# Add AppRun script that sets required environment variable (since AppImages are mounted at varying different each time)
cat > AppRun <<\EOF
#!/bin/bash
HERE="$(dirname "$(readlink -f "${0}")")"
export MOZ_LEGACY_PROFILES=1 # Prevent per installation profiles in ff > 68
"$HERE/usr/bin/firefox" "$@"
EOF
chmod a+x AppRun
cd ..
# Turn AppDir into AppImage
wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
chmod +x *.AppImage
./appimagetool-x86_64.AppImage appdir/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment