Skip to content

Instantly share code, notes, and snippets.

@gornostal
Created February 19, 2017 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gornostal/53b70ba960b12e4e10dec9b8936ee6fd to your computer and use it in GitHub Desktop.
Save gornostal/53b70ba960b12e4e10dec9b8936ee6fd to your computer and use it in GitHub Desktop.
#!/bin/bash -eux
# This is a very simple example on how to bundle a Python application as an AppImage
# using virtualenv and AppImageKit using Ubuntu
# NOTE: Please test the resulting AppImage on your target systems and copy in any additional
# libraries and/or dependencies that might be missing on your target system(s).
########################################################################
# Get virtualenv on the target system
########################################################################
sudo apt-get update
# Install build deps
sudo apt-get -y install zsync git libarchive-dev autoconf libtool make gcc libtool libfuse-dev \
liblzma-dev libglib2.0-dev libssl-dev libinotifytools0-dev liblz4-dev equivs libcairo-dev
sudo apt-get -y install python-virtualenv wget python-gi gobject-introspection python-gobject
########################################################################
# Source some helper functions
########################################################################
wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh
. ./functions.sh
########################################################################
# Create the AppDir
########################################################################
APP=PythonGTK3Hello
LOWERAPP=${APP,,}
ARCH=x86-64
mkdir -p $APP/$APP.AppDir/
cd $APP/
cd $APP.AppDir/
########################################################################
# Create a virtualenv inside the AppDir
########################################################################
virtualenv usr
# Install python dependencies into the virtualenv
# ./usr/bin/pip install ...
# The following ones cannot be installed using pip
mkdir -p usr/share/pyshared/
mkdir -p usr/lib/python2.7/site-packages
cp -r /usr/lib/python2.7/dist-packages/gi usr/lib/python2.7/site-packages/
cp -r /usr/lib/python2.7/dist-packages/gobject/ usr/lib/python2.7/site-packages/
cp -r /usr/lib/python2.7/dist-packages/glib/ usr/lib/python2.7/site-packages/
########################################################################
# "Install" a simple sample app in the AppDir
########################################################################
mkdir -p usr/bin/
cat > usr/bin/$LOWERAPP <<\EOF
#!/usr/bin/env python
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
win = Gtk.Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()
EOF
chmod a+x usr/bin/$LOWERAPP
########################################################################
# Finalize the AppDir
########################################################################
get_apprun
cat > $LOWERAPP.desktop <<EOF
[Desktop Entry]
Name=$APP
Exec=$LOWERAPP
Icon=$LOWERAPP
Comment=A hello world app written in GTK3 and Python
EOF
# Make the AppImage ask to "install" itself into the menu
get_desktopintegration $LOWERAPP
cp /root/appImageTest/logview.png $LOWERAPP.png
########################################################################
# Bundle dependencies
########################################################################
copy_deps ; copy_deps ; copy_deps
delete_blacklisted
move_lib
VERSION=1
########################################################################
# Package the AppDir as an AppImage
########################################################################
# At this point, you should be able to run the application by executing
# ./AppRun
cd ..
generate_appimage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment