#!/bin/bash
# Copyright 2014–2024 Endless OS Foundation LLC
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

export GJS_PATH="/usr/share/eos-gates/js${GJS_PATH:+:$GJS_PATH}"
export GI_TYPELIB_PATH="/usr/lib/x86_64-linux-gnu/eos-gates/girepository-1.0${GI_TYPELIB_PATH:+:$GI_TYPELIB_PATH}"
export LD_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu/eos-gates${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

if [ "$GJS_DEBUG_OUTPUT" == "" ]; then
    export GJS_DEBUG_OUTPUT=stderr
fi

if [ "$GJS_DEBUG_TOPICS" == "" ]; then
    export GJS_DEBUG_TOPICS="JS ERROR;JS LOG"
fi

DEBUG_COMMAND=""
if [ "$RUN_DEBUG" != "" ]; then
    DEBUG_COMMAND="gdb --args"
fi

exec $DEBUG_COMMAND /usr/bin/gjs-console -I /usr/share/eos-gates/src -c "const EosGatesLinuxPackage = imports.eos_gates_linux_package; EosGatesLinuxPackage.main(ARGV);" "$@"
