#!/bin/sh

# copyright, licensing and documentation at the end

set -e
set -u

. "${DPT__SCRIPTS:-/usr/share/pkg-perl-tools}/lib/dpt-lib.sh"

[ -z "${1:-}" ] || die "No command line arguments supported"

USCAN="$(uscan --dehs|| true)"
if echo "$USCAN" | grep -q "<status>newer package available</status>"; then
    ORIG=$(echo "$USCAN" | grep "<target-path>"|sed -e's,</\?target-path>,,g')
    echo "Importing $ORIG"
    gbp import-orig "$ORIG"
fi

POD=<<'EOF'
=head1 NAME

dpt-uscan - a tiny wrapper around C<uscan> and C<gbp import-orig>

=head1 SYNOPSIS

B<dpt uscan>

=head1 DESCRIPTION

B<dpt uscan> calls L<uscan(1)> and then B<gbp import-orig>
if a newer upstream version was downloaded.

It is similar to L<dpt-import-orig(1)>, but without the upstream repository
integration.

Running B<dpt uscan> is equivalent to

 % uscan
 % gbp import-orig upstream-tarball

with the location of the newly downloaded tarball detected from uscan's
B<--dehs> output, and therefore is not hardcoded to F<../>, but depending on
uscan's configuration.

=head1 SEE ALSO

L<dpt-import-orig(1)>, L<uscan(1)>, L<devscripts.conf(5)>,
L<gbp-import-orig(1)>

=head1 COPYRIGHT & LICENSE

=over

=item Copyright 2017 Damyan Ivanov L<dam@debian.org>

=back

This program is free software, licensed under the same term as perl.

=cut
EOF
