| 1 | #!/bin/bashscip-shell filesystem . . `/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="`basenamescip-shell system . . basename. $0`" |
| 18 | |
| 19 | # |
| 20 | usagescip-shell shell shell-project 0.0.0 usage().() { |
| 21 | echoscip-shell system . . echo. "Reset the files in user's home directory." |
| 22 | echoscip-shell system . . echo. "Usage: $run_cmd [OPTION]" |
| 23 | echoscip-shell system . . echo. "Options:" |
| 24 | language_help_prompt_by_idx_no |
| 25 | echoscip-shell system . . echo. "-g, --group GROUP: set the GROUP to be processed." |
| 26 | echoscip-shell system . . echo. "-a, --all: process all user except root." |
| 27 | echoscip-shell system . . echo. "-u, --auto-login: process auto-login accounts." |
| 28 | echoscip-shell system . . echo. "-v, --verbose prints out verbose information" |
| 29 | echoscip-shell system . . echo. "If no group or user is assigned, only auto-login account will be reset" |
| 30 | echoscip-shell system . . echo. "Ex:" |
| 31 | echoscip-shell system . . echo. "$run_cmd -g students" |
| 32 | } |
| 33 | |
| 34 | # |
| 35 | while [scip-shell system . . `[`. $# -gt 0 ]; do |
| 36 | case "$1" in |
| 37 | -l|--language) |
| 38 | shift; specified_lang="$1" |
| 39 | shift;; |
| 40 | -g|--group) |
| 41 | shift |
| 42 | if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. $1 |grepscip-shell system . . 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 | -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2 |
| 58 | usagescip-shell shell shell-project 0.0.0 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 [scip-shell system . . `[`. -n "$chosen_group" -a "$chosen_group" != "all" -a "$chosen_group" != "auto_login" -a -z "`grepscip-shell system . . grep. \"^$chosen_group:\" /etc/groupscip-shell filesystem . . `/etc/group`. 2>/dev/nullscip-shell filesystem . . `/dev/null`.`" ]; then |
| 68 | echoscip-shell system . . echo. "group $chosen_group does NOT exist!!!" |
| 69 | exit 1 |
| 70 | fi |
| 71 | |
| 72 | # the default one for chosen_group is auto_login |
| 73 | [scip-shell system . . `[`. -z "$chosen_group" ] && chosen_group="auto_login" |
| 74 | |
| 75 | # |
| 76 | if [scip-shell system . . `[`. -n "$VERBOSE" ]; then |
| 77 | echoscip-shell system . . echo. "chosen_group=$chosen_group" |
| 78 | fi |
| 79 | |
| 80 | # main |
| 81 | account_list= |
| 82 | case "$chosen_group" in |
| 83 | all) |
| 84 | echoscip-shell system . . 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 [scip-shell system . . `[`. "$uid" -ge "$UID_BEGIN_DEFAULT" -a "$uname" != "nfsnobody" ]; then |
| 91 | account_list="$account_list $uname" |
| 92 | fi |
| 93 | done </etc/passwdscip-shell filesystem . . `/etc/passwd`. |
| 94 | IFS=$IFS_org |
| 95 | ;; |
| 96 | auto_login) |
| 97 | echoscip-shell system . . echo. "You did NOT specify group or all users, so process \"auto-login\" users only..." |
| 98 | echoscip-shell system . . 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 | echoscip-shell system . . echo. -n "." |
| 104 | done |
| 105 | echoscip-shell system . . echo. " done!" |
| 106 | ;; |
| 107 | *) |
| 108 | echoscip-shell system . . echo. "Process the users in the chosen group \"$chosen_group\"... " |
| 109 | # process the chosen group |
| 110 | account_list=$(grepscip-shell system . . grep. "^$chosen_group:" /etc/groupscip-shell filesystem . . `/etc/group`. | awkscip-shell system . . awk. -F':' '{print $4}' | sedscip-shell system . . sed. -e "s/,/ /g") |
| 111 | ;; |
| 112 | esac |
| 113 | |
| 114 | # remove the leading space if it exists |
| 115 | account_list=`echoscip-shell system . . echo. $account_list | sedscip-shell system . . sed. -e "s/^ //g"` |
| 116 | # check the account list |
| 117 | if [scip-shell system . . `[`. -z "$account_list" ]; then |
| 118 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 119 | echoscip-shell system . . echo. "No any account you assigned exists! Program terminated!" |
| 120 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 121 | exit 1 |
| 122 | fi |
| 123 | |
| 124 | [scip-shell system . . `[`. -n "$VERBOSE" ] && echoscip-shell system . . echo. "account_list=$account_list" |
| 125 | |
| 126 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 127 | echoscip-shell system . . echo. "$msg_warning_home_dir_will_be_deleted!!!" |
| 128 | echoscip-shell system . . echo. "$msg_these_accounts_are:" |
| 129 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 130 | echoscip-shell system . . echo. "$account_list" |
| 131 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 132 | echoscip-shell system . . echo. "$msg_are_u_sure_u_want_to_continue" |
| 133 | [scip-shell system . . `[`. "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 134 | echoscip-shell system . . echo. -n "[y/N] " |
| 135 | read reset_account_confirm |
| 136 | case "$reset_account_confirm" in |
| 137 | Y|y|[yY][eE][sS]) |
| 138 | echoscip-shell system . . echo. "$msg_ok_let_do_it!" |
| 139 | ;; |
| 140 | *) |
| 141 | echoscip-shell system . . 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="$(grepscip-shell system . . grep. "^$id:" /etc/passwdscip-shell filesystem . . `/etc/passwd`. | awkscip-shell system . . awk. -F':' '{print $6}')" |
| 152 | [scip-shell system . . `[`. -z "$USER_HOME_DIR" -o ! -d "$USER_HOME_DIR" ] && continue |
| 153 | login_group="$(idscip-shell system . . id. -n -g $id)" |
| 154 | echoscip-shell system . . echo. -n "Reseting account $id's home directory $USER_HOME_DIR... " |
| 155 | [scip-shell system . . `[`. -n "$verbose" ] && rsync_opt_verbose="--progress" |
| 156 | rsyncscip-shell system . . rsync. -a --delete $rsync_opt_verbose /etc/skel/scip-shell filesystem . . `/etc/skel/`. $USER_HOME_DIR/ |
| 157 | chownscip-shell system . . chown. -R ${id}:${login_group} /etc/skel/scip-shell filesystem . . `/etc/skel/`. $USER_HOME_DIR/ |
| 158 | echoscip-shell system . . echo. "done!" |
| 159 | done |
| 160 | |
| 161 | # restore the LC_ALL |
| 162 | export LC_ALL=$LC_ALL_org |