#!/bin/sh -e

. shell-quote

usage()
{
    cat <<EOF
usage: gear-cronbuild <gear invocation arguments>

gear-cronbuild is a shell wrapper for the sequence
gear-cronbuild-apply-hooks && gear <gear invocation arguments> && gear-commit
EOF
}

if [ x"$1" = x--help ]; then
    usage
    exit 0
fi

if [ $# -eq 0 ]; then
    echo "gear-cronbuild needs some arguments for gear."
    echo "usually it is --hasher -- <hsh-command>... "
    usage
    exit 1
fi

echo running gear-cronbuild-apply-hooks ...
gear-cronbuild-apply-hooks
echo "gear-cronbuild-apply-hooks update successful."

echo running gear "$@" ...
gear --commit "$@"

[ -n "\$(git status --porcelain -s -uno)" ] || {
echo unuse gear-commit
exit 0
}

commitmsg=
[ -x .gear/cronbuild-commitmsg ] && commitmsg=`.gear/cronbuild-commitmsg`
[ -n "$commitmsg" ] && commitmsg="\"$(quote_shell "$commitmsg")\""

echo running gear-commit ${commitmsg:+-m "$commitmsg"} ...
gear-commit ${commitmsg:+-m "$commitmsg"}

: <<'__EOF__'

=head1	NAME

gear-cronbuild

=head1	SYNOPSIS

B<gear-cronbuild> --- gear-cronbuild-apply-hooks && rebuild && commit

=head1	DESCRIPTION

B<gear-cronbuild> <gear invocation arguments>

gear-cronbuild is a shell wrapper for the sequence
gear-cronbuild-apply-hooks && gear <gear invocation arguments> && gear-commit

=head1	OPTIONS

<gear invocation arguments> -- any arguments you pass to gear.
 usually it is --hasher -- <hsh-command>...

=head1 SEE ALSO

http://www.altlinux.org/Gear/cronbuild

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	COPYING

Copyright (c) 2010-2020 Igor Vlasenko, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

=cut

__EOF__
