1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
#!/usr/bin/env bash
# TODO:
# -
# FIXME:
# - PyQt5 from pypi is available only for x86_64
# Cleanup the console
echo -en "\ec"
# Exit on error
set -e
# Enable verbose shell output
set -x
# Allow to use ldconfig under Debian Jessie
export PATH="/sbin:$PATH"
########################################################################
# Create the AppDir
########################################################################
APP="LinuxShowPlayer"
LOWERAPP=${APP,,}
if [ -d $APP/$APP.AppDir/ ]; then
rm -rf $APP/$APP.AppDir/
fi
mkdir -p $APP/$APP.AppDir/
cd $APP/
########################################################################
# Get Build dependencies (and virtualenv)
########################################################################
sudo apt-get update -qq || true
sudo apt-get -y install build-essential python3-dev libffi-dev libportmidi-dev libasound2-dev \
libjack-jackd2-dev bison flex libcppunit-dev bison flex uuid-dev libprotobuf-dev protobuf-compiler \
libprotoc-dev libncurses5-dev autoconf libtool rsync wget python3-pip virtualenv
# If the python3 version is < 3.7
if [ `python3 -c 'import sys; print(sys.version_info.major >= 3 and sys.version_info.minor >= 7)'` = "False" ];
then
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
# Install and initialize pyenv, if needed
if ! [ -x "$(command -v pyenv)" ];
then
sudo apt-get -y install libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev curl git llvm libncurses5-dev libncursesw5-dev xz-utils
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
fi
eval "$(pyenv init -)"
pyenv install -s 3.7.6
pyenv global 3.7.6
fi
# Install some via pip
pip3 install --user -U protobuf pip setuptools virtualenv
########################################################################
# Source some helper functions
########################################################################
wget "https://github.com/AppImage/pkg2appimage/raw/master/functions.sh"
. ./functions.sh
########################################################################
# Get the last version of the app from GitHub
########################################################################
REPO="FrancescoCeruti/linux-show-player"
if [ -z "$1" ]; then
VERSION="master"
elif [ "$1" = "latest" ]; then
VERSION=$(wget -q "https://api.github.com/repos/$REPO/releases/latest" -O - | grep -E "tag_name" | cut -d'"' -f4)
else
VERSION="$1"
fi
DLD="https://github.com/$REPO/archive/"$VERSION".tar.gz"
ARCHIVE="linux-show-player-"$VERSION".tar.gz"
# Download in the "$APP" directory
wget $DLD -O $ARCHIVE
########################################################################
# Get the dependencies
########################################################################
# Get OLA
OLA_VERSION="0.10.3"
OLA_FILE="ola-"$OLA_VERSION
wget -nc -c "https://github.com/OpenLightingProject/ola/releases/download/"$OLA_VERSION"/"$OLA_FILE".tar.gz"
# We need to re-compile PyGObject aganist our python version (may become unecessary in future)
# Get PyGObject
apt-get source python3-gi
# To be able to compile it we need to install some build-dependecies
sudo apt-get -y build-dep python3-gi
# Get .deb(s)
mkdir -p debs
cd debs
apt-get download libglib2.0-0 libgstreamer1.0-0 gstreamer1.0-plugins-base libgirepository-1.0-1 \
gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad gstreamer1.0-alsa \
gstreamer1.0-pulseaudio gstreamer1.0-libav gstreamer1.0-fluendo-mp3 gir1.2-gstreamer-1.0 \
gir1.2-gst-plugins-base-1.0 gir1.2-glib-2.0 libportmidi0 alsa-utils libpulse0 libffi6
cd ..
########################################################################
# Create a virtualenv inside the AppDir
########################################################################
PYVERSION=`python3 -V | cut -d' ' -f2 | cut -d'.' -f1,2`
SYS_PYLIB=`python3 -c 'import os; print(os.path.dirname(os.__file__))'`
APP_PYLIB='usr/lib/python'$PYVERSION
cd $APP.AppDir/
# Create the virtualenv in "usr" with python3, coping the files
virtualenv -p python3 --always-copy usr
# Copy all the python stdlib files skipped by virtualenv (why??)
rsync -tr $SYS_PYLIB/* $APP_PYLIB/ --exclude="*-packages/"
# For some reason using "--always-copy" even "python"/"python3" are not linked but copied
# fix that and save ~10MB of space
cd usr/bin
rm python3 python
ln -s python$PYVERSION python
ln -s python$PYVERSION python3
cd ../..
# Create "sitecustomize.py" to load "site-packages"
cat > $APP_PYLIB"/sitecustomize.py" <<EOF
import sys, os
sys.path.append((os.path.join(os.path.dirname(__file__), 'site-packages')))
EOF
# Patch site.py with empty "USER" paths
sed -i -e 's|USER_BASE = None|USER_BASE = ""|g' $APP_PYLIB"/site.py"
sed -i -e 's|USER_SITE = None|USER_SITE = ""|g' $APP_PYLIB"/site.py"
########################################################################
# "Install" the app in the AppDir
########################################################################
# Activate the virtualenv
source usr/bin/activate
# Install the last version of pip & setuptools
pip3 install -U pip setuptools
# Install the application and it's dependencies
pip3 install PyQt5==5.14.1 protobuf ../$ARCHIVE
# Deactivate the virtualenv
deactivate
# Patch absolute paths created by the virtualenv
REPLACE="/home.*/$APP/$APP\.AppDir/usr"
find usr/bin/ -type f -exec grep -Iq . {} \; -and -print0 | xargs -0 sed -i -e 's|'$REPLACE'|././|g'
# Build & Install OLA (only the python client)
cd ..
tar xzf $OLA_FILE".tar.gz"
cd $OLA_FILE
# configure
autoreconf -i
PYTHON=python3 ./configure --enable-python-libs
# generate the protobuf files
make builtfiles
# remove unwanted files
rm python/ola/Makefile.mk || true
rm python/ola/*Test.py || true
rm python/ola/rpc/Makefile.mk || true
rm python/ola/rpc/*Test.py || true
# copy the python client
cp -r python/ola ../$APP.AppDir/$APP_PYLIB/site-packages/
cd ..
# Build & Install PyGObject
cd pygobject-3*
# configure
./configure --disable-cairo --disable-glibtest
# build
make
# "install"
cp -r gi ../$APP.AppDir/$APP_PYLIB/site-packages/
cd ../$APP.AppDir
# Install from deb packages
find ../debs/ -name *deb -exec dpkg -x {} . \;
# Bundle dependencies
set +x
copy_deps
delete_blacklisted
move_lib
set -x
########################################################################
# Workarounds/Patches
########################################################################
# Create libjack.so as a link to libjack.so.0 otherwise ctypes.util.find_libary(name) is not able to find it
# NOTE: this may be necessary for every "find_library(name)" target that should be picked from the AppImage
# NOTE: cffi.dlopen(name) will use "find_library(name)" if name is not a specific libaray name/path
# grep -r --include '*.py' "find_library('" .
# grep -r --include '*.py' "dlopen('" .
cd usr/lib/x86_64-linux-gnu
ln -s libjack.so.0 libjack.so
cd ../../..
# Workaround to set environment variable
mv usr/bin/linux-show-player usr/bin/linux-show-player-origin
cat > usr/bin/linux-show-player <<EOF
#!/bin/sh
# Set GStreamer variables
export GST_PLUGIN_PATH_1_0="././/lib/x86_64-linux-gnu/gstreamer-1.0/"
export GST_PLUGIN_SCANNER_1_0="././/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0/gst-plugin-scanner"
# Allow GObject-Introspection to work correctly
export GI_TYPELIB_PATH="././/lib/girepository-1.0"
# Invoke the app with the arguments passed
linux-show-player-origin \$@
EOF
chmod +x usr/bin/linux-show-player
# Otherwise in Fedora cannot load the Qt platform plugin "xcb"
cp $(ldconfig -p | grep libEGL.so.1 | cut -d ">" -f 2 | xargs) ./usr/lib/
# move libpulsecommon-<version>.so to the parent directory
mv usr/lib/x86_64-linux-gnu/pulseaudio/* usr/lib/x86_64-linux-gnu/
rm -rf usr/lib/x86_64-linux-gnu/pulseaudio/
# make sure that GI_TYPELIB_PATH point to the right directory (some distro put gir files in different locations)
mv usr/lib/x86_64-linux-gnu/girepository-1.0/* usr/lib/girepository-1.0/ || true
rm -rf usr/lib/x86_64-linux-gnu/girepository-1.0 || true
# Remove some "garbage"
rm -rf ./home || true
rm -rf ./var || true
rm -rf ./etc || true
rm -rf usr/lib/udev/ || true
rm -rf usr/lib/systemd/ || true
rm -rf usr/lib/x86_64-linux-gnu/mesa/ || true
rm -rf usr/lib/x86_64-linux-gnu/mesa-egl/ || true
rm -rf usr/lib/x86_64-linux-gnu/gio/ || true
rm -rf usr/share/alsa || true
rm -rf usr/share/doc || true
rm -rf usr/share/lintian || true
rm -rf usr/share/man || true
rm -rf usr/share/python-wheels || true
rm -rf usr/lib/python-wheels || true
rm -rf usr/share/sounds || true
########################################################################
# Finalize the AppDir
########################################################################
cd ..
# Extract the archive
ARCHIVE_CONT="linux-show-player-content"
mkdir -p $ARCHIVE_CONT
tar zxf $ARCHIVE -C $ARCHIVE_CONT --strip-components 1
# Copy icons/mime
MIME_DIR="$APP.AppDir/usr/share/mime"
DESKTOP_DIR="$APP.AppDir/usr/share/applications"
ICONS_DIR="$APP.AppDir/usr/share/icons/default/512x512/apps"
MIME_ICONS_DIR="$APP.AppDir/usr/share/icons/default/512x512/mimetypes"
mkdir -p $MIME_DIR
mkdir -p $ICONS_DIR
mkdir -p $DESKTOP_DIR
mkdir -p $MIME_ICONS_DIR
cp $ARCHIVE_CONT/dist/linuxshowplayer.xml $MIME_DIR
cp $ARCHIVE_CONT/dist/linuxshowplayer.png $ICONS_DIR
cp $ARCHIVE_CONT/dist/linuxshowplayer.desktop $DESKTOP_DIR
cp $ARCHIVE_CONT/dist/application-x-linuxshowplayer.png $MIME_ICONS_DIR
cd $APP.AppDir/
# Apprun & desktop-integration
get_apprun
get_icon
get_desktop
get_desktopintegration $LOWERAPP
########################################################################
# Package the AppDir as an AppImage
########################################################################
# At this point, you should be able to run the application by executing
# ./AppRun
cd ..
generate_type2_appimage
# To check libraries opened from the base system
#strace -e open -f ./AppRun 2>&1 | grep '("/usr/lib/' | grep so
|