components/texinfo/svc-texinfo-update
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Mon, 11 Mar 2013 10:38:09 -0700
branchs11-update
changeset 2520 ceec631e74d1
parent 599 3493d2848bde
child 971 345f87d27ffb
permissions -rw-r--r--
Close of build 10.
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
#
599
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
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
599
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    69
		if [[ -f ${dir_file}.new ]] ; then
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    70
			# new dir file created, replace the original one
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    71
			mv -f ${dir_file}.new ${dir_file}
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    72
			chmod -f 0644 ${dir_file}
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    73
			chown -f ${owner_group} ${dir_file}
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    74
			ln -s ${1} ${dir_file}.backlink 2>/dev/null
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    75
		else
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    76
			# no dir file created (no input files installed)
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    77
			rm -f ${dir_file} ${dir_file}.backlink
3493d2848bde 7109099 application/texinfo-update's start method throws errors
Petr Cvachoucek <petr.cvachoucek@oracle.com>
parents: 559
diff changeset
    78
		fi
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    79
		;;
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    80
	esac
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    81
}
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    82
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    83
### Begin Here ###
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    84
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    85
case "$1" in
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    86
'start'|'refresh')
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    87
	# refresh texinfo directories
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    88
	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
    89
			  sort -u) ; do
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    90
		populate_texinfo_directory /${dir_link}
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    91
	done
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    92
	# remove any unreferenced directories
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    93
	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
    94
		path=$(readlink ${link})
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    95
		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
    96
			file=${link%.backlink}
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    97
			echo -n "removing unreferenced texinfo directory: "
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
    98
			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
    99
			rm -f ${file} ${link}
221
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   100
		fi
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   101
	done
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   102
	;;
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   103
*)
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   104
	echo "Usage: $0 (start|refresh)"
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   105
	exit 1
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   106
	;;
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   107
esac
a82f927119a1 7017805 texinfo should move to userland
Norm Jacobs <Norm.Jacobs@Oracle.COM>
parents:
diff changeset
   108
exit $SMF_EXIT_OK