1 #! /usr/bin/ksh
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 #
  24 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 [ -n "$DEBUG" ] && [ "$DEBUG" != "0" ] && set -x
  28 
  29 
  30 NAME=`basename $0`
  31 CDIR=`pwd`
  32 
  33 id | grep "0(root)" > /dev/null 2>&1
  34 if [ $? -ne 0 ]; then
  35         echo "$NAME: This script require root permission to run."
  36         exit 99
  37 fi
  38 
  39 PATH=/usr/bin:/usr/sbin:$PATH; export PATH
  40 DOSHARE=_doSHareDir_
  41 SHFiles=$DOSHARE/_ShFiles
  42 ZONEPATH=_zonePATH_
  43 
  44 if [ "X$ZONEPATH" != "X" ]; then
  45         ZONEROOT=$ZONEPATH/root
  46 else
  47         ZONEROOT=""
  48 fi
  49 
  50 [ ! -d $DOSHARE ] && mkdir -m 0777 -p $DOSHARE || chmod 0777 $DOSHARE
  51 echo "doshare is now running ..."
  52 > $SHFiles
  53 
  54 while :; do
  55         sleep 2
  56         # exit if DOSHARE directory is removed from client
  57         [ ! -d $DOSHARE ] && exit 2
  58         action=`ls -d $DOSHARE/*are 2>/dev/null | nawk -F\/ '{print $NF}'`
  59         sleep 2         # allow client writes path to this file on server
  60 
  61         case $action in
  62           share)
  63                 spath=`cat $DOSHARE/share`
  64                 echo $spath | grep "ck_symlink" > /dev/null 2>&1
  65                 [ $? -eq 0 ] && ln -s $ZONEROOT/usr/lib $spath
  66                 share $spath > $DOSHARE/DONE 2>&1
  67                 if [ $? -ne 0 ]; then
  68                     echo "share <$spath> failed." >> $DOSHARE/DONE 2>&1
  69                 else 
  70                     ckPath=$spath
  71                     Type=`ls -l $spath | cut -c 1`
  72                     [ "$Type" = "l" ] && \
  73                         ckPath=`ls -l $spath | awk '{print $NF}'`
  74                     share | grep "$ckPath" > $DOSHARE/DONE 2>&1
  75                     if [ $? -ne 0 ]; then
  76                         echo "<$spath> not in share table" >> $DOSHARE/DONE 2>&1
  77                     else
  78                         echo "share <$spath> OK in `uname -n`" \
  79                                 > $DOSHARE/DONE 2>&1
  80                         echo "$spath" >> $SHFiles
  81                         sleep 1         # allow DONE file write to client
  82                     fi
  83                 fi
  84                 rm -f $DOSHARE/share
  85                 ;;
  86           unshare)
  87                 spath=`cat $DOSHARE/unshare`
  88                 ckPath=$spath
  89                 Type=`ls -l $spath | cut -c 1`
  90                 [ "$Type" = "l" ] && \
  91                         ckPath=`ls -l $spath | awk '{print $NF}'`
  92                 unshare $ckPath > $DOSHARE/DONE 2>&1
  93                 if [ $? != 0 ]; then
  94                     echo "unshare <$spath> failed." >> $DOSHARE/DONE 2>&1
  95                 else
  96                     share | grep "$ckPath" > $DOSHARE/DONE 2>&1
  97                     if [ $? -eq 0 ]; then
  98                         echo "<$ckPath> is still in share table." \
  99                                 >> $DOSHARE/DONE 2>&1
 100                     else
 101                         echo "unshare <$ckPath> OK in `uname -n`" \
 102                                 > $DOSHARE/DONE 2>&1
 103                         sleep 1         # allow DONE file write to client
 104                     fi
 105                 fi
 106                 echo $spath | grep "ck_symlink" > /dev/null 2>&1
 107                 [ $? -eq 0 ] && rm -f $spath
 108                 rm -f $DOSHARE/unshare
 109                 ;;
 110           killushare)
 111                 for spath in `sort $SHFiles | uniq`
 112                 do
 113                         unshare $spath > /dev/null 2>&1
 114                 done
 115                 echo "doshare is now killed ..." > $DOSHARE/DONE 2>&1
 116                 exit 0
 117                 ;;
 118           *)
 119                 continue
 120                 ;;
 121 
 122         esac
 123 done
 124 
 125 exit 0