#!/bin/sh
## -------------------------------------------------------------------
##
## riak-cs-supercluster: Riak CS supercluster management
##
## Copyright (c) 2014 Basho Technologies, Inc.,
##               2021-2023 TI Tokyo.  All Rights Reserved.
##
## This file is provided to you 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.
##
## -------------------------------------------------------------------

SCRIPT="riak-cs-supercluster"
# if we are called as `riak admin`, PLATFORM_BASE_DIR will have been set
PLATFORM_BASE_DIR=/usr/lib64/riak-cs
PLATFORM_BASE_DIR=${PLATFORM_BASE_DIR:-$(cd $(dirname "$0")/.. && pwd -P)}

PLATFORM_BIN_DIR=/usr/lib64/riak-cs/bin
if [ "$PLATFORM_BIN_DIR" = "${PLATFORM_BIN_DIR#/}" ]; then
    PLATFORM_BIN_DIR=$PLATFORM_BASE_DIR/$PLATFORM_BIN_DIR
fi

PLATFORM_LIB_DIR=/usr/lib64/riak-cs/lib
if [ "$PLATFORM_LIB_DIR" = "${PLATFORM_LIB_DIR#/}" ]; then
    PLATFORM_LIB_DIR=$PLATFORM_BASE_DIR/$PLATFORM_LIB_DIR
fi
. $PLATFORM_LIB_DIR/lib.sh

export USE_NODETOOL=1  # {use_nodetool, true} is not clear enough

# Check the first argument for instructions
case "$1" in
    list-members|weight|weight-manifest|weight-block|refresh)
        rpc riak_cs_multibag_console "$@"
        ;;
    *)
        echo "Usage: $SCRIPT { list-members | weight | weight-manifest | weight-block | refresh }"
        exit 1
        ;;
esac
exit 0
