# This recipe uses binaries from the project's ppa for trusty,
# and uses a trusty system to bundle the dependencies.
# As a result, the AppImage will not be compatible with distributions
# older than trusty. To achieve that, we could compile e.g., on CentOS 6.

wget -q https://github.com/probonopd/AppImages/raw/master/functions.sh -O ./functions.sh
. ./functions.sh

APP=VSXu
LOWERAPP=${APP,,}

# sed -i -e 's|main restricted|main universe restricted|g' /etc/apt/sources.list
sudo add-apt-repository -y ppa:vovoid/vsxu-daily
sudo apt-get update
sudo apt-get clean

sudo apt-get -y install $LOWERAPP

mkdir -p $APP/$APP.AppDir
cd $APP/$APP.AppDir
find /var/cache/apt/archives/*deb -exec dpkg -x {} . \;

cp ./usr/share/applications/vsxu-player.desktop vsxu.desktop
( cd usr/bin ; ln -s vsxu_player vsxu )
sed -i -e "s|Exec=.*|Exec=vsxu|g" vsxu.desktop

cp usr/share/pixmaps/hicolor/apps/256x256/$LOWERAPP.png .
rm -rf ./usr/share/icons/48x48/apps || true
rm -rf ./usr/share/icons/hicolor/48x48/apps || true

get_apprun

# Copy in the indirect dependencies
copy_deps ; copy_deps ; copy_deps # Three runs to ensure we catch indirect ones

mv ./lib/x86_64-linux-gnu/* ./usr/lib/x86_64-linux-gnu/ ; rm -rf ./lib

# patch_usr
# Patching only the executable files seems not to be enough for some apps
find usr/ -type f -exec sed -i -e "s|/usr|././|g" {} \;

delete_blacklisted

VERSION=$(ls /var/cache/apt/archives/vsxu-player_* | head -n 1 | cut -d "_" -f 2 | cut -d "-" -f 1)
echo $VERSION

get_desktopintegration $LOWERAPP

# Go out of AppImage
cd ..

generate_appimage
