# In this example, we use a trusty PPA - keep providing these!

APP=OpenShot
LOWERAPP=${APP,,}

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

generate_status

echo "deb http://archive.ubuntu.com/ubuntu/ trusty main universe
deb http://ppa.launchpad.net/openshot.developers/ppa/ubuntu trusty main
" > sources.list

apt-get $OPTIONS update
URLS=$(apt-get $OPTIONS -y install --print-uris $LOWERAPP | cut -d "'" -f 2 | grep -e "^http")

wget -c $URLS

cd ./$APP.AppDir/

find ../*.deb -exec dpkg -x {} . \; || true

find ./usr/share -name $LOWERAPP.desktop -exec cp {} . \;

rm -rf ./usr/share/icons/48x48/apps || true
find ./usr/share/icons -path *256* -name $LOWERAPP.png -exec cp {} . \; || true
find ./usr/share/icons -path *512* -name $LOWERAPP.png -exec cp {} . \; || true

get_apprun

mv ./usr/lib/x86_64-linux-gnu/pulseaudio/*.so usr/lib/x86_64-linux-gnu/ || true

delete_blacklisted
rm -rf ./etc/ ./home/ || true

# patch_usr
# find usr/ -type f -exec sed -i -e "s|/usr|././|g" {} \;
find usr/ -type f -exec sed -i -e "s|/usr/bin/python|/usr/bin/env python|g" {} \;

VERSION=$(find ../*.deb -name $LOWERAPP*"_*" | head -n 1 | cut -d "~" -f 1 | cut -d "_" -f 2 | cut -d "-" -f 1 | sed -e 's|1%3a||g' )
echo $VERSION

get_desktopintegration $LOWERAPP

# Go out of AppImage
cd ..

generate_appimage
