#!/bin/sh

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

APPNAME="RLanguage ROX-App"
VERSION="v1.0"
PKGVER=3.3.2

export TEXTDOMAINDIR="${0%/*}/locale"
export TEXTDOMAIN=rlanguage
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.r-project.org/
    ;;
  --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 RLanguage desktop icons?')" $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 R Language %s?')" $PKGVER)"
    [ $? -eq 100 ] && exec "${0%/*}/uninstall.sh"
    ;;
  --run|*) # default action
    [ "$1" = --run ] && shift
    read term << EOF
$(which $R_TERM defaultterm urxvt xterm rxvt lxterminal sakura 2>/dev/null)
EOF
    [ -e /usr/bin/R-$PKGVER ] &&
      exec $term -e /usr/bin/R-3.3.2 "$@"
    exec $term -e /usr/bin/R "$@"
    ;;
esac
