#!/bin/bash

# This is not working yet, look at other recipes for examples

APP="eclipse-cpp"
LOWERAPP=${APP//-cpp/}
VERSION=4.6.0 # FIXME: Do not hardcode the version number

sudo apt-get install bsdtar

rm -rf $APP/$APP.AppDir
rm -rf out
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

# FIXME: Never hardcode download links in this way; get from "official" URL
wget -c "http://mirror.internode.on.net/pub/$LOWERAPP/technology/epp/downloads/release/neon/R/$LOWERAPP-cpp-neon-R-linux-gtk-x86_64.tar.gz"

# Get Java
wget -c --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u66-b17/jre-8u66-linux-x64.tar.gz

cd $APP.AppDir/

get_apprun

bsdtar -xf ../$LOWERAPP-*.tar.gz -C usr
cp -r usr/$LOWERAPP/* usr/bin
rm -rf usr/$LOWERAPP

mv usr/bin/eclipse usr/bin/eclipse-cpp

# FIXME: Actually put Java somewhere it is really picked up by Eclipse; this doesn't seem to work
tar xf ../jre*
( cd ./eclipse-* ; mkdir -p jre ; cd jre ; mv ../../jre* ./jre )

cat > $APP.desktop <<EOF
[Desktop Entry]
Version=1.0
Type=Application
Name=Eclipse
Icon=$LAPP
Exec=$APP.wrapper
Categories=Development;IDE;C;C++
Terminal=false
EOF

cp usr/bin/plugins/org.eclipse.epp.package.cpp_*/eclipse256.png $LOWERAPP.png

find usr \
  -name "*.html" -exec rm '{}' \; \
  -or -name "*.bat" -exec rm '{}' \; \
  -or -name "mac*.png" -exec rm '{}' \; \
  -or -name "win*.png" -exec rm '{}' \; \
  -or -name "eclipse*.gif" -exec rm '{}' +

get_desktopintegration $APP

cd .. # Move out of the AppDir

generate_appimage
