#!/bin/sh

###############################################################################
# RStudio launcher v1.0 by step 2016                                          #
# GNU GPL v2 applies                                                          #
###############################################################################

APPNAME="RStudio ROX-App"
VERSION="v1.0"
PKGVER=@PKGVER

export TEXTDOMAINDIR="${0%/*}/locale"
export TEXTDOMAIN=rstudio
export OUTPUT_CHARSET=UTF-8

case $1 in
  --help-forum)
    exec defaultbrowser http://www.murga-linux.com/puppy/viewtopic.php?t=95980
    ;;
  --help-upstream)
    exec defaultbrowser http://www.rstudio.com
    ;;
  --open-install-log)
    xdg-open "${0%/*}/install.log" &
    ;;
  --repair)
    command -v gxmessage >/dev/null && XMESSAGE=gxmessage || XMESSAGE=xmessage
    $XMESSAGE -center -title "$(gettext "$APPNAME")" \
      -buttons "$(gettext No):101,$(gettext Yes):100,$(gettext Cancel):102" \
      "$(printf "$(gettext 'Repair RStudio desktop icons and file associations?')" $PKGVER)"
    [ $? -eq 100 ] && NOWOOF=true exec "${0%/*}/install.sh"
    ;;
  --uninstall)
    command -v gxmessage >/dev/null && XMESSAGE=gxmessage || XMESSAGE=xmessage
    $XMESSAGE -center -title "$(gettext "$APPNAME")" \
      -buttons "$(gettext No):101,$(gettext Yes):100,$(gettext Cancel):102" \
      "$(printf "$(gettext 'Completely uninstall RStudio %s?')" $PKGVER)"
    [ $? -eq 100 ] && exec "${0%/*}/uninstall.sh"
    ;;
  --run|*) # default action
    [ "$1" = --run ] && shift
    [ -e /usr/lib/rstudio-$PKGVER ] &&
      exec /usr/lib/rstudio-@PKGVER/bin/rstudio "$@"
    exec /usr/lib/rstudio/bin/rstudio "$@"
    ;;
esac
