#!/bin/ksh93 # License: CDDL 1.0 (see http://opensource.org/licenses/cddl-1.0) # Copyright 2015 Jens Elkner BASEDIR=@CLIENT_BASEDIR@ DEFAULT_CF_DIR=${BASEDIR}/lib/ghc-7.6/package.conf.d . /lib/svc/share/smf_include.sh # on S10 there is no smf_exit_codes.sh function updateCache { [[ -z ${SMF_FMRI} ]] && SMF_FMRI="ghc-pkg-cache-76:default" typeset X L DIR="${ svcprop -p config/pkg_db ${SMF_FMRI} 2>/dev/null ; }" [[ ${DIR} == '""' || -z ${DIR} ]] && DIR="${DEFAULT_CF_DIR}" if [[ ! -w ${DIR} ]]; then print -u2 "${DIR} is not writable, skiping." return ${SMF_EXIT_ERR_PERM} fi if [[ -s ${DIR}/package.cache && ${DIR}/package.cache -nt ${DIR} ]]; then X=${ find ${DIR} -type f -newer ${DIR}/package.cache ; } if [[ -z $X ]]; then # initial db might be 8x 0 - so a "fuzzy" check L=( ${ ls -l ${DIR}/package.cache ; } ) (( L[4] < 9 )) && X=1 fi else # GHC comes always with base pkgs. So this happens on install or if # the admin decided to force the creation of a new one. X=1 fi # -x check is needed to avoid SMF "failed" messages on uninstall if [[ -n $X && -x ${BASEDIR}/bin/ghc-pkg-7.6.3 ]]; then print "GHC update ${DIR}/package.cache" # Since it seems to be a rm/create op, make sure that the cache file # gets "modified" after the dir got modified, so that -nt works above. ${BASEDIR}/bin/ghc-pkg-7.6.3 recache && touch ${DIR}/package.cache fi # return codes undocumented, so assume everything is ok return ${SMF_EXIT_OK} } # Allow easy manual invocation [[ -z $1 ]] && METHOD='refresh' || METHOD="$1" case "${METHOD}" in start|refresh) updateCache ;; stop) ;; *) print -u2 "Usage: ${0##*/} [start|refresh]" && exit 2 esac # exit $?