#!/bin/bash

# This is an example for packaging a Java application as an AppImage.
# This application comes with a JRE.

APP=IDEA
LOWERAPP=${APP,,} 

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

cd $APP/

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

wget -c "https://download.jetbrains.com/idea/ideaIC-2016.1.3.tar.gz"

cd $APP.AppDir/

get_apprun

tar xf ../ideaIC-*.tar.gz 
( mkdir -p usr/bin/bin ; cd usr/bin; ln -s ../../*/bin/*.sh . )

cat > $LOWERAPP.desktop <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=$APP
Icon=$LOWERAPP
Exec=$LOWERAPP.sh
Categories=Development;IDE;
Terminal=false
EOF

cp *.*/bin/$LOWERAPP.png .

VERSION=$(ls ../$LOWERAPP*-* | cut -d - -f 2 | sed 's|.tar.gz||g')
echo $VERSION

# Do not add desktop integration since it comes with its own

cd .. # Go out of AppDir

generate_appimage
