Home | History | Annotate | Download | only in ext-sources
      1 #!/bin/sh
      2 #
      3 # Class Action Script for installing input method modules for libgtk
      4 #
      5 # CDDL HEADER START
      6 #
      7 # The contents of this file are subject to the terms of the
      8 # Common Development and Distribution License, Version 1.0 only
      9 # (the "License").  You may not use this file except in compliance
     10 # with the License.
     11 #
     12 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
     13 # or http://www.opensolaris.org/os/licensing.
     14 # See the License for the specific language governing permissions
     15 # and limitations under the License.
     16 #
     17 # When distributing Covered Code, include this CDDL HEADER in each
     18 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     19 # If applicable, add the following below this CDDL HEADER, with the
     20 # fields enclosed by brackets "[]" replaced with your own identifying
     21 # information: Portions Copyright [yyyy] [name of copyright owner]
     22 #
     23 # CDDL HEADER END
     24 #
     25 #
     26 # Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
     27 # Use is subject to license terms.
     28 #
     29 
     30 F_A=/tmp/im.add.$$
     31 F_M=/tmp/im.merged.$$
     32 pkg_start="# Start $PKGINST"
     33 pkg_end="# End $PKGINST"
     34 
     35 if [ "sparc" = "`uname -p`" ]; then
     36     ARCH=sparcv9
     37 else
     38     ARCH=amd64
     39 fi
     40 
     41 while read src dest; do
     42     if [ ! -f ${dest} ]; then
     43 	echo "$pkg_start"                   > ${dest}
     44 	sed -e "s/@ARCH@/${ARCH}/g" ${src} >> ${dest}
     45 	echo "$pkg_end"                    >> ${dest}
     46     else
     47         sed -e "s/@ARCH@/${ARCH}/g" ${src} > ${F_A}
     48 	# Check if any of the lines from ${src} are already in the file
     49 	do_merge=yes
     50 	# save the standard input as file descriptor 3
     51 	exec 3<&0
     52 	exec < ${F_A}
     53 	while read line; do
     54 	    # input method spec lines start with quotes
     55 	    case "$line" in
     56 		'"'*) ;;
     57                 *) continue; ;;
     58 	    esac
     59 	    if /usr/bin/egrep -s -- "$line" ${dest}; then
     60 		do_merge=no
     61 		break
     62 	    fi
     63 	done
     64 	# restore the standard input
     65 	exec <&3
     66 	# close file descriptor 3
     67 	exec 3<&-
     68 	if [ $do_merge = yes ]; then
     69 	    if egrep -s 'GTK\+ Input Method Modules file' ${F_A}; then
     70 		# The original Gtk+ config file should come first
     71 		# Any additions should be at the end
     72 		echo "$pkg_start"    >> ${F_M}
     73 		cat ${F_A}           >> ${F_M}
     74 		echo "$pkg_end"      >> ${F_M}
     75 		cat ${dest}          >> ${F_M}
     76 	    else
     77 		cat ${dest}          >> ${F_M}
     78 		echo "$pkg_start"    >> ${F_M}
     79 		cat ${F_A}           >> ${F_M}
     80 		echo "$pkg_end"      >> ${F_M}
     81 	    fi
     82 	    cp ${F_M} ${dest}
     83 	    rm -f ${F_M}
     84 	fi
     85         rm -f ${F_A}
     86     fi
     87 done
     88 
     89 exit 0
     90