Debian Codegraph @

sbin/drbl-useradd

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Author: Blake, Kuo-Lien Huang
3 # License: GPL
4 # Description:
5 # * creat and delete accounts for DRBL, actually it for NIS (YP).
6 #
7 # Modified by Steven Shiau <[email protected]> to used in DRBL for Redhat
8
9 # Load DRBL setting and functions
10 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
11 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
12
13 #
14 USAGEscip-shell shell shell-project 0.0.0 USAGE().() {
15 echoscip-shell system . . echo. "Usage: "
16 echoscip-shell system . . echo. "Option 1:"
17 echoscip-shell system . . echo. "$0 [-s|--single] <username> <groupname>"
18 echoscip-shell system . . echo. " generate a single user <username> with group <groupname>"
19 echoscip-shell system . . echo. "Option 2:"
20 echoscip-shell system . . echo. "$0 [-r|--range] <prefix> <start> <end> <groupname> [<passwd_opt>]"
21 echoscip-shell system . . echo. " generate a range of users from <prefix><start> to <prefix><end> with group <groupname>,"
22 echoscip-shell system . . echo. " passwd_opt:"
23 echoscip-shell system . . echo. " If one digit, it's the length of randomly created password."
24 echoscip-shell system . . echo. " If blank, it will be randomly generated with some (say:8) characters."
25 echoscip-shell system . . echo. " Other setting is the password itself."
26 echoscip-shell system . . echo. "Option 3:"
27 echoscip-shell system . . echo. "$0 [-f|--file] <filename>"
28 echoscip-shell system . . echo. " generate users that are listed in <filename>."
29 echoscip-shell system . . echo. " the username/password pairs are listed in $useradd_gen"
30 echoscip-shell system . . echo.
31 echoscip-shell system . . echo. " the format of the file <filename>: PREFIX START END GROUPNAME PASSWD_OPT"
32 echoscip-shell system . . echo. " passwd_opt:"
33 echoscip-shell system . . echo. " If one digit, it's the length of randomly created password."
34 echoscip-shell system . . echo. " If blank, it will be randomly generated with some (say:8) characters."
35 echoscip-shell system . . echo. " Other setting is the password itself."
36 echoscip-shell system . . echo. " for example: "
37 echoscip-shell system . . echo. " # account for student"
38 echoscip-shell system . . echo. " s 89101 89129 g3c9 8"
39 echoscip-shell system . . echo. " # account for teacher"
40 echoscip-shell system . . echo. " tckps 01 99 teacher drblnice"
41 echoscip-shell system . . echo. "Option 4:"
42 echoscip-shell system . . echo. "$0 [-l|--list] <filename>"
43 echoscip-shell system . . echo. " generate users that are listed in <filename>."
44 echoscip-shell system . . echo. " the username/password pairs are listed in $useradd_gen"
45 echoscip-shell system . . echo.
46 echoscip-shell system . . echo. " the format of the file <filename>: ID GROUPNAME PASSWD_OPT"
47 echoscip-shell system . . echo. " passwd_opt:"
48 echoscip-shell system . . echo. " If one digit, it's the length of randomly created password."
49 echoscip-shell system . . echo. " If blank, it will be randomly generated with some (say:8) characters."
50 echoscip-shell system . . echo. " Other setting is the password itself."
51 echoscip-shell system . . echo. " for example: "
52 echoscip-shell system . . echo. " # account for student001"
53 echoscip-shell system . . echo. " student001 g3c9 8"
54 echoscip-shell system . . echo. " # account for student002"
55 echoscip-shell system . . echo. " student002 g3c9 drblnice"
56 }
57
58
59 #
60 check_if_root
61
62 # Parse command-line options
63 while [scip-shell system . . `[`. $# -gt 0 ]; do
64 case "$1" in
65 -s|--single)
66 format="single"
67 shift; username=$1
68 shift; groupname=$1
69 shift;;
70 -r|--range)
71 format="range"
72 shift; prefix=$1
73 shift; start=$1
74 shift; end=$1
75 shift; groupname=$1
76 shift
77 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . grep. ^-.)" ]; then
78 # skip the -xx option, in case
79 passwd_opt=$1
80 fi
81 shift ;;
82 -f|--file)
83 format="file"
84 shift; filename=$1
85 shift ;;
86 -l|--list)
87 format="list"
88 shift; filename=$1
89 shift ;;
90 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
91 USAGEscip-shell shell shell-project 0.0.0 USAGE().
92 exit 2 ;;
93 *) break ;;
94 esac
95 done
96
97 # check if groupname is not valid one
98 if `echoscip-shell system . . echo. "$groupname" | grepscip-shell system . . grep. -q "^[0-9]"`; then
99 echoscip-shell system . . echo. "groupname can NOT begin with digits (0-9)!"
100 echoscip-shell system . . echo. "The one you specified is \"$groupname\""
101 echoscip-shell system . . echo. "Program terminated"
102 exit 1
103 fi
104
105 #
106 case "$format" in
107 single)
108 [scip-shell system . . `[`. -z "$username" ] && echoscip-shell system . . echo. "No username! Program terminated!" && exit 1
109 [scip-shell system . . `[`. -z "$groupname" ] && echoscip-shell system . . echo. "No groupname! Program terminated!" && exit 1
110 ;;
111 range)
112 [scip-shell system . . `[`. -z "$prefix" ] && echoscip-shell system . . echo. "No prefix! Program terminated!" && exit 1
113 [scip-shell system . . `[`. -z "$start" ] && echoscip-shell system . . echo. "No start! Program terminated!" && exit 1
114 [scip-shell system . . `[`. -z "$end" ] && echoscip-shell system . . echo. "No end! Program terminated!" && exit 1
115 [scip-shell system . . `[`. -z "$groupname" ] && echoscip-shell system . . echo. "No groupname! Program terminated!" && exit 1
116 ;;
117 file)
118 [scip-shell system . . `[`. -z "$filename" ] && echoscip-shell system . . echo. "No filename! Program terminated!" && exit 1
119 ;;
120 list)
121 [scip-shell system . . `[`. -z "$filename" ] && echoscip-shell system . . echo. "No filename! Program terminated!" && exit 1
122 ;;
123 *)
124 USAGEscip-shell shell shell-project 0.0.0 USAGE().
125 exit 1
126 ;;
127
128 esac
129
130 # check the necessary files
131 file_to_be_checked="$useradd_range_exec_file $userdel_range_exec_file $useradd_file_exec_file $userdel_file_exec_file $useradd_list_exec_file $userdel_list_exec_file"
132
133 for ifile in $file_to_be_checked; do
134 if ! type "$ifile" &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
135 echoscip-shell system . . echo. "No $ifile file!"
136 exit 1
137 fi
138 done
139
140 #
141 useradd_gen_tmp="$(mktempscip-shell system . . mktemp. /tmp/useradd.XXXXXXscip-shell filesystem . . `/tmp/useradd.XXXXXX`.)"
142
143 # file to store the username and password, clean it first.
144 [scip-shell system . . `[`. -f "$useradd_gen" ] && rmscip-shell system . . rm. -f $useradd_gen
145
146 # add/delete single user
147 case "$format" in
148 single)
149 # add single users
150 echoscip-shell system . . echo. "Password of $username ? (It will not be echoed in the screen. If you want to use random password, just press Enter)"
151 read -s passwd_single1
152 if [scip-shell system . . `[`. -z "$passwd_single1" ]; then
153 make_random_password
154 passwd_single1=$random_password
155 else
156 echoscip-shell system . . echo. "Retype password of $username: (It will not be echoed in the screen)"
157 read -s passwd_single2
158 while [scip-shell system . . `[`. "$passwd_single1" != "$passwd_single2" ]; do
159 echoscip-shell system . . echo. "Sorry, passwords do not match"
160 echoscip-shell system . . echo. "Password of $username ? (It will not be echoed in the screen. If you want to use random password, just press Enter)"
161 read -s passwd_single1
162 echoscip-shell system . . echo. "Retype password of $username: (It will not be echoed in the screen)"
163 read -s passwd_single2
164 done
165 fi
166 echoscip-shell system . . echo. "The password of $username is \"$passwd_single1\"" >> $useradd_gen_tmp
167 run_cmd="/usr/sbin/groupadd $groupname; /usr/sbin/useradd -m $username -g $groupname; echo \"$username:$passwd_single1\" | /usr/sbin/chpasswd"
168 ;;
169
170 range)
171 # add a range of users
172 run_cmd="$useradd_range_exec_file $prefix $start $end $groupname $passwd_opt"
173 ;;
174
175 file)
176 # add users which are listed in file
177 run_cmd="$useradd_file_exec_file $filename"
178 ;;
179 list)
180 # add users which are listed line by line in file
181 run_cmd="$useradd_list_exec_file $filename"
182 ;;
183
184 esac
185
186 echoscip-shell system . . echo. "Creating..."
187 eval "$run_cmd | tee -a $useradd_gen_tmp"
188
189 # filter those we do not want... just output the password and username
190 grepscip-shell system . . grep. "The password of" $useradd_gen_tmp > $useradd_gen
191 chmodscip-shell system . . chmod. 600 $useradd_gen
192 chownscip-shell system . . chown. root:root $useradd_gen
193
194 #
195 if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then
196 tune-debian-dev-group-perm -g "$desktop_user_group_debian" -e -r
197 fi
198 #
199 echoscip-shell system . . echo. "Now update the NIS data in /var/yp ..."
200 makescip-shell system . . make. -C /var/yp/scip-shell filesystem . . `/var/yp/`.
201 echoscip-shell system . . echo.
202 #
203 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
204 echoscip-shell system . . echo. "***********************************************************"
205 echoscip-shell system . . echo. "The username/password pairs are listed in \"$useradd_gen\"."
206 echoscip-shell system . . echo. "***********************************************************"
207 [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
208
209 [scip-shell system . . `[`. -f "$useradd_gen_tmp" ] && rmscip-shell system . . rm. -f $useradd_gen_tmp
210
211 echoscip-shell system . . echo. "Done."
212 exit 0