File: drbl-client-xfs-switch

package info (click to toggle)
drbl 5.7.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,984 kB
  • sloc: sh: 43,522; perl: 8,820; xml: 867; makefile: 131
file content (119 lines) | stat: -rwxr-xr-x 4,977 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Written by Steven Shiau <steven@nchc.org.tw> to use in DRBL for RedHat
# License: GPL
#
# set the iptables NAT
# clean the old tables

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

#
check_if_root

# main
USAGE="Usage: $0 {local|remote}"
switch=$1

#
if [ $# -ne 1 ]; then
  echo "$USAGE"
  echo "Example: use the following to use remote xfs service for clients"
  echo "$0 remote"
  exit 1
fi
#
case "$switch" in
   "remote")
      [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
      echo "Setting the remote xfs for clients..."
      [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
      # Change the xfs setting in server
      # set the client_no first, minimum 10.
      client_no=$(unalias ls 2> /dev/null; ls -d $drblroot/* 2>/dev/null |wc -w|sed -e "s/ //g")
       # / 1 to make the result as integer.
      client_no=$(echo "scale=0; $client_no * $XFS_RATIO / 1" |bc -l)
      [ $client_no -lt 10 ] && client_no=10
      perl -p -i -e "s/^[[:space:]]*[#]*[[:space:]]*client-limit[[:space:]]*=.*/client-limit = $client_no/" /etc/X11/fs/config
      # enable the xfs service with tcp
      perl -p -i -e "s/^.*no-listen = tcp.*/#no-listen = tcp/" /etc/X11/fs/config
      # restart xfs
      /etc/init.d/xfs restart

      # change the XF86Config file in client, for MDK it's XF86Config-4, 
      for ihost in $drblroot/*; do
         # try to get the font server
	 IP=$(basename $ihost)
         font_server=$(grep -e "$drblroot/$IP/etc" $drblroot/$IP/etc/fstab | awk -F":" '{print $1}')
	 [ -z "$font_server" ] && echo "Failed to find the font server...Program terminated!" && exit 1
	 #
	 echo -n "Setting the remote font server in XF86Config for client $IP..."
         if [ -f $ihost/etc/X11/XF86Config ]; then
             # backup first
	     echo "Editing XF86Config..."
             cp -f $ihost/etc/X11/XF86Config $ihost/etc/X11/XF86Config.drblsave
             perl -p -i -e "s/^[[:space:]]*[^#]*[[:space:]]*FontPath[[:space:]]+\".*\".*/\tFontPath     \"tcp\/$font_server:$fs_port\"/" $ihost/etc/X11/XF86Config
             # del the xfs service to clients
             drbl-client-service -h $IP xfs del
             # stop the xfs service in clients
             drbl-doit -h $IP "/etc/init.d/xfs stop"
         fi
         if [ -f $ihost/etc/X11/XF86Config-4 ]; then
             # backup first
             cp -f $ihost/etc/X11/XF86Config-4 $ihost/etc/X11/XF86Config-4.drblsave
             perl -p -i -e "s/^[[:space:]]*[^#]*[[:space:]]*FontPath[[:space:]]+\".*\".*/\tFontPath     \"tcp\/$font_server:$fs_port\"/" $ihost/etc/X11/XF86Config-4
             # del the xfs service to clients
             drbl-client-service -h $IP xfs del
             # stop the xfs service in clients
             drbl-doit -h $IP "/etc/init.d/xfs stop"
         fi
         if [ -f $ihost/etc/X11/XF86Config -a -f $ihost/etc/X11/XF86Config-4 ]; then
             # we need xfs, otherwise firstboot will fail to detect successfully, because no xfs service running locally
             # so keep the xfs service to client
             drbl-client-service -h $IP xfs add
         fi
      done
      #
      echo "done!"
      ;;
    "local")
      [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
      echo "Setting the local xfs for clients..."
      [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
      # Change the xfs setting in server, Default font server comes with client-limt = 10
      client_no=10
      perl -p -i -e "s/^[[:space:]]*[#]*[[:space:]]*client-limit[[:space:]]*=.*/client-limit = $client_no/" /etc/X11/fs/config
      perl -p -i -e "s/^.*no-listen = tcp.*/no-listen = tcp/" /etc/X11/fs/config
      # restart xfs
      /etc/init.d/xfs restart

      # add the xfs service to clients
      drbl-client-service xfs add
      # change the XF86Config file in client, for MDK it's XF86Config-4, 
      # backup first
      for ihost in $drblroot/*; do
	 IP=$(basename $ihost)
	 echo -n "Setting the local font server in XF86Config for client $IP..."
         if [ -f $ihost/etc/X11/XF86Config ]; then
             cp -f $ihost/etc/X11/XF86Config $ihost/etc/X11/XF86Config.drblsave
             perl -p -i -e "s/^[[:space:]]*[^#]*[[:space:]]*FontPath[[:space:]]+\".*\".*/\tFontPath     \"unix\/:$fs_port\"/" $ihost/etc/X11/XF86Config
         fi
         if [ -f $ihost/etc/X11/XF86Config-4 ]; then
             cp -f $ihost/etc/X11/XF86Config-4 $ihost/etc/X11/XF86Config-4.drblsave
             perl -p -i -e "s/^[[:space:]]*[^#]*[[:space:]]*FontPath[[:space:]]+\".*\".*/\tFontPath     \"unix\/:$fs_port\"/" $ihost/etc/X11/XF86Config-4
         fi
      done
      #
      drbl-doit "/etc/init.d/xfs restart"

      echo "done!"

      ;;
    *)
      echo "$USAGE"
esac
#
echo "-------------------------------------------------------"
echo "Since some config files are modified in template client, creating template tarball for DRBL SSI..."
drbl-gen-ssi-files