# This is an example on how to convert a Canonical Snap to an AppImage
# The result currently segfaults on Fedora 23
# and refuses to run on some distributions
# because they don't have the Ubuntu Snappy Core runtime bundled which snaps depend on
# gtk-update-icon-cache: symbol lookup error: ./lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined symbol: g_option_group_unref
# /mnt/usr/bin/keepassx: error while loading shared libraries: libgcrypt.so.20: cannot open shared object file: No such file or directory

APP=KeePassX
LOWERAPP=${APP,,}

mkdir -p ./$APP/$APP.AppDir

cd ./$APP/

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

wget -c https://public.apps.ubuntu.com/anon/download-snap/xlZwsUn7GO6Kr2pB5nYZXVx04gilSytB_1.snap

cd ./$APP.AppDir/

unsquashfs ../*.snap
mv squashfs-root/* . && rm -r squashfs-root/

find . -wholename "*applications/$LOWERAPP.desktop" -exec cp {} . \;

find . -wholename "*/256x256/apps/$LOWERAPP.png" -exec cp {} . \;

mv bin/* usr/bin/ || true

get_apprun

get_desktopintegration $LOWERAPP

VERSION=$(cat meta/snap.yaml | grep version | cut -d " " -f 2)
echo $VERSION

# Go out of AppImage
cd ..

generate_appimage
