Debian Codegraph @

sbin/drbl-fuh

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2 # Author: Blake, Kuo-Lien Huang
3 # License: GPL
4 # Description: put/get the file to/from all DRBL clients,
5 # file utility for host(fuh)
6 #
7 # Modified by Steven Shiau <[email protected]> to be 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 run_cmd="`basenamescip-shell system . . basename. $0`"
16
17 # to backword compatible
18 case "$run_cmd" in
19 "drbl-cp-host"|"drbl-host-cp")
20 run_cmd="drbl-fuh-put"
21 ;;
22 "drbl-rm-host"|"drbl-host-rm")
23 run_cmd="drbl-fuh-rm"
24 ;;
25 "drbl-get-host"|"drbl-host-get")
26 run_cmd="drbl-fuh-get"
27 ;;
28 esac
29
30 usagescip-shell shell shell-project 0.0.0 usage().() {
31 echoscip-shell system . . echo. "NAME Put(default)/get/remove files to/from DRBL clients."
32 echoscip-shell system . . echo.
33 echoscip-shell system . . echo. "DESCRIPTION"
34 echoscip-shell system . . echo. "drbl-cp-host (or drbl-host-cp) for putting files, drbl-get-host (or drbl-host-get) for collecting files, drbl-rm-host (or drbl-host-rm) for removing files."
35 echoscip-shell system . . echo.
36 echoscip-shell system . . echo. "Usage: `basenamescip-shell system . . basename. $0` [-d|--directory DIR ] [-v|--verbose] source target"
37 echoscip-shell system . . echo. "-d, --directory=DIR: process the DIR relative to client root directory"
38 echoscip-shell system . . echo. "-v, --verbose prints out verbose information"
39 echoscip-shell system . . echo. "\"target\" can be a file or a directory, it it's file, it's new filename for source to be copied. If it's a directory, the source will be copied into that directory."
40 echoscip-shell system . . echo.
41 echoscip-shell system . . echo. "Example:"
42 echoscip-shell system . . echo. "drbl-cp-host ./XF86_DEFAULT /etc"
43 echoscip-shell system . . echo. "will copy XF86_DEFAULT into client's /etc directory"
44 echoscip-shell system . . echo.
45 echoscip-shell system . . echo. "drbl-cp-host -d local source_files new_file.txt"
46 echoscip-shell system . . echo. "will copy source_files into client's /local directory as file name new_file.txt"
47 echoscip-shell system . . echo.
48 echoscip-shell system . . echo. "drbl-rm-host -d local target.txt"
49 echoscip-shell system . . echo. "will remove target.txt from client's /local directory"
50 echoscip-shell system . . echo.
51 echoscip-shell system . . echo. "drbl-get-host -d local target.txt"
52 echoscip-shell system . . echo. "will get target.txt from client's /local directory"
53 echoscip-shell system . . echo.
54 echoscip-shell system . . echo. "drbl-get-host -d local \"*.txt\""
55 echoscip-shell system . . echo. "will get *.txt from client's /local directory"
56 echoscip-shell system . . echo. "NOTE!!! You must put \" \" before and after the star wildcard * filename!"
57 }
58
59 #
60 if [scip-shell system . . `[`. "$run_cmd" = "drbl-fuh" ]; then
61 echoscip-shell system . . echo. "use drbl-cp-host (or drbl-host-cp) for putting files, drbl-get-host (or drbl-host-get) for collecting files, drbl-rm-host (or drbl-host-rm) for removing files."
62 exit 1
63 fi
64
65 while [scip-shell system . . `[`. $# -gt 0 ]; do
66 case "$1" in
67 -d|--directory)
68 shift; sub_dir="$1"
69 shift;;
70 -v|--verbose)
71 VERBOSE="on"
72 shift;;
73 -*) echoscip-shell system . . echo. "${0}: ${1}: invalid option" >&2
74 usagescip-shell shell shell-project 0.0.0 usage(). >& 2
75 exit 2 ;;
76 *) break ;;
77 esac
78 done
79
80 # get the source and target
81 source_file=$1
82 target_file=$2
83
84 # check if source_file is dir or file, if dir, append /
85 [scip-shell system . . `[`. -d "$source_file" ] && source_file=$source_file"/"
86
87 # check parameter
88 if [scip-shell system . . `[`. $# -le 0 ]; then
89 usagescip-shell shell shell-project 0.0.0 usage().
90 exit 1
91 fi
92 case "$run_cmd" in
93 "drbl-fuh-put")
94 mode="put"
95 ;;
96 "drbl-fuh-get")
97 mode="get"
98 ;;
99 "drbl-fuh-rm")
100 mode="rm"
101 ;;
102 *)
103 echoscip-shell system . . echo. "Unknown mode! Did you change the filename ?"
104 echoscip-shell system . . echo. "Program terminated!"
105 exit 1
106 ;;
107 esac
108
109 # set the default values if empty
110 [scip-shell system . . `[`. -z "$mode" ] && mode="put"
111 [scip-shell system . . `[`. -z "$source_file" ] && echoscip-shell system . . echo. "No source! Program terminated!" && exit 1
112 [scip-shell system . . `[`. -z "$target_file" ] && target_file="$source_file"
113
114 #
115 if [scip-shell system . . `[`. -n "$VERBOSE" ]; then
116 echoscip-shell system . . echo. "mode=$mode"
117 echoscip-shell system . . echo. "source_file=$source_file"
118 echoscip-shell system . . echo. "target_file=$target_file"
119 fi
120
121 # main
122 unalias ls 2>/dev/nullscip-shell filesystem . . `/dev/null`.
123 nodes_list=$(lsscip-shell system . . ls. $drblroot)
124
125 #
126 if [scip-shell system . . `[`. "$mode" = "rm" ]; then
127 echoscip-shell system . . echo. "Warning! This will delete $source_file in each DRBL client!!! Are you sure ?"
128 echoscip-shell system . . echo. "[y/N]"
129 read rm_confirm
130 case "$rm_confirm" in
131 y|[yY][eE][sS])
132 if [scip-shell system . . `[`. -n "$sub_dir" ]; then
133 echoscip-shell system . . echo. "Do you want to remove the directory \"$sub_dir\" for each host in $drblroot ?"
134 echoscip-shell system . . echo. "[y/N]"
135 read rm_dir_confirm
136 case "$rm_dir_confirm" in
137 y|[yY][eE][sS])
138 rm_dir_confirm="yes"
139 ;;
140 *)
141 rm_dir_confirm="no"
142 ;;
143 esac
144 fi
145 ;;
146 esac
147 fi
148
149 # store the LC_ALL
150 LC_ALL_org=$LC_ALL
151 export LC_ALL=C
152
153 # main
154 for inode in $nodes_list; do
155 CLIENT_DIR="$drblroot/$inode"
156 case "$mode" in
157 "rm")
158 case "$rm_confirm" in
159 y|[yY][eE][sS])
160 # just in case, we separate the rm -rf $sub_dir into two steps
161 rmscip-shell system . . rm. -rfv $CLIENT_DIR/$sub_dir/$source_file
162 if [scip-shell system . . `[`. "$rm_dir_confirm" = "yes" ]; then
163 rmdirscip-shell system . . rmdir. -v $CLIENT_DIR/$sub_dir/
164 fi
165 ;;
166 *)
167 echoscip-shell system . . echo. "abort!"
168 exit
169 esac
170 ;;
171 "get")
172 for ifile in $CLIENT_DIR/$sub_dir/$source_file; do
173 [scip-shell system . . `[`. -f "$ifile" ] && cpscip-shell system . . cp. -av $ifile ${inode}_"$(basenamescip-shell system . . basename. ${ifile})"
174 done
175 ;;
176 "put")
177 [scip-shell system . . `[`. ! -e "$source_file" ] && echoscip-shell system . . echo. "$source_file does not exist!" && exit 1
178 if [scip-shell system . . `[`. -z "$(echoscip-shell system . . echo. "$target_file" | grepscip-shell system . . grep. -Ew "^/etc")" -a \
179 -z "$(echoscip-shell system . . echo. "$target_file" | grepscip-shell system . . grep. -Ew "^/root")" -a \
180 -z "$(echoscip-shell system . . echo. "$target_file" | grepscip-shell system . . grep. -Ew "^/var")" ]; then
181 echoscip-shell system . . echo. "You should use drblpush to deploy the files, not this program. This program `basenamescip-shell system . . basename. $0` will only copy files to DRBL client's /etc, /root, or /var!".
182 else
183 [scip-shell system . . `[`. -n "$sub_dir" ] && mkdirscip-shell system . . mkdir. -p $CLIENT_DIR/$sub_dir
184 cpscip-shell system . . cp. -av $source_file $CLIENT_DIR/$sub_dir/$target_file
185 fi
186 ;;
187 *)
188 usagescip-shell shell shell-project 0.0.0 usage().
189 ;;
190 esac
191 done
192
193 #
194 echoscip-shell system . . echo. "-------------------------------------------------------"
195 echoscip-shell system . . echo. "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
196 drbl-gen-ssi-files
197
198 # restore the LC_ALL
199 export LC_ALL=$LC_ALL_org