#!/bin/sh

# If we're just upgrading, don't ask anything
case "$1" in
    configure)
        if [ "$2" == "" ]; then
            # If user account is locked, unlock it
            grep -q "^user:!" /etc/passwd && passwd -u user

            # Ask for a password for user account
            . /etc/osso-af-init/af-defines.sh
            pass=`maemo-get-passwd "Please set a password for 'user'
or press 'Back' to leave as-is"`
            # If user did not reject the proposal, set the password
            if [ -n "$pass" ]; then
                echo "user:$pass" | chpasswd
                echo "\
The password for user account has been set. You can change it at any
later time by invoking the 'passwd user' command from a terminal.

Now, to invoke a command with administrative priviledges, open a terminal
and run 'sudo <command>' then, when prompted, enter the password you
just set up. 'sudo' is smart enough to not ask you the password again
for some time in the same session.

To get into a root login shell, enter 'rush' inside a terminal 
" >/tmp/_sudser_
                maemo-confirm-text "Please note" /tmp/_sudser_
            fi
        fi
        ;;
esac

# If user has empty password, use NOPASSWD:
if grep -q "^user::" /etc/passwd; then
    echo "user	ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/everybody.sudoers
else # If password is not empty, use it
    echo "user	ALL=(ALL) ALL" >/etc/sudoers.d/everybody.sudoers
fi

/usr/sbin/update-sudoers
