#!/bin/sh

version="0.4"
license="# ${0} ${version} -- rename Debian packages to full package names
# Copyright (C) 1995 Erick Branderhorst <branderhorst@heel.fgg.eur.nl>.

# 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, or (at your option) any
# later version.

# This is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the file
# /usr/doc/copyright/GPL for more details."

usage="Usage: $0 file[s]
  Rename Debian packages to full package names.
  file.deb changes to <package>-<version>-<package_revision>.deb
  -h|--help|-V|--version|-L|--license  Show help/version/license"

case $# in
  1 )
    case "${1}" in
      --version|-V )
        echo "${0} version ${version}"; exit 0 ;;
      --license|-L )
        echo "$license"; exit 0 ;;
      --help|-h|--install|-i|--remove|-r )
        echo "$usage"; exit 0 ;;
    esac ;;
  0 )
    echo "Try $0 --help" >/dev/stderr; exit 1 ;;
esac ;

for name in "$@"; do
  if [ -e $name ]; then
    dpkgdeb=`dpkg-deb -f $name package version package_revision \
revision 2>/dev/null`
    if [ "$dpkgdeb" = "" -o -d $name ]; then
      echo "$name is not a Debian package" >/dev/stderr;
    else
      dpkgname=`echo $dpkgdeb|awk '{print $2 "-" $4 "-" $6 ".deb"}'`
      if [ $dpkgname = "$name" -o -f $dpkgname ]; then
	echo "Skipping $name" >/dev/stderr;
      else
        mv $name $dpkgname;
        echo "Renamed $name to $dpkgname" >/dev/stdout;
      fi
    fi
    else
      echo "File not found: $name" >/dev/stderr;
    fi
  done
exit 0 ;





