#!/bin/bash

# If server address is not in the environment, read it
if [ -z "$SERVER" ]
then
    SERVER=`grep ^host /etc/ldap.conf | cut -d' ' -f2 | cut -d: -f1`
fi

TEXT="Welcome to Zentyal Desktop first login configuration.

You are seeing this because you have enabled the roaming profiles feature. After you close this dialog, you will be asked for your password. It is needed to copy your public key tot he server. You will not have to do this on the next logins, just this time."

ssh-keygen -f $HOME/.ssh/id_rsa -N ''

zenity --text "$TEXT" --info

SSH_ASKPASS=ssh-askpass setsid ssh-copy-id $SERVER

if [ $? -eq 0 ]
then
    zenity --text "Key copied successfully." --info
else
    zenity --text "Copy public key to $SERVER failed." --error
fi
