Debian Codegraph @

setup/files/misc/drblthincli

raw symbols SCIP
1 #!/bin/bash
2 # drblthincli This shell script takes care of DRBL thin client
3 #
4 # chkconfig: 2345 98 2
5 # description: drblthincli is a script to let DRBL client run server's gdm/kdm/xdm, i.e. remote display
6 #
7 # Author: Steven Shiau <steven _at_ clonezilla org>
8 # License: GPL
9 #
10 # For SuSE insserv
11 ### BEGIN INIT INFO
12 # Provides: drblthincli
13 # Required-Start: $network $portmap $remote_fs ypbind xfs
14 # Required-Stop: $network $portmap $remote_fs ypbind xfs
15 # X-UnitedLinux-Should-Start:
16 # X-UnitedLinux-Should-Stop:
17 # Default-Start: 2 3 4 5
18 # Default-Stop: 0 1 2 6
19 # Description: Start DRBL terminal mode
20 ### END INIT INFO
21
22 # For SuSE
23 [ -e /etc/rc.status ] && . /etc/rc.status
24
25 # Load DRBL setting and functions
26 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
27
28 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
29
30 #
31 PATH=$PATH:/usr/X11R6/bin
32
33 if [ -e /etc/debian_version ]; then
34 # Debian
35 LOG_CMD="echo"
36 elif [ -e /etc/SuSE-release ]; then
37 # SuSE
38 LOG_CMD="echo"
39 else
40 # RH-like
41 LOG_CMD="initlog -n drblthincli -s"
42 fi
43
44 # The mode assigned by server
45 [ ! -f "$SYSCONF_PATH/drblthincli" ] && exit 0
46 . $SYSCONF_PATH/drblthincli
47
48 # The mode assigned when client boots, if this is assigned,
49 # it will overide the mode assigned by server
50 if grep -i -q "drblthincli=on" /proc/cmdline; then
51 DRBL_THIN_CLIENT=on
52 elif grep -i -q "drblthincli=off" /proc/cmdline; then
53 DRBL_THIN_CLIENT=off
54 fi
55
56 #
57 [ "$DRBL_THIN_CLIENT" = "off" ] && exit 0
58
59 # Load config file
60 [ -f /etc/diskless-image/config ] && . /etc/diskless-image/config
61
62 #
63 start() {
64 echo -n $"Starting drblthincli: "
65 # try to get the server IP address
66 NETDEVICES="$(cat /proc/net/dev | awk -F: '/eth.:|tr.:/{print $1}')"
67 for DEVICE in $NETDEVICES; do
68 IP_tmp="$(LC_ALL=C ip addr show dev $DEVICE | awk '/inet / {print $2}' | cut -d/ -f1 | head -n1)"
69 if [ -n "$IP_tmp" ]; then
70 # Got the IP address, stop to get from other port, so break
71 IP=$IP_tmp
72 $LOG_CMD $"Client IP address is $IP (got from [$DEVICE])"
73 break
74 else
75 $LOG_CMD $"Failed to get IP from [$DEVICE]!"
76 $LOG_CMD $"Try next NIC if available..."
77 fi
78 done
79
80 nfsserver="$(drbl-get-nfsserver $IP)"
81 if [ -n "$nfsserver" ]; then
82 $LOG_CMD $"NFS server is $nfsserver"
83 else
84 $LOG_CMD $"Can not find the right NFSSERVER, using default one"
85 nfsserver=$nfsserver_default
86 fi
87
88 # if XF86Config is not available, run firstboot to setup it
89 if [ ! -f "/etc/X11/XF86Config-4" -a ! -f "/etc/X11/XF86Config" -a ! -f "/etc/X11/xorg.conf" ]; then
90 # For RedHat 8.0/9 Fedora Core 1
91 [ -x "/usr/bin/redhat-config-xfree86" ] && /usr/bin/redhat-config-xfree86
92 # For Fedora Core 2
93 [ -x "/usr/bin/system-config-display" ] && /usr/bin/system-config-display
94 # For Mandrake
95 if [ -x "/usr/sbin/XFdrake" ]; then
96 chvt 7
97 TERM=linux XFdrake --noauto < /dev/tty7 > /dev/tty7
98 fi
99 # For Deiban
100 if [ -x "/usr/sbin/dpkg-reconfigure" ]; then
101 LC_ALL=C /usr/sbin/dpkg-reconfigure xserver-xfree86
102 fi
103 fi
104
105 # change to text mode
106 if [ -e /etc/debian_version ]; then
107 # Debian
108 default_dm="$(drbl-check-dm)"
109 # Clean the dm (S99) in rc2.d so that it won't start after this S98drblthincli.
110 rm -f /etc/rc2.d/S*${default_dm}
111
112 pid_run="$(cat /var/run/${default_dm}.pid 2>/dev/null)"
113 if [ -n "$(ps --pid $pid_run 2>/dev/null | grep $default_dm 2>/dev/null)" ]; then
114 /etc/init.d/${default_dm} stop
115 sleep 2
116 fi
117 elif [ -e /etc/SuSE-release ]; then
118 # SuSE
119 /etc/init.d/xdm stop
120 sleep 2
121 else
122 # RH-like
123 # set the init to 3 so that we can run X -query... We do not want the
124 # local gdm (/usr/bin/gdmgreeter) to run...
125 telinit 3; sleep 2
126 fi
127 # How about in Mandrake ? Will dm run ?
128 X -query $nfsserver vt7 >/dev/null &
129 #X :0 -audit 0 -auth /var/gdm/:0.Xauth -query $nfsserver vt7
130 RETVAL=$?
131 if [ ! -f /etc/debian_version -a ! -f /etc/SuSE-release ]; then
132 # For RH-like, we create the tag for service.
133 [ "$RETVAL" = 0 ] && touch /var/lock/subsys/drblthincli
134 fi
135 return $RETVAL
136 }
137
138 stop() {
139 echo -n $"Shutting down drblthincli: "
140 if [ -e /etc/debian_version ]; then
141 # Debian
142 default_dm="$(drbl-check-dm)"
143 (cd /etc/rc2.d; ln -fs /etc/init.d/${default_dm} S99${default_dm})
144 PID_X="$(pidof X)"
145 for ipid in $PID_X; do
146 kill -9 $ipid
147 RETVAL=$((RETVAL + $?))
148 done
149 else
150 # For RH-like, we create the tag for service.
151 killproc X
152 RETVAL=$?
153 [ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/drblthincli
154 fi
155 echo
156 return $RETVAL
157 }
158
159 ###
160 case "$1" in
161 "start")
162 start
163 ;;
164 "stop")
165 stop
166 ;;
167 "restart")
168 $0 stop
169 $0 start
170 ;;
171 *)
172 echo $"Usage: $0 {start|stop|restart}"
173 exit 1
174 esac