desktop-mime-cache revision 5887
165N/A#!/bin/ksh -p
165N/A#
165N/A# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
165N/A#
165N/A# Permission is hereby granted, free of charge, to any person obtaining a
165N/A# copy of this software and associated documentation files (the
165N/A# "Software"), to deal in the Software without restriction, including
165N/A# without limitation the rights to use, copy, modify, merge, publish,
165N/A# distribute, and/or sell copies of the Software, and to permit persons
165N/A# to whom the Software is furnished to do so, provided that the above
165N/A# copyright notice(s) and this permission notice appear in all copies of
165N/A# the Software and that both the above copyright notice(s) and this
165N/A# permission notice appear in supporting documentation.
165N/A#
165N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
165N/A# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
165N/A# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
165N/A# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
165N/A# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
165N/A# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
165N/A# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
1627N/A# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
165N/A# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
165N/A#
165N/A# Except as contained in this notice, the name of a copyright holder
165N/A# shall not be used in advertising or otherwise to promote the sale, use
1627N/A# or other dealings in this Software without prior written authorization
618N/A# of the copyright holder.
165N/A#
165N/A###########################################################################
844N/A#
1627N/APATH=/usr/bin:/usr/sbin
165N/A
1258N/A. /lib/svc/share/smf_include.sh
165N/A
165N/AUSAGE="Usage: $0 { start | refresh }"
165N/AFIND_NEWER=/usr/share/desktop-cache/find_newer
165N/A
165N/Aif [ $# -ne 1 ] ; then
165N/A echo $USAGE
165N/A exit 2
1627N/Afi
165N/A
165N/A#
165N/A# IF the mime cache exist then :
165N/A# get the list of mime type files newer than the cache file
165N/A# ELSE
165N/A# make list greater than zero to generate a cache
165N/A#
165N/A# generate the cache
165N/A#
165N/A
165N/AMIMEFILE="/usr/share/applications/mimeinfo.cache"
165N/AMIMEDIR="/usr/share/applications"
165N/A
165N/Astart_desktop_mime_cache () {
165N/A
165N/Atest -w $MIMEDIR || {
165N/A echo "$MIMEDIR is not writable, skipping."
165N/A return
165N/A}
165N/A
165N/Aif [ -a $MIMEFILE ]; then
165N/A RESULT=`${FIND_NEWER} -f -c -m \
165N/A --newer $MIMEFILE \
165N/A /usr/share/applications 2>/dev/null`
165N/Aelse
165N/A RESULT="no cache found"
165N/Afi
165N/A
165N/Aif [ -n "$RESULT" ]; then
165N/A test -x /usr/bin/update-desktop-database || {
165N/A echo "update-desktop-database not installed"
165N/A return
165N/A }
165N/A echo "updating desktop file cache"
165N/A /usr/bin/update-desktop-database -q
165N/A if [ $? -ne 0 ]; then
165N/A echo "update-mime-database exited with an error while generating the desktop file cache $MIMEFILE"
165N/A exit $SMF_EXIT_ERR_FATAL
165N/A else
165N/A echo "desktop file cache $MIMEFILE generated"
165N/A fi
165N/Afi
165N/A}
165N/A
165N/Arefresh_desktop_mime_cache () {
165N/A
165N/Atest -w $MIMEDIR || {
165N/A echo "$MIMEDIR is not writable, skipping."
165N/A return
165N/A}
165N/A
165N/Aif [ -a $MIMEFILE ]; then
165N/A RESULT=`/usr/bin/find /usr/share/applications ! -type d -follow 2>/dev/null`
165N/Aelse
165N/A RESULT="no cache found"
165N/Afi
165N/A
165N/Aif [ -n "$RESULT" ]; then
165N/A test -x /usr/bin/update-desktop-database || {
165N/A echo "update-desktop-database not installed"
165N/A return
165N/A }
165N/A echo "updating desktop file cache"
165N/A /usr/bin/update-desktop-database -q
165N/A if [ $? -ne 0 ]; then
165N/A echo "update-mime-database exited with an error while generating the desktop file cache $MIMEFILE"
165N/A exit $SMF_EXIT_ERR_FATAL
181N/A else
165N/A echo "desktop file cache $MIMEFILE generated"
165N/A fi
fi
}
METHOD="$1"
case "$METHOD" in
'start')
# Continue with rest of script
;;
'refresh')
;;
-*)
echo $USAGE
exit 2
;;
*)
echo "Invalid method $METHOD"
exit 2
;;
esac
${METHOD}_desktop_mime_cache
exit $SMF_EXIT_OK