#!/bin/sh

passwd_ldap="files ldap"
nssfile="/etc/nsswitch.conf"

read_profile()
{
    if grep -qs "^passwd:[[:space:]]$passwd_ldap" "$nssfile";then
	echo "ldap"
    else
	echo "local"
    fi
}

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

#turn off auto expansion
set -f

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

on_message()
{
	case "$in_action" in
		#information for renderer
		template)
			local profile="$(read_profile)"
			echo '('
			echo ' template "form"'
			
			if [ "$profile" = "ldap" ];then
			    echo 'url "nsswitch-ldap.html"'
			else
			    echo 'url "nsswitch-local.html"'
			fi

			echo ')'
			;;
		*)
			echo '#f'
	esac
}

message_loop
