# Note that Terminix has dependencies on components that are only present in very new distros
# which we are not bundling here (e.g., GTK3 and VTE). Do not expect this to run on 
# distributions before 2015-16ish.

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

APP=Terminix
LOWERAPP=${APP,,} 

VERSION=$(wget -q "https://github.com/gnunn1/terminix/releases" -O - | grep "/releases/tag" | head -n 1 | cut -d ">" -f 2 | cut -d "<" -f 1 | sed 's|Beta ||g' | sed 's|Stable ||g')
ZIP_PATH=$(wget -q "https://github.com/gnunn1/terminix/releases" -O - | grep terminix.zip | grep href | head -n 1 | cut -d '"' -f 2)
URL=https://github.com/$ZIP_PATH

mkdir -p $APP/$APP.AppDir

cd $APP
wget -c "$URL"

cd $APP.AppDir

unzip ../terminix.zip

cp ./usr/share/applications/com.gexperts.Terminix.desktop terminix.desktop
rm -rf usr/share/icons/hicolor/48x48/

get_apprun

find usr/ -type f -exec sed -i -e "s|/usr|././|g" {} \;

( mkdir -p usr/share/glib-2.0/schemas/ ; cd usr/share/glib-2.0/schemas/ ; glib-compile-schemas . )

get_desktopintegration $LOWERAPP

# https://github.com/gnunn1/terminix/issues/25#issuecomment-218013837
sed -i -e 's|exec $BIN $ARGS|exec $BIN -w $HOME $ARGS|g' ./usr/bin/terminix.wrapper

# Copy in the indirect dependencies
copy_deps ; copy_deps ; copy_deps # Three runs to ensure we catch indirect ones

move_lib

delete_blacklisted

# Go out of AppImage
cd ..

generate_appimage
