| 1 | #!/bin/bashscip-shell filesystem . . `/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 | [scip-shell system . . `[`. -e /etc/rc.statusscip-shell filesystem . . `/etc/rc.status`. ] && . /etc/rc.statusscip-shell source . . `/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 [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 34 | # Debian |
| 35 | LOG_CMD="echo" |
| 36 | elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/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 | [scip-shell system . . `[`. ! -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 grepscip-shell system . . grep. -i -q "drblthincli=on" /proc/cmdlinescip-shell filesystem . . `/proc/cmdline`.; then |
| 51 | DRBL_THIN_CLIENT=on |
| 52 | elif grepscip-shell system . . grep. -i -q "drblthincli=off" /proc/cmdlinescip-shell filesystem . . `/proc/cmdline`.; then |
| 53 | DRBL_THIN_CLIENT=off |
| 54 | fi |
| 55 | |
| 56 | # |
| 57 | [scip-shell system . . `[`. "$DRBL_THIN_CLIENT" = "off" ] && exit 0 |
| 58 | |
| 59 | # Load config file |
| 60 | [scip-shell system . . `[`. -f /etc/diskless-image/configscip-shell filesystem . . `/etc/diskless-image/config`. ] && . /etc/diskless-image/configscip-shell source . . `/etc/diskless-image/config`. |
| 61 | |
| 62 | # |
| 63 | startscip-shell shell shell-project 0.0.0 start().() { |
| 64 | echoscip-shell system . . echo. -n $"Starting drblthincli: " |
| 65 | # try to get the server IP address |
| 66 | NETDEVICES="$(catscip-shell system . . cat. /proc/net/devscip-shell filesystem . . `/proc/net/dev`. | awkscip-shell system . . awk. -F: '/eth.:|tr.:/{print $1}scip-shell filesystem . . `/eth.:|tr.:/{print $1}`.')" |
| 67 | for DEVICE in $NETDEVICES; do |
| 68 | IP_tmp="$(LC_ALL=C ip addr show dev $DEVICE | awkscip-shell system . . awk. '/inet / {print $2}scip-shell filesystem . . `/inet / {print $2}`.' | cutscip-shell system . . cut. -d/ -f1 | headscip-shell system . . head. -n1)" |
| 69 | if [scip-shell system . . `[`. -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 [scip-shell system . . `[`. -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 [scip-shell system . . `[`. ! -f "/etc/X11/XF86Config-4scip-shell filesystem . . `/etc/X11/XF86Config-4`." -a ! -f "/etc/X11/XF86Configscip-shell filesystem . . `/etc/X11/XF86Config`." -a ! -f "/etc/X11/xorg.confscip-shell filesystem . . `/etc/X11/xorg.conf`." ]; then |
| 90 | # For RedHat 8.0/9 Fedora Core 1 |
| 91 | [scip-shell system . . `[`. -x "/usr/bin/redhat-config-xfree86scip-shell filesystem . . `/usr/bin/redhat-config-xfree86`." ] && /usr/bin/redhat-config-xfree86scip-shell filesystem . . `/usr/bin/redhat-config-xfree86`. |
| 92 | # For Fedora Core 2 |
| 93 | [scip-shell system . . `[`. -x "/usr/bin/system-config-displayscip-shell filesystem . . `/usr/bin/system-config-display`." ] && /usr/bin/system-config-displayscip-shell filesystem . . `/usr/bin/system-config-display`. |
| 94 | # For Mandrake |
| 95 | if [scip-shell system . . `[`. -x "/usr/sbin/XFdrakescip-shell filesystem . . `/usr/sbin/XFdrake`." ]; then |
| 96 | chvt 7 |
| 97 | TERM=linux XFdrake --noauto < /dev/tty7scip-shell filesystem . . `/dev/tty7`. > /dev/tty7scip-shell filesystem . . `/dev/tty7`. |
| 98 | fi |
| 99 | # For Deiban |
| 100 | if [scip-shell system . . `[`. -x "/usr/sbin/dpkg-reconfigurescip-shell filesystem . . `/usr/sbin/dpkg-reconfigure`." ]; then |
| 101 | LC_ALL=C /usr/sbin/dpkg-reconfigurescip-shell filesystem . . `/usr/sbin/dpkg-reconfigure`. xserver-xfree86 |
| 102 | fi |
| 103 | fi |
| 104 | |
| 105 | # change to text mode |
| 106 | if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/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 | rmscip-shell system . . rm. -f /etc/rc2.d/S*${default_dm} |
| 111 | |
| 112 | pid_run="$(catscip-shell system . . cat. /var/run/${default_dm}.pid 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" |
| 113 | if [scip-shell system . . `[`. -n "$(psscip-shell system . . ps. --pid $pid_run 2>/dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. $default_dm 2>/dev/nullscip-shell filesystem . . `/dev/null`.)" ]; then |
| 114 | /etc/init.d/${scip-shell filesystem . . `/etc/init.d/${default_dm}`.default_dm}scip-shell filesystem . . `/etc/init.d/${default_dm}`. stop |
| 115 | sleepscip-shell system . . sleep. 2 |
| 116 | fi |
| 117 | elif [scip-shell system . . `[`. -e /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then |
| 118 | # SuSE |
| 119 | /etc/init.d/xdmscip-shell filesystem . . `/etc/init.d/xdm`. stop |
| 120 | sleepscip-shell system . . 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; sleepscip-shell system . . sleep. 2 |
| 126 | fi |
| 127 | # How about in Mandrake ? Will dm run ? |
| 128 | X -query $nfsserver vt7 >/dev/nullscip-shell filesystem . . `/dev/null`. & |
| 129 | #X :0 -audit 0 -auth /var/gdm/:0.Xauth -query $nfsserver vt7 |
| 130 | RETVAL=$? |
| 131 | if [scip-shell system . . `[`. ! -f /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. -a ! -f /etc/SuSE-releasescip-shell filesystem . . `/etc/SuSE-release`. ]; then |
| 132 | # For RH-like, we create the tag for service. |
| 133 | [scip-shell system . . `[`. "$RETVAL" = 0 ] && touchscip-shell system . . touch. /var/lock/subsys/drblthincliscip-shell filesystem . . `/var/lock/subsys/drblthincli`. |
| 134 | fi |
| 135 | return $RETVAL |
| 136 | } |
| 137 | |
| 138 | stopscip-shell shell shell-project 0.0.0 stop().() { |
| 139 | echoscip-shell system . . echo. -n $"Shutting down drblthincli: " |
| 140 | if [scip-shell system . . `[`. -e /etc/debian_versionscip-shell filesystem . . `/etc/debian_version`. ]; then |
| 141 | # Debian |
| 142 | default_dm="$(drbl-check-dm)" |
| 143 | (cd /etc/rc2.dscip-shell filesystem . . `/etc/rc2.d`.; lnscip-shell system . . ln. -fs /etc/init.d/${default_dm} S99${default_dm}) |
| 144 | PID_X="$(pidofscip-shell system . . pidof. X)" |
| 145 | for ipid in $PID_X; do |
| 146 | killscip-shell system . . 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 | [scip-shell system . . `[`. "$RETVAL" = 0 ] && rmscip-shell system . . rm. -f /var/lock/subsys/drblthincliscip-shell filesystem . . `/var/lock/subsys/drblthincli`. |
| 154 | fi |
| 155 | echoscip-shell system . . echo. |
| 156 | return $RETVAL |
| 157 | } |
| 158 | |
| 159 | ### |
| 160 | case "$1" in |
| 161 | "start") |
| 162 | startscip-shell shell shell-project 0.0.0 start(). |
| 163 | ;; |
| 164 | "stop") |
| 165 | stopscip-shell shell shell-project 0.0.0 stop(). |
| 166 | ;; |
| 167 | "restart") |
| 168 | $0 stop |
| 169 | $0 start |
| 170 | ;; |
| 171 | *) |
| 172 | echoscip-shell system . . echo. $"Usage: $0 {start|stop|restart}" |
| 173 | exit 1 |
| 174 | esac |