#!/bin/sh

# 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

# If user has empty password, add NOPASSWD
if grep -q "^user::" /etc/passwd; then
    sed -e 's/(ALL) *ALL/(ALL) NOPASSWD: ALL/' /etc/sudoers.d/everybody.sudoers >/tmp/_sudser_
else # If password is not empty, remove NOPASSWD:
    sed -e 's/NOPASSWD: //' /etc/sudoers.d/everybody.sudoers >/tmp/_sudser_
fi
mv -f /tmp/_sudser_ /etc/sudoers.d/everybody.sudoers

/usr/sbin/update-sudoers
