#!/usr/bin/env bash
# Description: Script for run cid-gtk
# Copyright (C) 2012-2021 Eduardo Moraes <emoraes25@gmail.com>
# This file is part of CID (Closed In Directory).
#
# CID 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.
#
# CID 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 CID.  If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------#


# Function: Help
Help () {
	echo -e "Use: ${0##*/} (only root)
 or: ${0##*/} [OPTION]

Graphical tool to insert and manage the station in an AD domain.

OPTIONS:
    -h, --help\t\tShow this help and exit
    -v, --version\tShow the version and exit\n"
	exit "$1"
}


# Start
if [ -f /usr/share/cid/scripts/vars.bash ]; then
	# shellcheck source=/dev/null
	. /usr/share/cid/scripts/vars.bash
else
	echo 'File /usr/share/cid/scripts/vars.bash not found!' >&2
	exit 127
fi

if [ $# -eq 0 ]; then
	xhost +SI:localuser:root > /dev/null 2>&1
	pkexec "${SHAREDIR}/cid_gtk.bash"
	xhost -SI:localuser:root > /dev/null 2>&1
else
	if [ $# -eq 1 ]; then
		case $1 in
			-v|--version) echo "CID version $VERSION" ; exit 0 ;;
			-h|--help) Help 0 ;;
			*) Help 1 ;;
		esac
	else
		Help 1
	fi
fi
