Annotation of /trunk/mage/usr/lib/mage/mgroupadd
Parent Directory | Revision Log
Revision 1273 -
(hide annotations)
(download)
Wed Apr 27 09:45:07 2011 UTC (13 years, 5 months ago) by niro
File size: 1706 byte(s)
Wed Apr 27 09:45:07 2011 UTC (13 years, 5 months ago) by niro
File size: 1706 byte(s)
-support busybox out-of-the-box
1 | niro | 42 | #!/bin/bash |
2 | niro | 78 | # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/mgroupadd,v 1.4 2005-06-01 15:48:38 niro Exp $ |
3 | niro | 42 | |
4 | niro | 1273 | # include all needed files |
5 | [ -f /etc/mage.rc.global ] && source /etc/mage.rc.global | ||
6 | [ -f ${MAGERC} ] && source ${MAGERC} | ||
7 | [ -f ${MLIBDIR}/mage4.functions.sh ] && source ${MLIBDIR}/mage4.functions.sh | ||
8 | |||
9 | niro | 42 | print_usage() |
10 | { | ||
11 | echo "$(basename $0 .sh) adds groups to /etc/group." | ||
12 | echo " USAGE: $(basename $0 .sh) -o OPTIONS GROUP_NAME .." | ||
13 | echo | ||
14 | echo " OPTIONS: -o \"OPTS\"all options from /usr/sbin/groupadd can be used." | ||
15 | echo | ||
16 | echo " Examples:" | ||
17 | echo " $(basename $0 .sh) -o \"-g 22\" sshd" | ||
18 | echo | ||
19 | } | ||
20 | |||
21 | niro | 1273 | busybox_fix_group_opts() |
22 | { | ||
23 | local i | ||
24 | local FIXED_GROUP_OPTS | ||
25 | |||
26 | for i in $* | ||
27 | do | ||
28 | case $1 in | ||
29 | -r) FIXED_GROUP_OPTS+=" -S" ;; | ||
30 | *) FIXED_GROUP_OPTS+=" $1" ;; | ||
31 | esac | ||
32 | shift | ||
33 | done | ||
34 | |||
35 | echo "${FIXED_GROUP_OPTS}" | ||
36 | } | ||
37 | |||
38 | niro | 42 | while getopts "o:-" opt ; do |
39 | case "${opt}" in | ||
40 | o) | ||
41 | GROUP_OPTS="${OPTARG}" | ||
42 | ;; | ||
43 | |||
44 | -) break | ||
45 | ;; | ||
46 | |||
47 | *) | ||
48 | print_usage | ||
49 | exit 1 | ||
50 | ;; | ||
51 | esac | ||
52 | done | ||
53 | shift $(($OPTIND - 1)) | ||
54 | |||
55 | #exit if $1 is zero | ||
56 | if [ -z "$1" ] | ||
57 | then | ||
58 | print_usage | ||
59 | exit 1 | ||
60 | fi | ||
61 | |||
62 | GROUP_TO_ADD="$1" | ||
63 | |||
64 | niro | 1273 | # busybox support needed? |
65 | if need_busybox_support addgroup | ||
66 | niro | 42 | then |
67 | echo " Adding group '${GROUP_TO_ADD}' ..." | ||
68 | niro | 1273 | addgroup $(busybox_fix_group_opts ${GROUP_OPTS}) "${GROUP_TO_ADD}" |
69 | |||
70 | # normal systems | ||
71 | niro | 42 | else |
72 | niro | 1273 | #start nscd to cache /etc/group |
73 | $(which nscd) -i group | ||
74 | # get the info | ||
75 | my_group="$(getent group ${GROUP_TO_ADD})" | ||
76 | |||
77 | # if above entries are empty the user/group does not exist | ||
78 | if [ -z "${my_group}" ] | ||
79 | then | ||
80 | echo " Adding group '${GROUP_TO_ADD}' ..." | ||
81 | groupadd ${GROUP_OPTS} "${GROUP_TO_ADD}" | ||
82 | else | ||
83 | echo " Modifing group '${GROUP_TO_ADD}' ..." | ||
84 | groupmod ${GROUP_OPTS} "${GROUP_TO_ADD}" | ||
85 | fi | ||
86 | niro | 42 | fi |