APP=Sublime-Text
LOWERAPP=sublime_text # ${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

DEB=$(wget -q "https://www.sublimetext.com/3" -O - | grep dl_linux_64 | cut -d '"' -f 4 | tail -n 1)
wget -c $DEB

cd ./$APP.AppDir/

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

mv opt/sublime_text/* usr/bin/
rm -r opt/

rm -rf ./usr/share/icons/hicolor/48x48/apps
cp ./usr/share/icons/hicolor/256x256/apps/sublime-text.png .

cp ./usr/share/applications/$LOWERAPP.desktop .
sed -i -e 's|/opt/sublime_text/||g' $LOWERAPP.desktop 

get_apprun

# Copy in the indirect dependencies
# copy_deps # not needed here because upstream seems to have avoided uncommon dependencies, yay

VERSION=$( find ../*.deb -name sublime-text"_*" | head -n 1  | cut -d _ -f 2 | cut -d "-" -f 2 )
echo $VERSION

get_desktopintegration $LOWERAPP

# Go out of AppImage
cd ..

generate_appimage
