Magellan Linux

Contents of /trunk/mage/usr/lib/mage/museradd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 60 - (show annotations) (download)
Tue Feb 15 22:59:14 2005 UTC (19 years, 2 months ago) by niro
File size: 943 byte(s)
rev bump to 0.3.6-r13

1 #!/bin/bash
2 # version: 0.3.6-r13
3
4 print_usage()
5 {
6 echo "$(basename $0 .sh) adds users to /etc/passwd."
7 echo " USAGE: $(basename $0 .sh) -o OPTIONS USER_NAME .."
8 echo
9 echo " OPTIONS: -o \"OPTS\"all options from /usr/sbin/useradd can be used."
10 echo
11 echo " Examples:"
12 echo " $(basename $0 .sh) -o \"-u 22 -g sshd -d /var/empty -s /bin/false\" sshd"
13 echo
14 }
15
16 while getopts "o:-" opt ; do
17 case "${opt}" in
18 o)
19 USER_OPTS="${OPTARG}"
20 ;;
21
22 -) break
23 ;;
24
25 *)
26 print_usage
27 exit 1
28 ;;
29 esac
30 done
31 shift $(($OPTIND - 1))
32
33 #exit if $1 is zero
34 if [ -z "$1" ]
35 then
36 print_usage
37 exit 1
38 fi
39
40 USER_TO_ADD="$1"
41
42 #start nscd to cache passwd
43 $(which nscd) -i passwd
44 # get the info
45 my_user="$(getent passwd ${USER_TO_ADD})"
46
47 if [ -z "${my_user}" ]
48 then
49 echo " Adding user '${USER_TO_ADD}' ..."
50 useradd ${USER_OPTS} "${USER_TO_ADD}"
51 else
52 echo " Modifing user '${USER_TO_ADD}' ..."
53 usermod ${USER_OPTS} "${USER_TO_ADD}"
54 fi