#!/bin/sh

#   Copyright 2011 Red Hat, Inc.
#
#   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.

usage()
{
cat << EOF

USAGE:
aeolus-cleanup [-d|--debug] [-h|--help] [-v|--verbose]

OPTIONS:
   -h | --help       Show this message.
   -d | --debug      Debug logging mode.
   -v | --verbose    Verbose logging mode.
EOF
}

args=`getopt -o :hdv --long help,debug,verbose -- "$@"`
if test $? != 0
     then
         usage
         exit 1
fi

eval set -- $args
while true ; do
        case "$1" in
                -h|--help) usage ; exit 1 ;  shift ;;
                -d|--debug) LOGLEVEL="--debug" ; shift ;;
                -v|--verbose) LOGLEVEL="--verbose" ; shift  ;;
                --) shift ; break ;;
                *)  usage ; exit 1 ;;
        esac
done

PUPPET_NODE='cleanup'

export FACTER_AEOLUS_ENABLE_HTTPS=true
export FACTER_AEOLUS_ENABLE_SECURITY=false
puppet /usr/share/aeolus-configure/modules/aeolus/aeolus.pp \
       --modulepath=/usr/share/aeolus-configure/modules/ \
       --external_nodes "/bin/sh /usr/share/aeolus-configure/modules/aeolus/aeolus-node $PUPPET_NODE" --node_terminus exec \
       --logdest=/var/log/aeolus-configure/aeolus-cleanup.log \
       --logdest=console \
       $LOGLEVEL
