components/texinfo/svc-texinfo-update
changeset 559 5ec27e888a6e
parent 536 cc30c1136ebb
child 599 3493d2848bde
equal deleted inserted replaced
558:f30a27eeab26 559:5ec27e888a6e
    19 #
    19 #
    20 # CDDL HEADER END
    20 # CDDL HEADER END
    21 #
    21 #
    22 
    22 
    23 #
    23 #
    24 # Copyright (c) 2011, Oracle and/or it's affiliates.  All rights reserved.
    24 # Copyright (c) 2011, Oracle and/or its affiliates.  All rights reserved.
    25 #
    25 #
    26 
    26 
    27 . /lib/svc/share/smf_include.sh
    27 . /lib/svc/share/smf_include.sh
    28 
    28 
       
    29 PATH=/usr/bin
       
    30 
    29 TEXINFO_DATA_DIR="/var/info"
    31 TEXINFO_DATA_DIR="/var/info"
       
    32 
       
    33 function readlink() {
       
    34 	while getopts f name; do
       
    35 		case $name in
       
    36 			f) follow=1 ;;
       
    37 		esac
       
    38 	done
       
    39 	shift $((OPTIND - 1))
       
    40 
       
    41 	if (( follow )); then
       
    42 		python -ESc "import os; print os.path.realpath('$1')"
       
    43 	else    
       
    44 		python -ESc "import os; print os.readlink('$1')"
       
    45         fi
       
    46 }
    30 
    47 
    31 function populate_texinfo_directory() {
    48 function populate_texinfo_directory() {
    32 	directory=$(dirname $1)
    49 	directory=$(dirname $1)
    33 	dir_file=$(readlink -f $1)
    50 	dir_file=$(readlink -f $1)
    34 
    51 
    35 	[[ ${dir_file} -ot ${directory} ]] || return
    52 	[[ ${dir_file} -ot ${directory} ]] || return
    36 
    53 
    37 	case "${dir_file}" in
    54 	case "${dir_file}" in
    38 	/var/info/*)	# Only process if the link resolves inside /var/info.
    55 	/var/info/*)	# Only process if the link resolves inside /var/info.
    39 		echo "populating ${dir_file} from ${directory}"
    56 		echo "populating ${dir_file} from ${directory}"
    40 		/bin/rm -f ${dir_file}.new
    57 		rm -f ${dir_file}.new
    41 		for info_file in $(find ${directory} -type f | \
    58 		for info_file in $(find ${directory} -type f | \
    42 				   egrep -v -e '-[0-9]+$') ; do
    59 				   egrep -v -e '-[0-9]+$') ; do
    43 			/usr/bin/install-info --dir-file=${dir_file}.new \
    60 			install-info --dir-file=${dir_file}.new \
    44 				--info-file=${info_file}
    61 				--info-file=${info_file}
    45 		done
    62 		done
    46 		owner_group='root:bin'	# default owner/group
    63 		owner_group='root:bin'	# default owner/group
    47 		if [[ -f ${dir_file} ]] ; then
    64 		if [[ -f ${dir_file} ]] ; then
    48 			# get owner/group from original file
    65 			# get owner/group from original file
    49 			group_bin=$(/bin/ls -l ${dir_file} | \
    66 			group_bin=$(ls -l ${dir_file} | \
    50 				    awk '{print $3":"$4}')
    67 				    awk '{print $3":"$4}')
    51 		fi
    68 		fi
    52 		/bin/mv -f ${dir_file}.new ${dir_file}
    69 		mv -f ${dir_file}.new ${dir_file}
    53 		/bin/chmod -f 0644 ${dir_file}
    70 		chmod -f 0644 ${dir_file}
    54 		/bin/chown -f ${owner_group} ${dir_file}
    71 		chown -f ${owner_group} ${dir_file}
    55 		/bin/ln -s ${1} ${dir_file}.backlink 2>/dev/null
    72 		ln -s ${1} ${dir_file}.backlink 2>/dev/null
    56 		;;
    73 		;;
    57 	esac
    74 	esac
    58 }
    75 }
    59 
    76 
    60 ### Begin Here ###
    77 ### Begin Here ###
    68 	done
    85 	done
    69 	# remove any unreferenced directories
    86 	# remove any unreferenced directories
    70 	for link in $(find ${TEXINFO_DATA_DIR} -type l -name '*.backlink') ; do
    87 	for link in $(find ${TEXINFO_DATA_DIR} -type l -name '*.backlink') ; do
    71 		path=$(readlink ${link})
    88 		path=$(readlink ${link})
    72 		if [[ ! -L ${path} ]] ; then
    89 		if [[ ! -L ${path} ]] ; then
    73 			file=$(expr "${link}" : "\(.*\)\.backlink")
    90 			file=${link%.backlink}
    74 			echo -n "removing unreferenced texinfo directory: "
    91 			echo -n "removing unreferenced texinfo directory: "
    75 			echo "${file} ${link}"
    92 			echo "${file} ${link}"
    76 			/bin/rm -f ${file} ${link}
    93 			rm -f ${file} ${link}
    77 		fi
    94 		fi
    78 	done
    95 	done
    79 	;;
    96 	;;
    80 *)
    97 *)
    81 	echo "Usage: $0 (start|refresh)"
    98 	echo "Usage: $0 (start|refresh)"