#!/bin/sh

# Copyright & License below

. "$DPT__SCRIPTS/lib/dpt-lib.sh"

DIR=$(mktemp -d)
trap "rm -rf '$DIR'" QUIT TERM EXIT

apt_get_source() {
    info "Trying apt-get source $PKG=$VER";
    ( cd "$DIR" && apt-get source -qq --download-only --tar-only "$PKG=$VER")
}

if ! apt_get_source ; then
    warn "Falling back to uscan"
    uscan --verbose --force-download --download-current-version \
        --rename --destdir="$DIR"
fi
pristine-tar commit "$DIR/${PKG}_${UVER}".orig* "upstream/$UVER"

exit 0

POD=<<'EOF'
=head1 NAME

dpt-missing-pristine-tar -- fix missing pristine-tar information

=head1 SYNOPSIS

B<dpt missing-pristine-tar>

=head1 DESCRIPTION

B<dpt missing-pristine-tar> fixes missing L<pristine-tar(1)> information by
downloading and importing upstream sources.

The download first tries L<apt-get source|apt-get(1)> and if that fails,
falls back to L<uscan(1)>.

=head1 COPYRIGHT & LICENSE

Copyright 2011 gregor herrmann <gregoa@debian.org>
          2022 Damyan Ivanov <dmn@debian.org>

License: Artistic | GPL-1+

=cut
EOF
