Debian Codegraph @

sbin/drbl-useradd-file

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 use 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 ACCOUNT_FILE="$1"
16 ACCOUNT_FILE_TMP=`mktempscip-shell system . . mktemp. /tmp/account_tmp.XXXXXXscip-shell filesystem . . `/tmp/account_tmp.XXXXXX`.`
17 mode=""
18
19 USAGE="Usage: $0 account_file"
20 # Check if root or not
21 if [scip-shell system . . `[`. ! "$UID" = "0" ]; then
22 echoscip-shell system . . echo.
23 echoscip-shell system . . echo. "[$LOGNAME] You need to run this script \"$0\" as root."
24 echoscip-shell system . . echo.
25 exit 1
26 fi
27
28 if [scip-shell system . . `[`. $# -ne 1 ]; then
29 echoscip-shell system . . echo. "$USAGE"
30 echoscip-shell system . . echo. "Create or delete accounts from the specified account_file."
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. "-----------------------------------------------------------------"
38 echoscip-shell system . . echo. "# account for student"
39 echoscip-shell system . . echo. "s 89101 89129 g3c9 8"
40 echoscip-shell system . . echo. "# account for teacher"
41 echoscip-shell system . . echo. "tckps 01 99 teacher drblnice"
42 echoscip-shell system . . echo. "-----------------------------------------------------------------"
43 exit 1
44 fi
45
46 [scip-shell system . . `[`. ! -f "$ACCOUNT_FILE" ] && echoscip-shell system . . echo. "File $ACCOUNT_FILE not exists!" && exit 1
47 [scip-shell system . . `[`. ! -f "$useradd_range_exec_file" ] && echoscip-shell system . . echo. "Can NOT find $useradd_range_exec_file file!" && exit 1
48 [scip-shell system . . `[`. ! -f "$userdel_range_exec_file" ] && echoscip-shell system . . echo. "Can NOT find $userdel_range_exec_file file!" && exit 1
49
50 # filter the comment line, only keep the account line
51 grepscip-shell system . . grep. -v '^[[:space:]]*#' $ACCOUNT_FILE > $ACCOUNT_FILE_TMP
52
53 #
54 if [scip-shell system . . `[`. -n "$(basenamescip-shell system . . basename. $0 | grepscip-shell system . . grep. -E "useradd")" ]; then
55 mode="useradd"
56 elif [scip-shell system . . `[`. -n "$(basenamescip-shell system . . basename. $0 | grepscip-shell system . . grep. -E "userdel")" ]; then
57 mode="userdel"
58 else
59 echoscip-shell system . . echo. "Unknown mode!"
60 exit 1
61 fi
62
63 # useradd mode
64 if [scip-shell system . . `[`. "$mode" = "useradd" ]; then
65 while read prefix start end groupname password_opt; do
66 # check if groupname is not valid one
67 if `echoscip-shell system . . echo. "$groupname" | grepscip-shell system . . grep. -q "^[0-9]"`; then
68 echoscip-shell system . . echo. "groupname can NOT begin with digits (0-9)!"
69 echoscip-shell system . . echo. "The one you specified is \"$groupname\""
70 echoscip-shell system . . echo. "Program terminated"
71 exit 1
72 fi
73 if [scip-shell system . . `[`. -n "$prefix" ]; then
74 echoscip-shell system . . echo. -n "Creating accounts with $prefix $start $end $groupname $password_opt"
75 $useradd_range_exec_file $prefix $start $end $groupname $password_opt
76 echoscip-shell system . . echo. "done!"
77 fi
78 done < $ACCOUNT_FILE_TMP
79 fi
80
81 # userdel mode
82 if [scip-shell system . . `[`. "$mode" = "userdel" ]; then
83 # prompt to ask some confirmation
84 echoscip-shell system . . echo. -n "Do you also want to clean user's home directory [y/N] ? "
85 read clean_home
86 case "$clean_home" in
87 y|Y|[yY][eE][sS])
88 echoscip-shell system . . echo. "Warning! The user's home directory will be deleted! Are you sure ?"
89 echoscip-shell system . . echo. -n "[y/N] "
90 read clean_home_confirm
91 ;;
92 *)
93 RM_HOME_OPT=""
94 esac
95 echoscip-shell system . . echo. -n "Do you also want to clean group [Y/n] ? "
96 read clean_group
97 CONFIRM_TMP=`mktempscip-shell system . . mktemp. /tmp/confirm_tmp.XXXXXXscip-shell filesystem . . `/tmp/confirm_tmp.XXXXXX`.`
98 echoscip-shell system . . echo. "$clean_home" >> $CONFIRM_TMP
99 echoscip-shell system . . echo. "$clean_home_confirm" >> $CONFIRM_TMP
100 echoscip-shell system . . echo. "$clean_group" >> $CONFIRM_TMP
101
102 while read prefix start end groupname password_opt; do
103 if [scip-shell system . . `[`. -n "$prefix" ]; then
104 echoscip-shell system . . echo. "Deleting accounts with $prefix $start $end $groupname $password_opt"
105 $userdel_range_exec_file $prefix $start $end $groupname < $CONFIRM_TMP
106 echoscip-shell system . . echo. "done!"
107 fi
108 done < $ACCOUNT_FILE_TMP
109 fi
110
111 [scip-shell system . . `[`. -f "$ACCOUNT_FILE_TMP" ] && rmscip-shell system . . rm. -f $ACCOUNT_FILE_TMP
112 [scip-shell system . . `[`. -f "$CONFIRM_TMP" ] && rmscip-shell system . . rm. -f $CONFIRM_TMP