components/texinfo/svc-texinfo-update
author Rich Burridge <rich.burridge@oracle.com>
Wed, 02 Nov 2011 06:05:14 -0700
changeset 559 5ec27e888a6e
parent 536 cc30c1136ebb
child 599 3493d2848bde
permissions -rw-r--r--
7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     1
#!/bin/bash
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     2
#
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     3
# CDDL HEADER START
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     4
#
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     8
#
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    12
# and limitations under the License.
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    13
#
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    19
#
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    20
# CDDL HEADER END
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    21
#
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    22
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    23
#
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    24
# Copyright (c) 2011, Oracle and/or its affiliates.  All rights reserved.
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    25
#
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    26
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    27
. /lib/svc/share/smf_include.sh
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    28
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    29
PATH=/usr/bin
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    30
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    31
TEXINFO_DATA_DIR="/var/info"
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    32
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    33
function readlink() {
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    34
	while getopts f name; do
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    35
		case $name in
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    36
			f) follow=1 ;;
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    37
		esac
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    38
	done
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    39
	shift $((OPTIND - 1))
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    40
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    41
	if (( follow )); then
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    42
		python -ESc "import os; print os.path.realpath('$1')"
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    43
	else    
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    44
		python -ESc "import os; print os.readlink('$1')"
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    45
        fi
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    46
}
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    47
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    48
function populate_texinfo_directory() {
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    49
	directory=$(dirname $1)
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    50
	dir_file=$(readlink -f $1)
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    51
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    52
	[[ ${dir_file} -ot ${directory} ]] || return
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    53
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    54
	case "${dir_file}" in
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    55
	/var/info/*)	# Only process if the link resolves inside /var/info.
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    56
		echo "populating ${dir_file} from ${directory}"
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    57
		rm -f ${dir_file}.new
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    58
		for info_file in $(find ${directory} -type f | \
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    59
				   egrep -v -e '-[0-9]+$') ; do
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    60
			install-info --dir-file=${dir_file}.new \
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    61
				--info-file=${info_file}
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    62
		done
536
cc30c1136ebb 7092164 application/texinfo-update's start method needs improvement
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 221
diff changeset
    63
		owner_group='root:bin'	# default owner/group
cc30c1136ebb 7092164 application/texinfo-update's start method needs improvement
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 221
diff changeset
    64
		if [[ -f ${dir_file} ]] ; then
cc30c1136ebb 7092164 application/texinfo-update's start method needs improvement
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 221
diff changeset
    65
			# get owner/group from original file
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    66
			group_bin=$(ls -l ${dir_file} | \
536
cc30c1136ebb 7092164 application/texinfo-update's start method needs improvement
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 221
diff changeset
    67
				    awk '{print $3":"$4}')
cc30c1136ebb 7092164 application/texinfo-update's start method needs improvement
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents: 221
diff changeset
    68
		fi
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    69
		mv -f ${dir_file}.new ${dir_file}
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    70
		chmod -f 0644 ${dir_file}
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    71
		chown -f ${owner_group} ${dir_file}
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    72
		ln -s ${1} ${dir_file}.backlink 2>/dev/null
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    73
		;;
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    74
	esac
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    75
}
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    76
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    77
### Begin Here ###
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    78
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    79
case "$1" in
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    80
'start'|'refresh')
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    81
	# refresh texinfo directories
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    82
	for dir_link in $(pkg search -H -l -o path ':link:path:*/info/dir' | \
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    83
			  sort -u) ; do
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    84
		populate_texinfo_directory /${dir_link}
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    85
	done
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    86
	# remove any unreferenced directories
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    87
	for link in $(find ${TEXINFO_DATA_DIR} -type l -name '*.backlink') ; do
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    88
		path=$(readlink ${link})
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    89
		if [[ ! -L ${path} ]] ; then
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    90
			file=${link%.backlink}
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    91
			echo -n "removing unreferenced texinfo directory: "
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    92
			echo "${file} ${link}"
559
5ec27e888a6e 7092165 text/texinfo's missing a dependency on file/gnu-coreutils
Rich Burridge <rich.burridge@oracle.com>
parents: 536
diff changeset
    93
			rm -f ${file} ${link}
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    94
		fi
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    95
	done
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    96
	;;
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    97
*)
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    98
	echo "Usage: $0 (start|refresh)"
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    99
	exit 1
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   100
	;;
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   101
esac
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   102
exit $SMF_EXIT_OK