Debian Codegraph @

sbin/drbl-userdel

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
12 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
13
14
15 #
16 check_if_root
17
18 # Parse command-line options
19 while [scip-shell system . . `[`. $# -gt 0 ]; do
20 case "$1" in
21 -s|--single)
22 format="single"
23 shift; username=$1
24 shift; groupname=$1
25 shift;;
26 -r|--range)
27 format="range"
28 shift; prefix=$1
29 shift; start=$1
30 shift; end=$1
31 shift; groupname=$1
32 shift ;;
33 -f|--file)
34 format="file"
35 shift; filename=$1
36 shift ;;
37 -l|--list)
38 format="list"
39 shift; filename=$1
40 shift ;;
41 -g|--group)
42 format="group"
43 shift; group2del=$1
44 shift ;;
45 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
46 echoscip-shell system . . echo. $USAGE >& 2
47 exit 2 ;;
48 *) break ;;
49 esac
50 done
51
52 case "$format" in
53 single)
54 [scip-shell system . . `[`. -z "$username" ] && echoscip-shell system . . echo. "No username! Program terminated!" && exit 1
55 ;;
56 range)
57 [scip-shell system . . `[`. -z "$prefix" ] && echoscip-shell system . . echo. "No prefix! Program terminated!" && exit 1
58 [scip-shell system . . `[`. -z "$start" ] && echoscip-shell system . . echo. "No start! Program terminated!" && exit 1
59 [scip-shell system . . `[`. -z "$end" ] && echoscip-shell system . . echo. "No end! Program terminated!" && exit 1
60 ;;
61 file)
62 [scip-shell system . . `[`. -z "$filename" ] && echoscip-shell system . . echo. "No filename! Program terminated!" && exit 1
63 ;;
64 list)
65 [scip-shell system . . `[`. -z "$filename" ] && echoscip-shell system . . echo. "No filename! Program terminated!" && exit 1
66 ;;
67 group)
68 [scip-shell system . . `[`. -z "$group2del" ] && echoscip-shell system . . echo. "No groupname to delete! Program terminated!" && exit 1
69 ;;
70 *)
71 echoscip-shell system . . echo. "Usage: "
72 echoscip-shell system . . echo. "Option 1:"
73 echoscip-shell system . . echo. "$0 [-s|--single] <username> <groupname>"
74 echoscip-shell system . . echo. " delete a single user <username> with group <groupname>"
75 echoscip-shell system . . echo.
76 echoscip-shell system . . echo. "$0 [-r|--range] <prefix> <start> <end> <groupname>"
77 echoscip-shell system . . echo. " delete a range of users from <prefix><start> to <prefix><end> with group <groupname>,"
78 echoscip-shell system . . echo. "Option 2:"
79 echoscip-shell system . . echo. "$0 [-f|--file] <filename>"
80 echoscip-shell system . . echo. " delete users that are listed in <filename>."
81 echoscip-shell system . . echo. " the username/password pairs are listed in $useradd_gen"
82 echoscip-shell system . . echo.
83 echoscip-shell system . . echo. " the format of the file <filename>: PREFIX START END GROUPNAME"
84 echoscip-shell system . . echo. " for example: "
85 echoscip-shell system . . echo. " # account for student"
86 echoscip-shell system . . echo. " s 89101 89129 g3c9"
87 echoscip-shell system . . echo. " # account for teacher"
88 echoscip-shell system . . echo. " tckps 01 99 teacher"
89 echoscip-shell system . . echo. "Option 3:"
90 echoscip-shell system . . echo. "$0 [-l|--list] <filename>"
91 echoscip-shell system . . echo. " delete users that are listed in <filename>."
92 echoscip-shell system . . echo. " the username/password pairs are listed in $useradd_gen"
93 echoscip-shell system . . echo.
94 echoscip-shell system . . echo. " the format of the file <filename>: ID GROUPNAME"
95 echoscip-shell system . . echo. " for example: "
96 echoscip-shell system . . echo. " # account for student001"
97 echoscip-shell system . . echo. " student001 g3c9"
98 echoscip-shell system . . echo. " # account for student002"
99 echoscip-shell system . . echo. " student002 g3c9"
100 echoscip-shell system . . echo. "Option 4:"
101 echoscip-shell system . . echo. "$0 [-g|--group] <group>"
102 echoscip-shell system . . echo. " delete users that are in the group."
103 exit 1
104 ;;
105
106 esac
107
108 # check the necessary files
109 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"
110
111 for ifile in $file_to_be_checked; do
112 if ! type "$ifile" &>/dev/nullscip-shell filesystem . . `/dev/null`.; then
113 echoscip-shell system . . echo. "No $ifile file!"
114 exit 1
115 fi
116 done
117
118 userdel_gen_tmp=`mktempscip-shell system . . mktemp. /tmp/userdel.XXXXXXscip-shell filesystem . . `/tmp/userdel.XXXXXX`.`
119
120 # file to store the username and password, clean it first.
121 [scip-shell system . . `[`. -f "$userdel_gen" ] && rmscip-shell system . . rm. -f $userdel_gen
122
123 # add/delete single user
124 case "$format" in
125 single)
126 # delete single users
127 echoscip-shell system . . echo. -n "Do you also want to clean user's home directory [y/N] ? "
128 read clean_home
129 case "$clean_home" in
130 y|Y|[yY][eE][sS])
131 echoscip-shell system . . echo. "Warning! The user's home directory will be deleted! Are you sure ?"
132 echoscip-shell system . . echo. -n "[y/N] "
133 read clean_home_confirm
134 case "$clean_home_confirm" in
135 y|Y)
136 RM_HOME_OPT="-r"
137 ;;
138 *)
139 RM_HOME_OPT=""
140 esac
141 ;;
142 *)
143 RM_HOME_OPT=""
144 esac
145
146 if grepscip-shell system . . grep. "^$username:" /etc/passwdscip-shell filesystem . . `/etc/passwd`. >/dev/nullscip-shell filesystem . . `/dev/null`.; then
147 echoscip-shell system . . echo. -n "Deleting account $username..."
148 /usr/sbin/userdelscip-shell filesystem . . `/usr/sbin/userdel`. $RM_HOME_OPT $username
149 echoscip-shell system . . echo. "done!"
150 fi
151 ;;
152
153 range)
154 # del a range of users
155 echoscip-shell system . . echo. "Setuping..."
156 run_cmd="$userdel_range_exec_file $prefix $start $end $groupname"
157 eval "$run_cmd | tee -a $userdel_gen_tmp"
158 ;;
159
160 file)
161 # del users which are listed in file
162 echoscip-shell system . . echo. "Setuping..."
163 run_cmd="$userdel_file_exec_file $filename"
164 eval "$run_cmd | tee -a $userdel_gen_tmp"
165 ;;
166
167 list)
168 # del users which are listed line by line in file
169 echoscip-shell system . . echo. "Setuping..."
170 run_cmd="$userdel_list_exec_file $filename"
171 eval "$run_cmd | tee -a $userdel_gen_tmp"
172 ;;
173
174 group)
175 # del the users in a group
176 # check if the group2del exist ?
177 user2del=`grepscip-shell system . . grep. "^$group2del:" /etc/groupscip-shell filesystem . . `/etc/group`. | awkscip-shell system . . awk. -F':' '{print $4}' | sedscip-shell system . . sed. -e "s/,/ /g" `
178 if ! grepscip-shell system . . grep. "^$group2del:" /etc/groupscip-shell filesystem . . `/etc/group`. > /dev/nullscip-shell filesystem . . `/dev/null`.; then
179 echoscip-shell system . . echo. "The group \"$group2del\" to be killed does not exist!!! Program terminated!"
180 exit 1
181 else
182 echoscip-shell system . . echo. "The usernames for the group \"$group2del\" to be killed are: $user2del, are you sure want to continue ?"
183 echoscip-shell system . . echo. "[y/N] "
184 read kill_group_confirm
185 case "$kill_group_confirm" in
186 y|Y|[yY][eE][sS])
187 continue
188 ;;
189 *)
190 echoscip-shell system . . echo. "Ok, exit now!"
191 exit 0
192 esac
193
194 fi
195
196 echoscip-shell system . . echo. -n "Do you also want to clean user's home directory [y/N] ? "
197 read clean_home
198 case "$clean_home" in
199 y|Y|[yY][eE][sS])
200 echoscip-shell system . . echo. "Warning! The user's home directory will be deleted! Are you sure ?"
201 echoscip-shell system . . echo. -n "[y/N] "
202 read clean_home_confirm
203 case "$clean_home_confirm" in
204 y|Y)
205 RM_HOME_OPT="-r"
206 ;;
207 *)
208 RM_HOME_OPT=""
209 esac
210 ;;
211 *)
212 RM_HOME_OPT=""
213 esac
214 echoscip-shell system . . echo. -n "Do you also want to clean group [Y/n] ? "
215 read clean_group
216 case "$clean_group" in
217 n|N|[nN][oO])
218 RM_GROUP_OPT=""
219 ;;
220 *)
221 RM_GROUP_OPT="yes"
222 esac
223 echoscip-shell system . . echo. "Setuping..."
224 for iuser in $user2del; do
225 echoscip-shell system . . echo. -n "Deleting account $iuser..."
226 /usr/sbin/userdelscip-shell filesystem . . `/usr/sbin/userdel`. $RM_HOME_OPT $iuser
227 echoscip-shell system . . echo. "done!"
228 done
229
230 if [scip-shell system . . `[`. "$RM_GROUP_OPT" = "yes" ]; then
231 if grepscip-shell system . . grep. "^$group2del:" /etc/groupscip-shell filesystem . . `/etc/group`. >/dev/nullscip-shell filesystem . . `/dev/null`.; then
232 echoscip-shell system . . echo. -n "Deleting group $group2del..."
233 /usr/sbin/groupdelscip-shell filesystem . . `/usr/sbin/groupdel`. $group2del
234 echoscip-shell system . . echo. "done!"
235 fi
236 fi
237 ;;
238
239 esac
240
241 #
242 echoscip-shell system . . echo. "Now update the NIS data in /var/yp ..."
243 makescip-shell system . . make. -C /var/yp/scip-shell filesystem . . `/var/yp/`.
244 echoscip-shell system . . echo.
245
246 #
247 [scip-shell system . . `[`. -f "$userdel_gen_tmp" ] && rmscip-shell system . . rm. -f $userdel_gen_tmp
248
249 echoscip-shell system . . echo. "Done."
250 exit 0