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