#!/bin/bash

# Sparky Add Group is a simply tool which lets you add a new group to the system
# Created by Paweł "pavroo" Pijanowski 2013/Oct/28
# Copyright 2013-2019 under the GNU GPL2 License
# Last updated 2019/11/27 by pavroo

# get default's locale file
DEFLOCDIR="/usr/share/sparky/sparky-users"
if [ "`cat /etc/default/locale | grep de`" != "" ]; then
. $DEFLOCDIR/de
elif [ "`cat /etc/default/locale | grep el`" != "" ]; then
. $DEFLOCDIR/el
elif [ "`cat /etc/default/locale | grep es`" != "" ]; then
. $DEFLOCDIR/es
elif [ "`cat /etc/default/locale | grep fr`" != "" ]; then
. $DEFLOCDIR/fr
elif [ "`cat /etc/default/locale | grep hu`" != "" ]; then
. $DEFLOCDIR/hu
elif [ "`cat /etc/default/locale | grep id_ID`" != "" ]; then
. $DEFLOCDIR/id_ID
elif [ "`cat /etc/default/locale | grep it`" != "" ]; then
. $DEFLOCDIR/it
elif [ "`cat /etc/default/locale | grep ja`" != "" ]; then
. $DEFLOCDIR/ja
elif [ "`cat /etc/default/locale | grep pl`" != "" ]; then
. $DEFLOCDIR/pl
elif [ "`cat /etc/default/locale | grep pt_BR`" != "" ]; then
. $DEFLOCDIR/pt_BR
elif [ "`cat /etc/default/locale | grep pt_PT`" != "" ]; then
. $DEFLOCDIR/pt_PT
elif [ "`cat /etc/default/locale | grep ru`" != "" ]; then
. $DEFLOCDIR/ru
else
. $DEFLOCDIR/en
fi

testroot="`whoami`"
if [ "$testroot" != "root" ]; then
	/usr/bin/remsu $0 &
fi

DIALOG="`which yad` --width=450 --height=250 --window-icon=dialog-ok --image=dialog-ok"
TEXT="--text="
TITLE="--title="
ENTRY="--entry"
OKEXIT="--button=Ok:0 --button=$LOCAL5:1"
OKBUTTON="--button=Ok:0"
GROUP6=`groups | cut -d "|" -f 1`

GROUP5=`$DIALOG $TEXT"$LOCAL26\n$GROUP6 \n$LOCAL27" $TITLE"$LOCAL28" $ENTRY $OKEXIT`

if [ "$?" != "0" ]; then
	$DIALOG $TEXT"$LOCAL29" $TITLE"$LOCAL28" $OKBUTTON
	exit 1

elif [ "`grep $GROUP5 /etc/group`" != "" ]; then
	$DIALOG $TEXT"$LOCAL30 $GROUP5 $LOCAL31" $TITLE"$LOCAL28" $OKBUTTON
	exit 1

else
	groupadd $GROUP5

	$DIALOG $TEXT"$LOCAL32 $GROUP5 $LOCAL33" $TITLE"$LOCAL28" $OKBUTTON
	exit 0

fi

exit 0
