#!/bin/bash
#
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
. /etc/blackPanther-default-apps.conf
# Let the wrapped binary know that it has been run through the wrapper
export CHROME_WRAPPER="`readlink -f "$0"`"

PROGDIR="`dirname "$CHROME_WRAPPER"`"

case ":$PATH:" in
  *:$PROGDIR:*)
    # $PATH already contains $PROGDIR
    ;;
  *)
    # Append $PROGDIR to $PATH
    export PATH="$PATH:$PROGDIR"
    ;;
esac

case "$LANG" in
    hu*)
    LINK_MSG="Google on $(lsb_release -sir)<h2>Használjunk azonos beállításokat a Chrome-val?!</h2> Többet nem jelenik meg az üzenet!"
    ;;
    *)
    LINK_MSG="<h2>Do you want use same settings with Chrome?!</h2> Never display this message!"
    ;;

esac
LIBS=/usr/lib
[ "$(uname -m)" = "x86_64" ]&&LIBS=/usr/lib64
# Always use our versions of ffmpeg libs.
# This also makes RPMs find the compatibly-named NSS3/NSPR symlinks.
LD_LIBRARY_PATH="$PROGDIR:$PROGDIR/lib:$PROGDIR/lib64:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH

EXTRA_ARGS=
if [ -f /opt/google/chrome/PepperFlash/libpepflashplayer.so ];then
    # otpional blackPanther OS installation path
    echo -en "$YEL * Pepper Flash Player Detected on Optional path....$DEF"
    CHROME_FLASH="/opt/google/chrome/PepperFlash/libpepflashplayer.so"
    CHROME_FLASH_MANIFEST="/opt/google/chrome/PepperFlash/manifest.json"
    echo -e "[$GRN OK $DEF]"
elif [ -f $LIBS/chromium-browser/PepperFlash/libpepflashplayer.so ];then
    # default blackPanther OS installation path
    echo -en "$GRN * Pepper Flash Player Detected on blackPanther OS default-path....$DEF"
    CHROME_FLASH="$LIBS/chromium-browser/PepperFlash/libpepflashplayer.so"
    CHROME_FLASH_MANIFEST="$LIBS/chromium-browser/PepperFlash/manifest.json"
    echo -e "[$GRN OK $DEF]"
fi

if [ -e "$CHROME_FLASH" -a -e "$CHROME_FLASH_MANIFEST" ]; then
  # alternatives, for the record:
  CHROME_FLASH_VERSION="$(awk -F'"' '{ if ($2 == "version") { print $4; exit; } }' "$CHROME_FLASH_MANIFEST")"
  EXTRA_ARGS="$EXTRA_ARGS --ppapi-flash-path=$CHROME_FLASH --ppapi-flash-version=$CHROME_FLASH_VERSION"
fi

echo -e "$MAG * Launch Chromium on blackPanther OS.....$DEF"
if [ ! -d $HOME/.config/google-chrome ]||[ -L $HOME/.config/google-chrome ];then
#if [ ! -d $HOME/.config/google-chrome ]&&[ ! -L $HOME/.config/google-chrome ];then
    if [ -d $HOME/.config/chromium ]&&[ ! -f $HOME/.config/google-chrome-conf ];then
    #if [ -d $HOME/.config/chromium ]&&[ ! -f $HOME/.config/google-chrome-conf ];then
    xmsg=$(which pydialog 2>/dev/null || which kdialog 2>/dev/null)
	echo -e "$GRN + Link config directory at first time...$DEF"
	$xmsg --title "ChromeConf" --yesno "$LINK_MSG"
	CONF_LINK=$?
	echo "Link:$LINK"
	[ "$CONF_LINK" = "0" ] && ln -sf $HOME/.config/chromium $HOME/.config/google-chrome
	[ "$CONF_LINK" = "1" ] && rm -f $HOME/.config/google-chrome
	echo "LINK=$CONF_LINK" > $HOME/.config/google-chrome-conf
    fi
fi
if [ "$(echo $@ | grep DEBUG)x" = "x" ];then
    exec -a "$0" "$PROGDIR/chrome" $EXTRA_ARGS "$@" 2>/dev/null
 else
    exec -a "$0" "$PROGDIR/chrome" $EXTRA_ARGS $(echo "$@" |sed 's|DEBUG||')
fi
