Package: devscripts
Version: 2.10.46
Severity: wishlist
Tags: patch

Howdy,

In tuning my packaging workflow, I wanted an automated tool for
querying the Debian archive for the latest available version of the
current package, and emitting the version string.

Please find attached ‘dlatest’, a shell program that makes use of
‘parsechangelog’ and ‘rmadison’ to do this job. It has full option
parsing and a standard help message, but currently no manpage.

I hope this can be included in the ‘devscripts’ package.

-- 
 \     “I must have a prodigious quantity of mind; it takes me as much |
  `\   as a week sometimes to make it up.” —Mark Twain, _The Innocents |
_o__)                                                          Abroad_ |
Ben Finney <b...@benfinney.id.au>
#! /bin/bash
# -*- coding: utf-8 -*-
#
# dlatest – Get the latest version number of a Debian package
#
# Copyright © 2009 Ben Finney <ben+deb...@benfinney.id.au>
#
# This is free software: you may copy, modify, and/or distribute this work
# under the terms of the GNU General Public License, version 2 or later
# as published by the Free Software Foundation.
# No warranty expressed or implied. See the GNU GPL for details.

set -o errexit

progname=$(basename "$0")

function usage_exit() {
    exit_status=1
    if [ $# > 0 ] ; then
        exit_status=$1
    fi
    echo >&2 "Usage: $progname [options]
Query the Debian archive for the latest available version of the package.

Read the latest entry in the specified changelog to get the package
name and suite name, then query the online “madison” service to
determine the latest available version of the package in that suite.
If found, output the version string for that package.

Options:
-h, --help
    Show this usage message, then quit.
-f, --file=CHANGELOG
    Read the changelog named CHANGELOG (default: ‘debian/changelog’).
"
    exit $exit_status
}

changelog_file=debian/changelog

OPTS=$(getopt --name $progname \
    --options hf: --longoptions help,file: -- "$@" \
    ) || usage_exit
eval set -- "$OPTS"
while true ; do
    case "$1" in
        -h|--help)
            usage_exit 0
            shift
            ;;
        -f|--file)
            changelog_file=$2
            shift
            ;;
        --)
            shift
            break
            ;;
        *)
            usage_exit
            ;;
    esac
    shift
done

if [ ! -r ${changelog_file} ] ; then
    echo >&2 "$progname: Can't read changelog file: ${changelog_file}"
    exit 1
fi

packagename=$(parsechangelog --count 1 --file ${changelog_file} \
    | grep '^Source:' | cut -d' ' -f 2)
suitename=$(parsechangelog --count 1 --file ${changelog_file} \
    | grep '^Distribution:' | cut -d' ' -f 2)
latest_debian_version=$(rmadison --suite ${suitename} ${packagename} \
    | cut -d'|' -f 2 | sed -e 's/^[[:space:]]\+//')

echo "${latest_debian_version}"

Attachment: signature.asc
Description: Digital signature

Reply via email to