xref: /illumos-gate/usr/src/cmd/man/update-man-index (revision b9a2a14b8f156d14859ac7ceeea07ac7194df08d)
1#!/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source. A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
13#
14
15[ -f /lib/svc/share/smf_include.sh ] || exit 1
16
17. /lib/svc/share/smf_include.sh
18
19# Associative array to hold unique components for manpath
20typeset -A manpath
21
22default_system_path=
23if [ -f /etc/default/login ]; then
24	default_system_path="`grep '^PATH=' /etc/default/login | sed -n '
25	    s/PATH=//
26	    p
27	    q
28	    '`"
29fi
30
31oIFS="$IFS"; IFS=":"
32# The config/manpath property from the service will have been passed as
33# arguments to this method script.
34for p in $@; do
35	manpath["$p"]=1
36done
37
38# Add any additional man directories from the default system path
39for p in $default_system_path; do
40	dir="`dirname "$p"`"
41	for suffix in man share/man; do
42		[ -d "$dir/$suffix" ] && manpath["$dir/$suffix"]=1
43	done
44done
45IFS="$oIFS"
46
47MANPATH=
48for p in "${!manpath[@]}"; do
49	MANPATH+="${MANPATH:+:}$p"
50done
51
52echo "Rebuilding man page index using $MANPATH"
53export MANPATH
54/usr/bin/man -w
55
56exit 0
57