Debian Codegraph @

sbin/drbl-user-env-reset

raw symbols SCIP
1 #!/bin/bash
2 # Author: Blake, Kuo-Lien Huang
3 # License: GPL
4 # Description: reset use's home directory as initial status.
5 #
6 # Modified by Steven Shiau <[email protected]> to be used in DRBL for RedHat
7
8 # Load DRBL setting and functions
9 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
10
11 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
12
13 #
14 check_if_root
15
16 #
17 run_cmd="`basename $0`"
18
19 #
20 usage() {
21 echo "Reset the files in user's home directory."
22 echo "Usage: $run_cmd [OPTION]"
23 echo "Options:"
24 language_help_prompt_by_idx_no
25 echo "-g, --group GROUP: set the GROUP to be processed."
26 echo "-a, --all: process all user except root."
27 echo "-u, --auto-login: process auto-login accounts."
28 echo "-v, --verbose prints out verbose information"
29 echo "If no group or user is assigned, only auto-login account will be reset"
30 echo "Ex:"
31 echo "$run_cmd -g students"
32 }
33
34 #
35 while [ $# -gt 0 ]; do
36 case "$1" in
37 -l|--language)
38 shift; specified_lang="$1"
39 shift;;
40 -g|--group)
41 shift
42 if [ -z "$(echo $1 |grep ^-.)" ]; then
43 # skip the -xx option, in case
44 chosen_group="$1"
45 shift
46 fi
47 ;;
48 -a|--all)
49 shift; chosen_group="all"
50 ;;
51 -u|--auto-login)
52 shift; chosen_group="auto_login"
53 ;;
54 -v|--verbose)
55 shift; VERBOSE="on"
56 ;;
57 -*) echo "${0}: ${1}: invalid option" >&2
58 usage >& 2
59 exit 2 ;;
60 *) break ;;
61 esac
62 done
63
64 ask_and_load_lang_set $specified_lang
65
66 # check if group exists
67 if [ -n "$chosen_group" -a "$chosen_group" != "all" -a "$chosen_group" != "auto_login" -a -z "`grep \"^$chosen_group:\" /etc/group 2>/dev/null`" ]; then
68 echo "group $chosen_group does NOT exist!!!"
69 exit 1
70 fi
71
72 # the default one for chosen_group is auto_login
73 [ -z "$chosen_group" ] && chosen_group="auto_login"
74
75 #
76 if [ -n "$VERBOSE" ]; then
77 echo "chosen_group=$chosen_group"
78 fi
79
80 # main
81 account_list=
82 case "$chosen_group" in
83 all)
84 echo "Process all users..."
85 #
86 IFS_org=$IFS
87 IFS=':'
88 while read uname x uid gid x x x; do
89 # nfs user create a user called "nfsnobody", skip it.
90 if [ "$uid" -ge "$UID_BEGIN_DEFAULT" -a "$uname" != "nfsnobody" ]; then
91 account_list="$account_list $uname"
92 fi
93 done </etc/passwd
94 IFS=$IFS_org
95 ;;
96 auto_login)
97 echo "You did NOT specify group or all users, so process \"auto-login\" users only..."
98 echo -n "Finding the auto login accounts..."
99 # get the autologin account
100 for ihost in `get-client-ip-list`; do
101 iaccount="`get_existing_autologin_account $drblroot/$ihost`"
102 account_list="$account_list $iaccount"
103 echo -n "."
104 done
105 echo " done!"
106 ;;
107 *)
108 echo "Process the users in the chosen group \"$chosen_group\"... "
109 # process the chosen group
110 account_list=$(grep "^$chosen_group:" /etc/group | awk -F':' '{print $4}' | sed -e "s/,/ /g")
111 ;;
112 esac
113
114 # remove the leading space if it exists
115 account_list=`echo $account_list | sed -e "s/^ //g"`
116 # check the account list
117 if [ -z "$account_list" ]; then
118 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
119 echo "No any account you assigned exists! Program terminated!"
120 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
121 exit 1
122 fi
123
124 [ -n "$VERBOSE" ] && echo "account_list=$account_list"
125
126 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
127 echo "$msg_warning_home_dir_will_be_deleted!!!"
128 echo "$msg_these_accounts_are:"
129 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
130 echo "$account_list"
131 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
132 echo "$msg_are_u_sure_u_want_to_continue"
133 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
134 echo -n "[y/N] "
135 read reset_account_confirm
136 case "$reset_account_confirm" in
137 Y|y|[yY][eE][sS])
138 echo "$msg_ok_let_do_it!"
139 ;;
140 *)
141 echo "$msg_do_not_reset_autologin_home_dir! $msg_program_stop!"
142 exit 0
143 esac
144
145 # store the LC_ALL
146 LC_ALL_org=$LC_ALL
147 export LC_ALL=C
148
149 # main
150 for id in $account_list; do
151 USER_HOME_DIR="$(grep "^$id:" /etc/passwd | awk -F':' '{print $6}')"
152 [ -z "$USER_HOME_DIR" -o ! -d "$USER_HOME_DIR" ] && continue
153 login_group="$(id -n -g $id)"
154 echo -n "Reseting account $id's home directory $USER_HOME_DIR... "
155 [ -n "$verbose" ] && rsync_opt_verbose="--progress"
156 rsync -a --delete $rsync_opt_verbose /etc/skel/ $USER_HOME_DIR/
157 chown -R ${id}:${login_group} /etc/skel/ $USER_HOME_DIR/
158 echo "done!"
159 done
160
161 # restore the LC_ALL
162 export LC_ALL=$LC_ALL_org