#!/bin/bash

if [ "$1" = "google-chrome" ]; then
   NAME="Google Chrome Web Browser"
   ABOUT="Google Chrome is a web browser from Google,
that makes the web faster, safer, and easier."
   EXECUTABLE="/opt/google/chrome/chrome"
   INSTALL="wget -c -O /tmp/05-chrome.sb 'https://slax.org/download-google-chrome.php?b=slackware&v=$(cat /etc/slax-version | tr -s " " "_")' && slax activate /tmp/05-chrome.sb && rm /tmp/05-chrome.sb"
   POSTINSTALL=""
   GUEST=true
fi

shift

# ------------------------------------------------
#   do not touch anything below this line
# ------------------------------------------------

if [ "$ABOUT" != "" ]; then
   ABOUT="$ABOUT

"
fi


if [ "$EXECUTABLE" = "" ]; then
   exit
fi


if [ ! -f "$EXECUTABLE" ]; then

   if [ $(uname -m) != 'x86_64' -a "$ONLY64" = "true" ]; then
      gtkdialog -i /usr/share/icons/HighContrast/16x16/status/dialog-warning.png  -t Error -m "$NAME only works in 64bit version of Slax" -y OK
      exit 1
   fi

   if gtkdialog -i /usr/share/icons/HighContrast/16x16/status/dialog-question.png -t Question -m "$ABOUT$NAME is not yet installed.
Do you like to download and install it now?" -y Yes -n No; then
      xterm -ls -e bash --login -c -- "$INSTALL; sleep 2; $POSTINSTALL"
   fi
fi


if [ -f "$EXECUTABLE" ]; then

   fbstartupnotify

   if [ "$GUEST" = "true" -a "$EUID" -eq 0 ]; then
      xhost + >/dev/null 2>/dev/null
      exec su -c "$EXECUTABLE "$@""  guest
   fi

   exec "$EXECUTABLE" "$@"

fi
