omap3-pandora-kernel2: update
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_usermanager.sh
1 #!/bin/bash
2 # Released under the GPL
3 # User-Manager, v1.0, written by Michael Mrozek aka EvilDragon 2010.
4 # Partly based on the scripts by JohnX/Mer Project - http://wiki.maemo.org/Mer/
5 # Reworked for the OpenPandora - John Willis/Michael Mrozek
6 # This scripts allows you to create and remove users from the Pandora system.
7
8 . /usr/pandora/scripts/op_common.sh
9 user2=$(get_user)
10
11 while selection=$(zenity --title="Usermanager" --list --column "id" --column "Please select" --hide-column=1 --text="What do you want to do?" "add" "Add a user" "remove" "Remove a user" ); do
12   if [ ${selection} = "add" ]; then
13         echo "Add user"
14         if name=$(zenity --title="Enter full name" --entry --text "Please enter a full name for the new user.") ; then
15           username_guess=$(echo "$name" | cut -d" " -f1 | tr A-Z a-z)
16
17           if username=$(zenity --title="Enter the new username" --entry --text "Please choose a short username.\n\nIt should be all lowercase and contain only letters and numbers." --entry-text "$username_guess") || [ "x$username" = "x" ] ; then
18
19             while ! useradd -c "$name,,," -G adm,audio,video,wheel,netdev,plugdev,users "$username" ; do
20               username=$(zenity --title="Please check username" --entry --text "Please ensure that your username consists of only\nletters and numbers and is not already in use on the system." --entry-text "$username")
21             done
22
23             password=""
24             while [ x$password = x ] ; do
25               password1=$(zenity --title=Password --entry --text="Please choose a new password." --hide-text)
26               password2=$(zenity --title=Confirm --entry --text="Confirm your new password." --hide-text)
27               if [ $password1 != $password2 ] ; then 
28                 zenity --title="Error" --error --text="The passwords do not match.\n\nPlease try again." --timeout 6
29               else 
30                 if [ x$password1 = x ] ; then
31                         zenity --title="Error" --error --text="Password cannot be blank!\n\nPlease try again." --timeout 6
32                 else
33                         password=$password1
34                 fi
35               fi
36             done
37
38 passwd "$username" <<EOF
39 $password
40 $password
41 EOF
42             if zenity --question --title="User created" --text="The user $username has been successfully created.\n\nDo you want to set this user as default user for the login?" --ok-label="Yes, please!" --cancel-label="No, keep the old user as default"; then
43               sed -i "s/.*default_user.*/default_user $username/g" /etc/slim.conf
44             fi
45             zenity --info --title="User created" --text "Thanks. The new user can now be used." --timeout 6
46           fi
47         fi
48   elif [ ${selection} = "remove" ]; then
49         echo "Remove User"
50         amount=$(cat /etc/passwd | grep /home/ | grep -v root | awk -F\: '{print $1 }' | wc -l)
51         if [ ${amount} = "1" ]; then
52               zenity --title="Error" --error --text="Sorry! You can't remove the last normal user!" --timeout 6
53         else
54               if selection=$(cat /etc/passwd | grep /home/ | grep -v root | grep -v $user2 | awk -F\: '{print $1 }' | zenity --width=100 --height=200 --title="Select the user to delete" --list  --column "Username"  --text "Select the user to delete\n\nPlease note: You can't remove the user that is currently logged in.") ; then
55                 if zenity --question --title="Confirm User Removal" --text="Are you REALLY sure you want to remove the user $selection?\n\nThere will be NO other confirmation and this can NOT be undone!" --ok-label="Yes, remove user!" --cancel-label="Don't remove the user"; then
56                   echo "Really remove $selection"
57                   userdel -fr $selection
58                   sed -i "s/.*default_user $selection/default_user/g" /etc/slim.conf
59                   zenity --info --title="User removed" --text "The user $selection has been removed." --timeout 6
60                 else
61                   echo "Don't remove $selection"
62                   zenity --info --title="User not removed" --text "Cancelled removal of user $selection at user's request." --timeout 6
63                fi
64             fi
65         fi
66   fi
67 done
68
69
70