APP=Slack
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

URL=$(wget -q https://slack.com/downloads -O - | grep amd64.deb | head -n 1 | cut -d '"' -f 2)
wget -c "$URL"

cd ./$APP.AppDir/

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

cp ./usr/share/applications/$LOWERAPP.desktop .
sed -i -e 's|^Exec=.*|Exec=slack|g' $LOWERAPP.desktop
cp ./usr/share/pixmaps/slack.png .

get_apprun

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

# 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' )
# Slack doesn't follow deb naming conventions, workaround:
VERSION=$(find ../*.deb -name $LOWERAPP-"*" | head -n 1 | cut -d "-" -f 3)
echo $VERSION

get_desktopintegration $LOWERAPP

# Go out of AppImage
cd ..

generate_appimage
