#!/bin/bash

if [ -z "$SERVICE_DATASTORE" ]; then
    echo "This script is meant to be run through 'compose' to work properly." >&2
    exit 1
fi

. /etc/shlib

include parse
include pretty

. $CHARM_PATH/lib/common

usage="
  $exname [-h|--help]
  $exname create MAIN_DOMAIN [DOMAINS..]
  $exname renew
"

if [ "$#" == 0 ]; then
    err "Please specify an action"
    print_usage
    exit 1
fi

while [ "$1" ]; do
    case "$1" in
        "--help"|"-h")
            print_usage
            exit 0
            ;;
        renew)
            exname="$exname $1"
            shift
            crt_renew "$@"
            exit $?
            ;;
        create)
            exname="$exname $1"
            shift
            crt_create "$@"
            exit $?
            ;;
        *)
            err "Wrong argument"
            print_usage
            exit 1
            ;;
    esac
    shift
done