Magellan Linux

Annotation of /branches/mage-next/src/helper/mgroupadd.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (hide annotations) (download)
Mon Jan 10 01:58:35 2005 UTC (19 years, 4 months ago) by niro
Original Path: trunk/mage/usr/lib/mage/mgroupadd
File size: 985 byte(s)
initial release

1 niro 42 #!/bin/bash
2     # version: 0.3.6-r11
3    
4     print_usage()
5     {
6     echo "$(basename $0 .sh) adds groups to /etc/group."
7     echo " USAGE: $(basename $0 .sh) -o OPTIONS GROUP_NAME .."
8     echo
9     echo " OPTIONS: -o \"OPTS\"all options from /usr/sbin/groupadd can be used."
10     echo
11     echo " Examples:"
12     echo " $(basename $0 .sh) -o \"-g 22\" sshd"
13     echo
14     }
15    
16     while getopts "o:-" opt ; do
17     case "${opt}" in
18     o)
19     GROUP_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     GROUP_TO_ADD="$1"
41    
42     #start nscd to cache /etc/group
43     $(which nscd) -i group
44     # get the info
45     my_group="$(getent group ${GROUP_TO_ADD})"
46    
47     # if above entries are empty the user/group does not exist
48     if [ -z "${my_group}" ]
49     then
50     echo " Adding group '${GROUP_TO_ADD}' ..."
51     groupadd ${GROUP_OPTS} "${GROUP_TO_ADD}"
52     else
53     echo " Modifing group '${GROUP_TO_ADD}' ..."
54     groupmod ${GROUP_OPTS} "${GROUP_TO_ADD}"
55     fi