APP=Inkscape
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/inkscape.dev/trunk/ubuntu trusty main
" > sources.list

apt-get $OPTIONS update

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

wget -c $URLS

wget -c https://github.com/fablabnbg/inkscape-silhouette/archive/master.zip
unzip master.zip

cd ./$APP.AppDir/

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

cp -r ../inkscape-silhouette-master/silhouette ../inkscape-silhouette-master/sendto_silhouette.* usr/share/inkscape/extensions/

get_desktop
get_icon
get_apprun

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

# Workaround for:
# inkscape.desktop": Failed to validate the created desktop file
# error: file contains group "Drawing Shortcut Group", but groups extending the format should start with "X-"
sed -i -e 's|Drawing Shortcut Group|X-Drawing Shortcut Group|g' $LOWERAPP.desktop

# 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" {} \;

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_type2_appimage
