#!/bin/bash
#
# Description: Script to generate kafs-client man pages from POD
# Author: Bill MacAllister <bill@ca-zephyr.org>
# Copyright (c) 2023 Bill MacAllister <bill@ca-zephyr.org>

VERSION="0.5-3"
PACKAGE="kafs-client"

function pod_to_man {
    action=$1
    section=$2
    this_pod="${3}.pod"
    this_man="${3}.$section"
    case $action in
        gen)
            pod2man --release=$VERSION \
                    --section $section \
                    --center=$PACKAGE \
		            $this_pod > $this_man
            ;;
        clean)
            if [ -e $this_man ]
            then
                rm -v $this_man
            fi
    esac
}

function display_usage {
    echo ""
    echo "Usage: AAA-MK-MAN [gen|clean]"
    echo ""
    echo "This script generates man pages for kafs-client from POD."
    exit 1
}

##############################################################################
# Main routine
##############################################################################

if [ "$1" = "" ]
then
    display_usage
fi

case $1 in
    gen | clean)
        pod_to_man $1 1 aklog-kafs
        pod_to_man $1 5 kafs-client.conf
        pod_to_man $1 7 kafs
        pod_to_man $1 7 rxrpc
        pod_to_man $1 8 kafs-preload
        pod_to_man $1 8 kafs-check-config
        pod_to_man $1 8 kafs-dns
        ;;
    *)
        echo "ERROR: unknown action $1"
        display_usage
        ;;
esac

exit

DOCS=<<__END_OF_DOCS__
=head1 NAME

AAA-MK-MAN - Generate kafs-client man pages

=head1 SYNOPSIS

AAA-MK-MAN gen|clean

=head1 DESCRIPTION

This generates the man pages for kafs-client from POD.  The script
hardcodes filenames.  While it can be used directly there probably 
better ways to do it as part of the package building process.

=head1 ARGUMENTS

=over 4

=item gen

Generate man pages from POD.

=item clean

Delete generated man pages.

=back

=head1 AUTHOR

Bill MacAllister <bill@ca-zephyr.org>

=head1 COPYRIGHT

Copyright (c) 2023 Bill MacAllister <bill@ca-zephyr.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

=cut
__END_OF_DOCS__
