#!/bin/bash

# Usage:
# getapp Firefox
# For the list of available apps, see https://bintray.com/probono/AppImages/

set -e
ARCH=$(arch)
PKGPATH=$(wget -q "https://bintray.com/probono/AppImages/$1/_latestVersion#files" -O - | grep pkgPath | cut -d '"' -f 6)
VERSION=$(echo $PKGPATH | cut -d "/" -f 5)
URL="https://bintray.com/probono/AppImages/download_file?file_path=$1-$VERSION-$ARCH.AppImage"
ls "$1-$VERSION-$ARCH.AppImage" || wget "$URL" -O "$1-$VERSION-$ARCH.AppImage"
chmod a+x "$1-$VERSION-$ARCH.AppImage"
./"$1-$VERSION-$ARCH.AppImage"
