#!/usr/bin/expect

## set user/password
set user [lindex $argv 0]
set password [lindex $argv 1]
set display [lindex $argv 2]
set login [lindex $argv 3]
set usr_lang [lindex $argv 4]

## let current x-session can be opened by login $user
exec xhost +localhost

## login $user
spawn su $user
exec sleep 1
expect "*"
send "$password\r"

## export DISPLAY and run KidSafeApp in root permission
send "export DISPLAY=$display;export LANGUAGE=$usr_lang;echo \"$password\" | sudo -S /usr/bin/efasdik_egdirb $login\r"

## set timeout to terminate this expect program
set timeout 2
expect eof {exit 0}
expect timeout {exit 0}

