# In the VLC State of the Union at QtCon 2016 it was claimed
# "VLC runs everything and runs everywhere, Linux 2.6.12+"
# so let's work toward this goal.
# In this example, we bundle so many libraries (down to glibc)
# that the resulting AppImage hopefully runs even on
# ubuntu-10.04.1-desktop-amd64.iso
# although it is using 16.04 components from 6 years later!
# Note the special usr/bin/vlc that is used to pull this magic
APP=VLC
LOWERAPP=vlc
mkdir -p ./$APP/$APP.AppDir/usr/lib
cd ./$APP/
wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh
. ./functions.sh
mkdir -p ./tmp/archives/
mkdir -p ./tmp/lists/partial
touch tmp/pkgcache.bin tmp/srcpkgcache.bin
cat > status <<EOF
Package: debconf
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: dpkg
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: libcups2
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: dbus
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: dpkg
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: passwd
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: uuid-runtime
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: libgl1-mesa
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Comment: Draws in 100 MB of dependencies
libllvm3.8
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
Package: mime-support
Status: install ok installed
Architecture: all
Version: 9999.9999.9999
EOF
echo "deb http://archive.ubuntu.com/ubuntu/ xenial main universe
deb http://ppa.launchpad.net/videolan/master-daily/ubuntu xenial main " > sources.list
OPTIONS="-o Debug::NoLocking=1
-o APT::Cache-Limit=125829120
-o Dir::Etc::sourcelist=./sources.list
-o Dir::State=./tmp
-o Dir::Cache=./tmp
-o Dir::State::status=./status
-o Dir::Etc::sourceparts=-
-o APT::Get::List-Cleanup=0
-o APT::Get::AllowUnauthenticated=1
-o Debug::pkgProblemResolver=true
-o Debug::pkgDepCache::AutoInstall=true
-o APT::Install-Recommends=0
-o APT::Install-Suggests=0
"
apt-get $OPTIONS update
URLS=$(apt-get $OPTIONS -y install --print-uris $LOWERAPP | cut -d "'" -f 2 | grep -e "^http")
wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh
. ./functions.sh
wget -c $URLS
cd ./$APP.AppDir/
find ../*.deb -exec dpkg -x {} . \;
find . -name $LOWERAPP.desktop -exec cp {} . \;
get_apprun
patch_usr
rm -rf ./usr/lib/apt/ ./usr/lib/dpkg/ ./usr/include || true
# Save > 100 MB
rm -rf ./usr/lib/x86_64-linux-gnu/dri
# The following does the magic of running the bundled ld-linux-x86-64.so.2
# so that it can load a newer glibc than what is present on the host system.
# Crashes if GCONV_PATH is not set to match, and if its location
# is not on the --library-path.
cat > ./usr/bin/runvlc <<\EOF
#!/bin/bash
export GCONV_PATH=./lib/x86_64-linux-gnu/gconv
export QT_PLUGIN_PATH=./lib/x86_64-linux-gnu/qt5/plugins/
export LD_LIBRARY_PATH=../lib:../lib/x86_64-linux-gnu:./lib:./lib/x86_64-linux-gnu:./lib/x86_64-linux-gnu/qt5/plugins/platforms:$LD_LIBRARY_PATH
exec ../lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 --inhibit-cache --inhibit-rpath --library-path ../lib:../lib/x86_64-linux-gnu:./lib:./lib/x86_64-linux-gnu ./bin/qvlc "$@"
EOF
chmod a+x ./usr/bin/runvlc
# Fix broken symlink
( cd lib ; rm ld-linux-x86-64.so.2 ; ln -s x86_64-linux-gnu/ld-linux-x86-64.so.2 . )
( cd lib64 ; rm ld-linux-x86-64.so.2 ; ln -s ../lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 . )
# strace -eopen -f ./AppRun 2>&1 | grep "open(./"
# must NOT try to open /lib/ .. libc.so.6
# open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
# open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
# THE FOLLOWING IS NOT QUITE WORKING YET TO RESOLVE THE ABOVE...
# Fix hardcoded paths in the core libraries
find lib/ -type f -exec sed -i 's|/lib/|../li/|g' {} \;
( cd usr ; ln -s ../lib li )
sed -i -e 's|/usr/bin/vlc|runvlc|g' vlc.desktop
get_desktopintegration runvlc # $LOWERAPP
cd ..
VERSION=$(ls "${LOWERAPP}"_*deb | head -n 1 | cut -d "_" -f 2 | cut -d "+" -f 1)
ARCH=$(arch)
generate_appimage