Debian Codegraph @

scripts/sbin/drbl-powerful-thin-client

raw symbols SCIP
1 #!/bin/bash
2 # Author: Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: To set the server so that client can run gdm/kdm remotely.
5
6 # Load DRBL setting and functions
7 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
8
9 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
10
11 #
12 check_if_root
13
14 # Get the $GDM_CFG/$KDM_CFG filename
15 get_gdm_kdm_conf_filename
16 if [ -z "$GDM_CFG" -a -z "$KDM_CFG" ]; then
17 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
18 echo "The GDM or KDM config file is NOT found! Skip setting the DM! Maybe you will not be able to make this DRBL server as thin client server!"
19 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
20 exit 1
21 fi
22
23 #
24 SERVER_INIT="5"
25
26 #
27 usage() {
28 echo "Description:"
29 echo "Switch the DRBL clients to thin or powerful mode."
30 echo "Usage: `basename $0` [-p|--powerful] [-t|--thin]"
31 echo "-p, --powerful Powerful client"
32 echo "-t, --thin Thin client"
33 echo "-h, --hosts IP_LIST Instead of all DRBL clients, assign the clients by IP address, like: -h \"192.168.0.1 192.168.0.2\" NOTE!!! You must put \" \" before and after the IP_LIST!"
34 echo "-g, --no-gen-ssi Do NOT generate DRBL SSI template tarball."
35 language_help_prompt_by_idx_no
36 language_help_prompt_by_idx_name
37 }
38 # option
39 while [ $# -gt 0 ]; do
40 case "$1" in
41 -p|--powerful)
42 shift; xdmcp_mode="off"
43 ;;
44 -t|--thin)
45 shift; xdmcp_mode="on"
46 ;;
47 -h|--hosts)
48 shift;
49 LIST_HOST="on"
50 if [ -z "$(echo $1 |grep ^-.)" ]; then
51 # skip the -xx option, in case
52 IP_LIST="$1"
53 fi
54 shift ;;
55 -g|--no-gen-ssi)
56 gen_ssi="no"
57 shift;;
58 -l|--language)
59 shift;
60 if [ -z "$(echo $1 |grep ^-.)" ]; then
61 # skip the -xx option, in case
62 language_opt="$1"
63 fi
64 shift ;;
65 -ln)
66 shift;
67 if [ -z "$(echo $1 |grep ^-.)" ]; then
68 # skip the -xx option, in case
69 language_opt="$1"
70 fi
71 shift ;;
72 -*) echo "${0}: ${1}: invalid option" >&2
73 usage >& 2
74 exit 2 ;;
75 *) break ;;
76 esac
77 done
78
79 [ -z "$xdmcp_mode" ] && usage && exit 1
80
81 #
82 ask_and_load_lang_set $language_opt
83
84 # function
85 clean_all_client_drblthincli_cfg() {
86 # clean the drblthincli
87 find $drblroot/*/$SYSCONF_PATH/ -name drblthincli -exec rm -f {} \;
88 }
89
90 #
91 set_gdm_remote_access() {
92 action=$1
93 case "$action" in
94 "on")
95 # make sure inittab in the clients is runlevel 5, only in RH-like
96 [ ! -f /etc/debian_version ] && switch_clients_init 5 $IP_LIST
97
98 # for server
99 if [ -e "$GDM_CFG" ]; then
100 # Set DisallowTCP=false in $GDM_CFG
101 lines="$(get_block_line_in_gdm_kdm xdmcp $GDM_CFG)"
102 begin_line=$(echo $lines | awk -F" " '{print $1}')
103 end_line=$(echo $lines | awk -F" " '{print $2}')
104 chk_cmd="if ($begin_line..$end_line) {print}"
105 if [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^DisallowTCP=")" ]; then
106 sub_cmd="if ($begin_line..$end_line) {s/^DisallowTCP=.*/DisallowTCP=false/}"
107 perl -pi -e "$sub_cmd" $GDM_CFG
108 else
109 # insert 1 blank line
110 sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
111 perl -pi -e "$sub_cmd" $GDM_CFG
112 # replace the one we want in the added blank line
113 sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/DisallowTCP=false/gi}"
114 perl -pi -e "$sub_cmd" $GDM_CFG
115 fi
116 fi
117 if [ -e "$FAC_GDM_CFG" ]; then
118 # Debian Etch does not have $FAC_GDM_CFG
119 perl -p -i -e "s/^[[:space:]]*#*DisallowTCP=.*/DisallowTCP=false/" $FAC_GDM_CFG
120 fi
121 #
122 lines=$(get_block_line_in_gdm_kdm xdmcp $GDM_CFG)
123 begin_line=$(echo $lines | awk -F" " '{print $1}')
124 end_line=$(echo $lines | awk -F" " '{print $2}')
125 chk_cmd="if ($begin_line..$end_line) {print}"
126 # If we found the xdmcp in gdm.conf is "Enable=false", enable it.
127 # If the xdmcp setting is already on, we should not restart gdm if in graphic mode (runlevel 5 or dm is running)
128 # but If the xdmcp setting is already on, we should start gdm if in text mode (runlevel 3 or dm is NOT running)
129 if [ -e /etc/debian_version ]; then
130 # Debian
131 default_dm="$(drbl-check-dm)"
132 pid_run="$(cat /var/run/${default_dm}.pid 2>/dev/null)"
133 if [ -n "$(ps --pid $pid_run | grep $default_dm 2>/dev/null)" ]; then
134 srv_mode=graphic
135 else
136 srv_mode=text
137 fi
138 else
139 # RH-like or SUSE
140 RL=$(runlevel | awk -F" " '{print $2}')
141 if [ "$RL" = "5" ]; then
142 srv_mode=graphic
143 else
144 srv_mode=text
145 fi
146 fi
147 if [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^Enable=false")" ]; then
148 echo "$msg_turn_on_gdm_remote_access"
149 sub_cmd="if ($begin_line..$end_line) {s/^Enable=.*/Enable=true/}"
150 perl -pi -e "$sub_cmd" $GDM_CFG
151
152 # Ask user to restart gdm if necessary
153 [ ! -f /etc/debian_version ] && perl -p -i -e "s/^id:[1-5]:initdefault:/id:$SERVER_INIT:initdefault:/g" /etc/inittab
154 if [ "$srv_mode" = "graphic" ]; then
155 # alread in graphic mode, assume gdm is running.
156 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
157 echo "$msg_logout_X_for_thin_client_gdm"
158 /usr/sbin/gdm-safe-restart
159 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
160 else
161 # not in graphic mode, start gdm now
162 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
163 echo "$msg_restart_graphic_mode_later"
164 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
165 fi
166 elif [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^Enable=true")" ]; then
167 echo "$msg_gdm_remote_access_is_already_on"
168 # If the xdmcp setting is already on, we should start gdm if in runlevel 3
169 if [ "$srv_mode" = "text" ]; then
170 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
171 echo "$msg_restart_graphic_mode_later"
172 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
173 fi
174 else
175 # Empty, such as default custom.conf, we should insert Enable=true in $GDM_CFG
176 lines="$(get_block_line_in_gdm_kdm xdmcp $GDM_CFG)"
177 begin_line=$(echo $lines | awk -F" " '{print $1}')
178 end_line=$(echo $lines | awk -F" " '{print $2}')
179 chk_cmd="if ($begin_line..$end_line) {print}"
180 if [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^Enable=")" ]; then
181 sub_cmd="if ($begin_line..$end_line) {s/^Enable=.*/Enable=true/}"
182 perl -pi -e "$sub_cmd" $GDM_CFG
183 else
184 # insert 1 blank line
185 sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
186 perl -pi -e "$sub_cmd" $GDM_CFG
187 # replace the one we want in the added blank line
188 sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/Enable=true/gi}"
189 perl -pi -e "$sub_cmd" $GDM_CFG
190 fi
191 fi
192
193 # make the tag for client
194 echo "$msg_set_thin_client_mode_for_clients"
195 for ihost in $drblroot/*; do
196 # skip those IP not listed in the $IP_LIST
197 if [ "$LIST_HOST" = "on" ]; then
198 [ -z "$(echo $IP_LIST | grep -E "\<${ihost##/*/}\>")" ] && continue
199 fi
200 echo "Set system config DRBL_THIN_CLIENT=on for client ${ihost##/*/}"
201 echo "DRBL_THIN_CLIENT=on" > $ihost/$SYSCONF_PATH/drblthincli
202 done
203 echo "$msg_done !"
204 ;;
205
206 "off")
207 if [ -e "$GDM_CFG" ]; then
208 # Set DisallowTCP=true in $GDM_CFG
209 lines="$(get_block_line_in_gdm_kdm xdmcp $GDM_CFG)"
210 begin_line=$(echo $lines | awk -F" " '{print $1}')
211 end_line=$(echo $lines | awk -F" " '{print $2}')
212 chk_cmd="if ($begin_line..$end_line) {print}"
213 if [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^DisallowTCP=")" ]; then
214 sub_cmd="if ($begin_line..$end_line) {s/^DisallowTCP=.*/DisallowTCP=true/}"
215 perl -pi -e "$sub_cmd" $GDM_CFG
216 else
217 # insert 1 blank line
218 sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
219 perl -pi -e "$sub_cmd" $GDM_CFG
220 # replace the one we want in the added blank line
221 sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/DisallowTCP=true/gi}"
222 perl -pi -e "$sub_cmd" $GDM_CFG
223 fi
224 fi
225 if [ -e "$FAC_GDM_CFG" ]; then
226 # Debian Etch does not have $FAC_GDM_CFG
227 perl -p -i -e "s/^[[:space:]]*#*DisallowTCP=.*/DisallowTCP=true/" $FAC_GDM_CFG
228 fi
229 lines=$(get_block_line_in_gdm_kdm xdmcp $GDM_CFG)
230 begin_line=$(echo $lines | awk -F" " '{print $1}')
231 end_line=$(echo $lines | awk -F" " '{print $2}')
232 chk_cmd="if ($begin_line..$end_line) {print}"
233 # If we found the xdmcp in gdm.conf is "Enable=true", disable it.
234 # If the xdmcp is already off, we should not restart gdm
235 if [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^Enable=true")" ]; then
236 echo "$msg_turn_on_gdm_remote_access"
237 sub_cmd="if ($begin_line..$end_line) {s/^Enable=.*/Enable=false/}"
238 perl -pi -e "$sub_cmd" $GDM_CFG
239
240 # Ask user to restart gdm if necessary
241 [ ! -f /etc/debian_version ] && perl -p -i -e "s/^id:[1-5]:initdefault:/id:$SERVER_INIT:initdefault:/g" /etc/inittab
242 if [ "$srv_mode" = "graphic" ]; then
243 # alread in graphic mode, assume gdm is running.
244 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
245 echo "$msg_logout_X_for_thin_client_gdm"
246 /usr/sbin/gdm-safe-restart
247 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
248 else
249 # not in graphic mode, start gdm now
250 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
251 echo "$msg_restart_graphic_mode_later"
252 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
253 fi
254 elif [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^Enable=false")" ]; then
255 echo "$msg_gdm_remote_access_is_already_off"
256 else
257 # Empty, such as default custom.conf, we should insert Enable=false in $GDM_CFG
258 lines="$(get_block_line_in_gdm_kdm xdmcp $GDM_CFG)"
259 begin_line=$(echo $lines | awk -F" " '{print $1}')
260 end_line=$(echo $lines | awk -F" " '{print $2}')
261 chk_cmd="if ($begin_line..$end_line) {print}"
262 if [ -n "$(perl -n -e "$chk_cmd" $GDM_CFG | grep -iE "^Enable=")" ]; then
263 sub_cmd="if ($begin_line..$end_line) {s/^Enable=.*/Enable=false/}"
264 perl -pi -e "$sub_cmd" $GDM_CFG
265 else
266 # insert 1 blank line
267 sub_cmd="if ($((end_line))..$((end_line))) {s/^(.*)$/\$1\n/gi}"
268 perl -pi -e "$sub_cmd" $GDM_CFG
269 # replace the one we want in the added blank line
270 sub_cmd="if ($((end_line+1))..$((end_line+1))) {s/^$/Enable=false/gi}"
271 perl -pi -e "$sub_cmd" $GDM_CFG
272 fi
273 fi
274
275 # make a tag for not using thin client
276 echo "$msg_disable_thin_client_mode_for_clients"
277 for ihost in $drblroot/*; do
278 # skip those IP not listed in the $IP_LIST
279 if [ "$LIST_HOST" = "on" ]; then
280 [ -z "$(echo $IP_LIST | grep -E "\<${ihost##/*/}\>")" ] && continue
281 fi
282
283 if [ -d "$$ihost/$SYSCONF_PATH" ]; then
284 echo "Set system config DRBL_THIN_CLIENT=off for client ${ihost##/*/}"
285 echo "DRBL_THIN_CLIENT=off" > $ihost/$SYSCONF_PATH/drblthincli
286 fi
287 done
288 echo "$msg_done !"
289 ;;
290 esac
291 }
292
293 set_kdm_remote_access() {
294 # no $FAC_GDM_CFG file for KDM
295 # and it seems no DisallowTCP in KDM_CFG, anyway, just set it if available
296 action=$1
297 case "$action" in
298 "on")
299 # make sure inittab in the clients is runlevel 5, only in RH-like
300 [ ! -f /etc/debian_version ] && switch_clients_init 5 $IP_LIST
301
302 # for server
303 perl -p -i -e "s/^[[:space:]]*#*DisallowTCP=.*/DisallowTCP=false/" $KDM_CFG
304 lines=$(get_block_line_in_gdm_kdm xdmcp $KDM_CFG)
305 begin_line=$(echo $lines | awk -F" " '{print $1}')
306 end_line=$(echo $lines | awk -F" " '{print $2}')
307 chk_cmd="if ($begin_line..$end_line) {print}"
308 # If we found the xdmcp in kdmrc is "Enable=false", enable it.
309 # If the xdmcp setting is already on, we should not restart kdm if in graphic mode (runlevel 5 or dm is running)
310 # but If the xdmcp setting is already on, we should start kdm if in text mode (runlevel 3 or dm is NOT running)
311 if [ -e /etc/debian_version ]; then
312 # Debian
313 default_dm="$(drbl-check-dm)"
314 pid_run="$(cat /var/run/${default_dm}.pid 2>/dev/null)"
315 if [ -n "$(ps --pid $pid_run | grep $default_dm 2>/dev/null)" ]; then
316 srv_mode=graphic
317 else
318 srv_mode=text
319 fi
320 else
321 # RH-like
322 RL=$(runlevel | awk -F" " '{print $2}')
323 if [ "$RL" = "5" ]; then
324 srv_mode=graphic
325 else
326 srv_mode=text
327 fi
328 fi
329 if [ -n "$(perl -n -e "$chk_cmd" $KDM_CFG | grep "^Enable=false")" ]; then
330 echo "$msg_turn_on_kdm_remote_access"
331 sub_cmd="if ($begin_line..$end_line) {s/^Enable=.*/Enable=true/}"
332 perl -pi -e "$sub_cmd" $KDM_CFG
333
334 # Ask user to restart kdm if necessary
335 [ ! -f /etc/debian_version ] && perl -p -i -e "s/^id:[1-5]:initdefault:/id:$SERVER_INIT:initdefault:/g" /etc/inittab
336 if [ "$srv_mode" = "graphic" ]; then
337 # alread in graphic mode, assume kdm is running.
338 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
339 echo "$msg_restart_X_for_thin_client_kdm"
340 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
341 else
342 # not in graphic mode, start gdm now
343 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
344 echo "$msg_restart_graphic_mode_later"
345 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
346 fi
347 else
348 echo "$msg_kdm_remote_access_is_already_on"
349 if [ "$srv_mode" = "text" ]; then
350 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
351 echo "$msg_restart_graphic_mode_later"
352 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
353 fi
354 fi
355
356 # make the tag for client
357 echo "$msg_set_thin_client_mode_for_clients"
358 for ihost in $drblroot/*; do
359 # skip those IP not listed in the $IP_LIST
360 if [ "$LIST_HOST" = "on" ]; then
361 [ -z "$(echo $IP_LIST | grep -E "\<${ihost##/*/}\>")" ] && continue
362 fi
363
364 echo "Set system config DRBL_THIN_CLIENT=on for client ${ihost##/*/}"
365 echo "DRBL_THIN_CLIENT=on" > $ihost/$SYSCONF_PATH/drblthincli
366 done
367 echo "$msg_done !"
368 ;;
369
370 "off")
371 perl -p -i -e "s/^[[:space:]]*#*DisallowTCP=.*/DisallowTCP=true/" $KDM_CFG
372 lines=$(get_block_line_in_gdm_kdm xdmcp $KDM_CFG)
373 begin_line=$(echo $lines | awk -F" " '{print $1}')
374 end_line=$(echo $lines | awk -F" " '{print $2}')
375 chk_cmd="if ($begin_line..$end_line) {print}"
376 # If we found the xdmcp in gdm.conf is "Enable=true", disable it.
377 # If the xdmcp is already off, we should not restart gdm
378 if [ -n "$(perl -n -e "$chk_cmd" $KDM_CFG | grep "^Enable=true")" ]; then
379 echo "$msg_turn_off_kdm_remote_access"
380 sub_cmd="if ($begin_line..$end_line) {s/^Enable=.*/Enable=false/}"
381 perl -pi -e "$sub_cmd" $KDM_CFG
382
383 # Ask user to restart kdm if necessary
384 [ ! -f /etc/debian_version ] && perl -p -i -e "s/^id:[1-5]:initdefault:/id:$SERVER_INIT:initdefault:/g" /etc/inittab
385 [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
386 echo "$msg_logout_X_for_modified_kdm_config_work"
387 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
388 else
389 echo "$msg_kdm_remote_access_is_already_off"
390 fi
391
392 # make a tag for not using thin client
393 echo "$msg_disable_thin_client_mode_for_clients"
394 for ihost in $drblroot/*; do
395 # skip those IP not listed in the $IP_LIST
396 if [ "$LIST_HOST" = "on" ]; then
397 [ -z "$(echo $IP_LIST | grep -E "\<${ihost##/*/}\>")" ] && continue
398 fi
399
400 echo "Set system config DRBL_THIN_CLIENT=off for client ${ihost##/*/}"
401 echo "DRBL_THIN_CLIENT=off" > $ihost/$SYSCONF_PATH/drblthincli
402 done
403 echo "$msg_done !"
404 ;;
405 esac
406 }
407
408 RC=""
409 preferred="$(drbl-check-dm)"
410 if [ "$preferred" = "gdm" -a -z "$GDM_CFG" ]; then
411 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
412 echo "The GDM config file is NOT found! Skip setting the DM! Maybe you will not be able to make this DRBL server as thin client server!"
413 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
414 exit 1
415 fi
416 if [ "$preferred" = "kdm" -a -z "$KDM_CFG" ]; then
417 [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
418 echo "The KDM config file is NOT found! Skip setting the DM! Maybe you will not be able to make this DRBL server as thin client server!"
419 [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
420 exit 1
421 fi
422
423 RC=$?
424 [ $RC -eq 0 ] && echo "$msg_dm_in_DRBL_server \"$preferred\""
425
426 #
427 case "$preferred" in
428 gdm)
429 set_gdm_remote_access $xdmcp_mode
430 ;;
431 kdm|mdkkdm)
432 set_kdm_remote_access $xdmcp_mode
433 ;;
434 esac
435 #
436 if [ "$gen_ssi" != "no" ]; then
437 echo "-------------------------------------------------------"
438 echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
439 drbl-gen-ssi-files
440 fi