#!/usr/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="--disable-features=AudioServiceOutOfProcess \
            --no-default-browser-check"

UA='Mozilla/5.0 (X11; blackPanther OS; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chromium/108.0.5359.124 Chrome/108.0.0.0 Safari/537.36'

USER_ARGS_FILE=$HOME/.config/chromium/args.txt

if [ -f "$USER_ARGS_FILE" ]; then
  EXTRA_ARGS+=$(grep -v '^#' "$USER_ARGS_FILE")
fi

echo -e "$MAG * Launch Chromium on blackPanther OS.....$DEF"

if [ -n "$ENABLE" ]&&[ ! -d $HOME/.config/google-chrome ]||[ -L $HOME/.config/google-chrome ];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 --user-agent="$UA" "$@" 2>/dev/null
 else
    exec -a "$0" "$PROGDIR/chrome" $EXTRA_ARGS $(echo "$@" |sed 's|DEBUG||')
fi
