svc-texinfo-update revision 1085
214N/A#!/bin/bash
214N/A#
1339N/A# CDDL HEADER START
214N/A#
214N/A# The contents of this file are subject to the terms of the
919N/A# Common Development and Distribution License (the "License").
919N/A# You may not use this file except in compliance with the License.
919N/A#
919N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
919N/A# or http://www.opensolaris.org/os/licensing.
919N/A# See the License for the specific language governing permissions
919N/A# and limitations under the License.
919N/A#
919N/A# When distributing Covered Code, include this CDDL HEADER in each
919N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
919N/A# If applicable, add the following below this CDDL HEADER, with the
919N/A# fields enclosed by brackets "[]" replaced with your own identifying
919N/A# information: Portions Copyright [yyyy] [name of copyright owner]
919N/A#
919N/A# CDDL HEADER END
919N/A#
919N/A
214N/A#
214N/A# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
493N/A#
493N/A
1003N/A. /lib/svc/share/smf_include.sh
1003N/A
1003N/APATH=/usr/bin
1003N/A
1339N/ATEXINFO_DATA_DIR="/var/info"
1339N/A
1339N/Afunction readlink() {
1339N/A while getopts f name; do
214N/A case $name in
1339N/A f) follow=1 ;;
214N/A esac
493N/A done
493N/A shift $((OPTIND - 1))
935N/A
935N/A if (( follow )); then
935N/A python -ESc "import os; print os.path.realpath('$1')"
810N/A else
810N/A python -ESc "import os; print os.readlink('$1')"
810N/A fi
493N/A}
493N/A
493N/Afunction populate_texinfo_directory() {
910N/A directory=$(dirname $1)
493N/A dir_file=$(readlink -f $1)
214N/A
214N/A [[ ${dir_file} -ot ${directory} ]] || return
493N/A
214N/A case "${dir_file}" in
214N/A /var/info/*) # Only process if the link resolves inside /var/info.
935N/A echo "populating ${dir_file} from ${directory}"
935N/A rm -f ${dir_file}.new
935N/A for info_file in $(find ${directory} -type f | \
935N/A egrep -v -e '-[0-9]+$') ; do
935N/A install-info --dir-file=${dir_file}.new \
935N/A --info-file=${info_file}
935N/A done
935N/A owner_group='root:bin' # default owner/group
935N/A if [[ -f ${dir_file} ]] ; then
935N/A # get owner/group from original file
935N/A group_bin=$(ls -l ${dir_file} | \
935N/A awk '{print $3":"$4}')
935N/A fi
935N/A if [[ -f ${dir_file}.new ]] ; then
935N/A # new dir file created, replace the original one
935N/A mv -f ${dir_file}.new ${dir_file}
935N/A chmod -f 0644 ${dir_file}
935N/A chown -f ${owner_group} ${dir_file}
935N/A ln -s ${1} ${dir_file}.backlink 2>/dev/null
935N/A else
935N/A # no dir file created (no input files installed)
935N/A rm -f ${dir_file} ${dir_file}.backlink
935N/A fi
935N/A ;;
935N/A esac
935N/A}
935N/A
935N/A### Begin Here ###
935N/A
214N/Acase "$1" in
910N/A'start'|'refresh')
214N/A if [[ "$1" = 'start' ]]; then
935N/A if [[ ! -f "/.SELF-ASSEMBLY-REQUIRED" ]]; then
exit $SMF_EXIT_OK
fi
fi
# refresh texinfo directories
for dir_link in $(pkg search -H -l -o path ':link:path:*/info/dir' | \
sort -u) ; do
# test the directory is writable
if [[ ! -w /${dir_link} ]]; then
echo $SMF_EXIT_OK
else
populate_texinfo_directory /${dir_link}
fi
done
# remove any unreferenced directories
for link in $(find ${TEXINFO_DATA_DIR} -type l -name '*.backlink') ; do
path=$(readlink ${link})
if [[ ! -L ${path} ]] ; then
file=${link%.backlink}
echo -n "removing unreferenced texinfo directory: "
echo "${file} ${link}"
rm -f ${file} ${link}
fi
done
;;
*)
echo "Usage: $0 (start|refresh)"
exit 1
;;
esac
exit $SMF_EXIT_OK