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