#!/bin/bash
# -*- coding: utf-8 -*-
# vim:fenc=utf-8

# This file is part of the  X2Go Project - https://www.x2go.org
# Copyright (C) 2012-2019 by Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
#
# X2Go Session Broker is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# X2Go Session Broker 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.

if [[ $EUID -ne 0 ]]; then
  echo "$(basename $0): You must be the root super-user to launch this command..." 2>&1
  exit 1
fi

if [ -e /etc/default/python-x2gobroker ]; then
	. /etc/default/python-x2gobroker
fi

if [ -e /etc/default/x2gobroker-daemon ]; then
	. /etc/default/x2gobroker-daemon
fi

if [ -n "$DAEMON_BIND_ADDRESS" ]; then
	su - x2gobroker -c "X2GOBROKER_SSL_CERTFILE=\"$X2GOBROKER_SSL_CERTFILE\" X2GOBROKER_SSL_KEYFILE=\"$X2GOBROKER_SSL_KEYFILE\" DAEMON_BIND_ADDRESS=\"$DAEMON_BIND_ADDRESS\" x2gobroker-daemon -b $DAEMON_BIND_ADDRESS -i $@"
else
	su - x2gobroker -c "X2GOBROKER_SSL_CERTFILE=\"$X2GOBROKER_SSL_CERTFILE\" X2GOBROKER_SSL_KEYFILE=\"$X2GOBROKER_SSL_KEYFILE\" x2gobroker-daemon -i $@"
fi
