#!/bin/bash
#
# remctl-ring-load -- wrapper for ring-load script
#
# Written by Bill MacAllister <bill@ca-zephyr.org>
# Copyright (c) 2024 Bill MacAllister <bill@ca-zephyr.org>

function help_em {
    echo "Usage: ring-load <action> <id> [<options>]"
    exit 1
}

if [ "$1" = "" ]
then
    echo "ERROR: action is required"
    help_em
fi
if [ "$2" = "" ]
then
    echo "ERROR: ring id is required"
    help_em
fi

RINGKEY="/etc/rings/service-ring-${2}.keytab"
if [ -e $RINGKEY ]
then
    RINGPREFIX="k5start -q -f $RINGKEY -U -t -- "
else
    echo "WARN: $RINGKEY not found"
fi

$RINGPREFIX ring-load $*

exit


##############################################################################
# Documentation
##############################################################################
DOCS=<<__END_OF_DOCS__

=head1 NAME

remctl-ring-load - Wrapper script for ring-load

=head1 SYNOPSIS

     remctl-ring-load <action> <id> [<options>]"

=head1 DESCRIPTION

This script is a wrapper for the ring-load script that provides
an AFS token if the keytab /etc/rings/service-<ring_id>.keytab
exists.

=head1 AUTHOR

Bill MacAllister <bill@ca-zephyr.org>

=head1 COPYRIGHT

Copyright 2024 CZ Software

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=cut
__END_OF_DOCS__
