#!/bin/bash
# -------------------------------------------------------------------
# File: remctl-ldap-dump
# Author: Bill MacAllister <bill@ca-zephyr.org>
# Copyright (c) 2020, Dropbox, Inc.
# Copyright (C) 2023 CZ Software
# Description: dump either the cn=config or data branch
#              of an ldap directory.

##############################################################################
# Subroutine
##############################################################################

function display_usage {
    echo "ldap-dump db|config|manual [help|manual]"
    exit 1
}

##############################################################################
# Main Routine
##############################################################################

shift

case $1 in
    db)
        script='ldap-dump-db'
        ;;
    config)
        script='ldap-dump-config'
        ;;
    manual)
        pod2text $0
        exit 1
        ;;
    *)
        display_usage
        ;;
esac

$script /var/tmp

exit

DOCS=<<__END_OF_DOCS__
=head1 NAME

remctl-ldap-dump - Dump LDAP data or configuration to LDIF

=head1 SYNOPSIS

remctl-ldap-dump db|config|manual [help|manual]

=head1 DESCRIPTION

This is a wrapper script around the ldap-dump-db and ldap-dump-config
scripts to allow the scripts to be invoked using remctl.

=head1 OPTIONS

=over 4

=item db [help|manual]

Perform operations on the LDAP database. If help or manual is
specified then usage or a man page is displayed and the script
exits. Otherwide a dump the data of the directory is created.

=item config [help|manual]

Perform operations on the LDAP configuration. If help or manual is
specified then usage or a man page is displayed and the script
exits. Otherwide a dump the cn=config branch of the directory is
created.

=item help

A short help message.

=item manual

This documentation.

=item files

Use the /etc/ldap/slapd.conf configuration file.

=item config

Use the cn=config data base at /etc/ldap/slapd.d.

=back

=head1 EXAMPLES

To load the LDAP database from the /tmp directory:

    ldap-load-db

To load the LDAP database using the cn=config configuration file
from the /var/tmp directory.

    ldap-load-db config /var/tmp

=head1 AUTHOR

Bill MacAllister <whm@dropbox.com>

=head1 COPYRIGHT

Copyright (C) 2015-2020, Dropbox Inc.
Copyright (C) 2023 CZ Software

This code is free software; you can redistribute it and/or modify it
under the same terms as Perl. For more details, see the full
text of the at https://opensource.org/licenses/Artistic-2.0.

This program is distributed in the hope that it will be
useful, but without any warranty; without even the implied
warranty of merchantability or fitness for a particular purpose.

=cut
__END_OF_DOCS__
