#!/bin/bash

# Run (or not) the two cron jobs based on the the values of
# the environment variables SHARED_LINK_ENABLED
# and CREATE_CAL_WG_ENABLED.
#
# Set either (or both) of these environment variables to any non-empty
# string to cause the respective script to be run. This flexibility is
# especially useful when testing the shared-email workflow.

echo "Starting shared-email-link-jobs"

if [[ ! -z "${SHARED_LINK_ENABLED}" ]]; then
    echo "running shared-email-link..."
    /usr/sbin/shared-email-link
    echo "...shared-email-link completed"
else
    echo "Skipping shared-email-link (SHARED_LINK_ENABLED not set)."
fi

if [[ ! -z "${CREATE_CAL_WG_ENABLED}" ]]; then
    echo "running shared-email-create-cal-wg..."
    /usr/sbin/shared-email-create-cal-wg
    echo "...shared-email-create-cal-wg completed"
else
    echo "Skipping shared-email-create-cal-wg (CREATE_CAL_WG_ENABLED not set)"
fi

echo "Ending shared-email-link-jobs"

exit 0

# Documentation.  Use a hack to hide this from the shell.  Because of the
# above exit line, this should never be executed.
DOCS=<<__END_OF_DOCS__

=head1 NAME

shared-email-link-jobs - Run the two shared-email linking jobs

=head1 SYNOPSIS

shared-email-link-jobs

=head1 DESCRIPTION

Run (or not) the two cron jobs based on the the values of the environment
variables C<SHARED_LINK_ENABLED> and
C<CREATE_CAL_WG_ENABLED>.

Set either (or both) of these environment variables to any non-empty
string to cause the respective script to be run. For example, the following
would run C<shared-email-link> but NOT run C<shared-email-create-cal-wg>:

    $ export SHARED_LINK_ENABLED=XXX
    $ export CREATE_CAL_WG_ENABLED=
    $ shared-email-link-jobs


=head1 OPTIONS

None.

=head1 EXIT STATUS

Returns C<0> on success, non-zero on any failure.

=head1 LICENSE AND COPYRIGHT

Copyright 2021 The Board of Trustees of the Leland Stanford Junior
University.  All rights reserved.

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of Stanford University not be used in
advertising or publicity pertaining to distribution of the software
without specific, written prior permission.  Stanford University makes no
representations about the suitability of this software for any purpose.
It is provided "as is" without express or implied warranty.

THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

=cut

__END_OF_DOCS__
