#!/bin/bash

# Password Change Tool Copyright 2009 by Tony Brijeski under the GPL V2
#
# Remastered for SparkyLinux by pavroo <pavroo@onet.eu> 2013/04/02
# Under the GPL V2
# Last update 2019/11/25 by pavroo

# get default's locale file
DEFLOCDIR="/usr/share/sparky/sparky-passwdchange"
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_JP`" != "" ]; 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 zenity` --width=400 --height=300 --window-icon=seahorse"
TITLE="--title="
TEXT="--text="
ENTRY="--entry "
ENTRYTEXT="--entry-text "
MENU="--list --column=$LOCAL1 --column=$LOCAL2"
YESNO="--question "
MSGBOX="--info "
PASSWORD="--entry --hide-text "
TITLETEXT="$LOCAL3"

for LINE in `grep '^[^:]*:[^:]*:[1-9][0-9][0-9][0-9]:' /etc/passwd | awk -F ":" '{print $1}'`; do
CHOICE="$CHOICE $LINE $LINE"
done

TARGETUSER=`$DIALOG $TITLE"$TITLETEXT" $MENU $TEXT"\n$LOCAL4" Exit "$LOCAL5" root root $CHOICE`

if [ "$TARGETUSER" = "Exit" ]; then
	exit 1
fi

#password entry section

TARGETPASS="1"
TARGETPASS2="2"

while [ "$TARGETPASS" != "$TARGETPASS2" ]; do

TARGETPASS=`$DIALOG $TITLE"$TITLETEXT" $PASSWORD $TEXT"$LOCAL6 $TARGETUSER."`
TARGETPASS2=`$DIALOG $TITLE"$TITLETEXT" $PASSWORD $TEXT"$LOCAL6 $TARGETUSER $LOCAL7"`

if [ "$TARGETPASS" != "$TARGETPASS2" ]; then
$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL8"
fi

done

echo -e "$TARGETPASS\n$TARGETPASS\n" | passwd $TARGETUSER

$DIALOG $TITLE"$TITLETEXT" $MSGBOX $TEXT"$LOCAL9 $TARGETUSER."

exit 0
