components/desktop/desktop-cache/files/icon-cache
changeset 5889 d78a523a8925
equal deleted inserted replaced
5888:09b82e3ff500 5889:d78a523a8925
       
     1 #!/bin/ksh -p
       
     2 #
       
     3 # Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
       
     4 #
       
     5 # Permission is hereby granted, free of charge, to any person obtaining a
       
     6 # copy of this software and associated documentation files (the
       
     7 # "Software"), to deal in the Software without restriction, including
       
     8 # without limitation the rights to use, copy, modify, merge, publish,
       
     9 # distribute, and/or sell copies of the Software, and to permit persons
       
    10 # to whom the Software is furnished to do so, provided that the above
       
    11 # copyright notice(s) and this permission notice appear in all copies of
       
    12 # the Software and that both the above copyright notice(s) and this
       
    13 # permission notice appear in supporting documentation.
       
    14 #
       
    15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
       
    16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
       
    17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
       
    18 # OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
       
    19 # HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
       
    20 # INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
       
    21 # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
       
    22 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
       
    23 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
       
    24 #
       
    25 # Except as contained in this notice, the name of a copyright holder
       
    26 # shall not be used in advertising or otherwise to promote the sale, use
       
    27 # or other dealings in this Software without prior written authorization
       
    28 # of the copyright holder.
       
    29 #
       
    30 ###########################################################################
       
    31 #
       
    32 
       
    33 PATH=/usr/bin:/usr/sbin
       
    34 
       
    35 . /lib/svc/share/smf_include.sh
       
    36 
       
    37 USAGE="Usage: $0 { start | refresh }"
       
    38 FIND_NEWER=/usr/share/desktop-cache/find_newer
       
    39 
       
    40 if [ $# -ne 1 ] ; then
       
    41     echo $USAGE
       
    42     exit 2
       
    43 fi
       
    44 
       
    45 #
       
    46 # for each icon directory update the icon cache if:
       
    47 #  - a index.theme file exist 
       
    48 # AND 
       
    49 #  - icons in the directory tree are newer than the icon cache
       
    50 # OR
       
    51 #  - if no cache exist but subdirectories (hence icons) are present
       
    52 #
       
    53 ICONDIR="/usr/share/icons"
       
    54 
       
    55 start_icon_cache ()
       
    56 {
       
    57 test -x /usr/bin/gtk-update-icon-cache || {
       
    58     echo "gtk-update-icon-cache not installed"
       
    59     return
       
    60 }
       
    61 test -w $ICONDIR || { 
       
    62   echo "$ICONDIR is not writable, skipping."
       
    63   return
       
    64 }
       
    65 for DIR in /usr/share/icons/*; do
       
    66      if [ -a "$DIR/index.theme" ] ; then
       
    67       if [ -a "$DIR/icon-theme.cache" ] ; then
       
    68 	RESULT=`${FIND_NEWER} -f -m -c --newer $DIR/icon-theme.cache $DIR 2>/dev/null`
       
    69       else
       
    70 	RESULT=`/usr/bin/find $DIR -type d`
       
    71 	if [ ${#RESULT} == ${#DIR} ]; then
       
    72 	  echo "$DIR doesn't contain subdirectories.  No icon cache is needed"
       
    73 	  RESULT=""
       
    74 	else
       
    75 	  RESULT="nocache"
       
    76 	fi
       
    77       fi
       
    78       if [ -n "$RESULT" ]; then
       
    79 	  if [ "$RESULT" == "nocache" ]; then 
       
    80 	    echo "No icon cache found in $DIR.  Generating one."
       
    81 	  else
       
    82 	    echo "Icons newer than the cache found in $DIR.  Updating the cache." 
       
    83 	  fi
       
    84 	  rm -f $DIR/.icon-theme.cache
       
    85 	  /usr/bin/gtk-update-icon-cache $DIR 
       
    86 	  if [ $? -ne 0 ]; then
       
    87 	    echo "/usr/bin/gtk-update-icon-cache exited with an error while \
       
    88 generating the icon cache for $DIR." 
       
    89 	  else
       
    90 	    echo "Icon cache successfully generated in $DIR"
       
    91 	  fi
       
    92       fi
       
    93      fi
       
    94 done
       
    95 }
       
    96 
       
    97 refresh_icon_cache ()
       
    98 {
       
    99 test -x /usr/bin/gtk-update-icon-cache || {
       
   100     echo "gtk-update-icon-cache not installed"
       
   101     return
       
   102 }
       
   103 test -w $ICONDIR || { 
       
   104   echo "$ICONDIR is not writable, skipping."
       
   105   return
       
   106 }
       
   107 for DIR in /usr/share/icons/*; do
       
   108      if [ -a "$DIR/index.theme" ] ; then
       
   109       if [ -a "$DIR/icon-theme.cache" ] ; then
       
   110 	rm -f $DIR/icon-theme.cache
       
   111 	RESULT=`/usr/bin/find $DIR ! -type d -follow 2>/dev/null`
       
   112       else
       
   113 	RESULT=`/usr/bin/find $DIR -type d`
       
   114 	if [ ${#RESULT} == ${#DIR} ]; then
       
   115 	  echo "$DIR doesn't contain subdirectories.  No icon cache is needed"
       
   116 	  RESULT=""
       
   117 	else
       
   118 	  RESULT="nocache"
       
   119 	fi
       
   120       fi
       
   121       if [ -n "$RESULT" ]; then
       
   122 	  if [ "$RESULT" == "nocache" ]; then 
       
   123 	    echo "No icon cache found in $DIR.  Generating one."
       
   124 	  else
       
   125 	    echo "Icons newer than the cache found in $DIR.  Updating the cache." 
       
   126 	  fi
       
   127 	  rm -f $DIR/.icon-theme.cache
       
   128 	  /usr/bin/gtk-update-icon-cache $DIR 
       
   129 	  if [ $? -ne 0 ]; then
       
   130 	    echo "/usr/bin/gtk-update-icon-cache exited with an error while \
       
   131 generating the icon cache for $DIR." 
       
   132 	  else
       
   133 	    echo "Icon cache successfully generated in $DIR"
       
   134 	  fi
       
   135       fi
       
   136      fi
       
   137 done
       
   138 }
       
   139 
       
   140 METHOD=$1
       
   141 
       
   142 case $METHOD in
       
   143     'start')
       
   144 	# Continue with rest of script
       
   145 	;;
       
   146     'refresh')
       
   147 	;;
       
   148     -*)
       
   149 	echo $USAGE
       
   150 	exit 2
       
   151 	;;
       
   152     *)
       
   153 	echo "Invalid method $METHOD"
       
   154 	exit 2
       
   155 	;;
       
   156 esac
       
   157 
       
   158 ${METHOD}_icon_cache
       
   159 
       
   160 exit $SMF_EXIT_OK