#!/bin/sh

_()
{
    LANG=${in_language%%;*}.utf8 gettext "alterator-users" "$1"
}

#turn off auto expansion
set -f

. /usr/share/alterator/build/backend3.sh

root_chpasswd()
{
    echo "root:$in_passwd1"|/usr/sbin/chpasswd
}

on_message()
{
	case "$in_action" in
		constraints)
		    echo '('
		    printf ' passwd1  (equal passwd2 label "%s")' "`_ "Password"`"
		    printf ' passwd2  (label "%s")' "`_ "Password"`"
		    echo ')'
		    ;;
		write)
		    if [  -n "$in_passwd1" ];then 
			if root_chpasswd; then
			    echo '()'
			else
			    printf '(error "%s")' "`_ "Unable to change password"`"
			fi
		    else
		        echo '()'
		    fi
		    ;;
		*)
		    echo '#f'
		    ;;
	esac
}

message_loop
