#!/bin/sh
#
# Install a man page, but fixing up paths as we go.  All of the man pages
# are written to use the Transarc paths, and this script fixes those paths to
# be correct for the chosen configure options as the man pages are installed.
# Takes the source man page file and the destination path as arguments.

set -e

manpage="$1"
dest="$2"

install=/home/afsbuild/test/sgi_65/sgi_65/src/pinstall/pinstall

# We have to include all of the variables here since several of them refer to
# each other and this is the only way we get them all expanded.
prefix=/usr/local
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
includedir=${prefix}/include
libdir=${exec_prefix}/lib
libexecdir=${exec_prefix}/libexec
localstatedir=${prefix}/var
mandir=${prefix}/share/man
sbindir=${exec_prefix}/sbin
sysconfdir=${prefix}/etc
afsbackupdir=/usr/afs/backup
afsbosconfigdir=/usr/afs/local
afsconfdir=/usr/afs/etc
afsdbdir=/usr/afs/db
afslocaldir=/usr/afs/local
afslogsdir=/usr/afs/logs
afssrvbindir=/usr/afs/bin
afskerneldir=/usr/vice/etc
afssrvlibexecdir=/usr/afs/bin
afssrvsbindir=/usr/afs/bin
viceetcdir=/usr/vice/etc

# Substitute the paths into a local temporary file and then install it with
# $install.
sed -e "s%/usr/afs/local/BosConfig%${afsbosconfigdir}/BosConfig%g" \
    -e "s%/usr/afs/etc%${afsconfdir}%g" \
    -e "s%/usr/afs/backup%${afsbackupdir}%g" \
    -e "s%/usr/afs/bin%${afssrvlibexecdir}%g" \
    -e "s%/usr/afs/db%${afsdbdir}%g" \
    -e "s%/usr/afs/local%${afslocaldir}%g" \
    -e "s%/usr/afs/logs%${afslogsdir}%g" \
    -e "s%/usr/vice/etc%${viceetcdir}%g" "$manpage" > "$manpage".tmp
$install -c -f -m 0644 "$manpage".tmp "$dest"
rm "$manpage".tmp
