#!/bin/ksh -p # # Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. # PATH=/usr/bin:/usr/sbin CUR_VERSION="MANINDEX1.8" INDEX_FILES=("term.dic" "term.doc" "term.exp" "term.idx" "term.pos" "term.req") . /lib/svc/share/smf_include.sh USAGE="Usage: $0 { start | refresh }" if [[ $# -ne 1 ]] ; then echo $USAGE exit 2 fi # # Check whether index version in each index file is up to date. # Return 0 if index version is up to date, return 1 otherwise; # check_version() { index_dir=${1}/man-index; state=0; if ! [[ -e "$index_dir" ]]; then return 1; fi for file in "${INDEX_FILES[@]}"; do index_file=${index_dir}/${file}; if [[ -r $index_file ]]; then index_ver=$(strings $index_file | head -1) if [[ "$index_ver" = "$CUR_VERSION" ]]; then continue; fi elif ! [[ -e $index_file ]]; then echo "$index_file hasn't been found!" else echo "$index_file can not be read!" fi state=1; break; done return $state; } # # Check whether man pages have changed after latest index update. # Return 0 if man pages have changed, return 1 otherwise; # check_manpage() { man_path=$1 cache_file=${man_path}/man-index/.index-cache; if [[ -e "$cache_file" ]]; then rev=$(find ${man_path}/man[1-9]* -newer $cache_file | head -1); if [[ -z "$rev" ]]; then return 1; else return 0; fi else return 0; fi } # # Create or update newest index for man pages in appointed man path. # Return 0 if index generated successfully, return 1 otherwise; # gen_index() { man_path=$1 if ! [[ -e "$man_path" ]]; then echo "$man_path does not exist!" return 1; fi if ! [[ -w "$man_path" ]]; then echo "Can not write $man_path due to insufficient permission!" return 1; fi # old version or man page has changed, generate newest index if ! check_version $man_path || check_manpage $man_path; then nice catman -w -M $man_path if [[ $? == 0 ]]; then echo "Index building completed in $man_path" touch ${man_path}/man-index/.index-cache else echo "Index building failed in $man_path" fi else echo "Index up to date in $man_path" fi return 0; } # # Generate index file for: # /usr/share/man # /usr/gnu/share/man # symbolic dirs in /usr/share/man/index.d # start_man_index () { for i in /usr/share/man /usr/gnu/share/man; do gen_index $i done MPATH="/usr/share/man/index.d" if [[ -d $MPATH ]]; then for f in $(ls $MPATH); do if [[ -h ${MPATH}/${f} ]]; then gen_index $(readlink ${MPATH}/${f}) fi done fi return 0; } refresh_man_index () { start_man_index } METHOD=$1 case "$METHOD" in 'start') if ! is_self_assembly_boot; then exit $SMF_EXIT_OK fi # Continue with rest of script ;; 'refresh') # Continue with rest of script ;; -*) echo $USAGE exit 2 ;; *) echo "Invalid method $METHOD" exit 2 ;; esac if smf_is_zone_immutable; then # We need to wait until the catman files have been written. ${METHOD}_man_index else ${METHOD}_man_index & fi exit $SMF_EXIT_OK