[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

another dpkg-name



Another dpkg-name update


#!/bin/sh

set -e

prog="`basename \"${0}\"`"
version="1.1.6"; # This line modified by Makefile
purpose="rename Debian packages to full package names"

license () {
echo "# ${prog} ${version} -- ${purpose}
# Copyright (C) 1995,1996 Erick Branderhorst <branderh@debian.org>.

# 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."
}

stderr () {
	echo "${prog}: $@" >/dev/stderr;
}

show_version () {
	echo "${prog} version ${version} -- ${purpose}";
}

usage () {
	echo "Usage: ${prog} file[s]
  ${purpose}
  file.deb changes to <package>-<version>.<architecture>.deb
  -h|--help|-v|--version|-l|--license  Show help/version/license"
}

rename () {
	if [ -f "$1" ];
	then
		if p=`dpkg-deb -f -- "$1" package`;
		then
			p=`echo $p|tr -s -- '- ' '_'`;
			v=`dpkg-deb -f -- "$1" version`;

			r=`dpkg-deb -f -- "$1" revision`;
			if [ -z "$r" ];
			then
				r=`dpkg-deb -f -- "$1" package_revision`;
			fi
			if [ -n "$r" ];
			then
				v=$v-$r;
			fi

			a=`dpkg-deb -f -- "$1" architecture`;
			if [ -z "$a" ]; # architecture field empty
			then
				a=`dpkg --print-architecture`;
				stderr "assuming "$a" architecture for \`"$1"'";
			fi				

			p=`dirname "$1"`"/"$p"-"$v.$a.deb
			np=`echo $p|sed -e 's/ //g'`
			if [ "$p" != "$np" ]; # control fields have spaces 
			then
                          stderr "bad package control information for \`"$1"'"
			fi

			if [ $np -ef "$1" ]; # same device and inode numbers
			then
				stderr "skipping \`"$1"'";
			elif [ -f $np ];
			then
				stderr "can't move \`"$1"' to existing file";
			elif `mv -- "$1" $np`;
			then
				echo "moved \``basename "$1"`' to \`${np}'";
			else
				stderr "hmm you found a dpkg-name bug?";
			fi
		fi
	else
		stderr "can't deal with \`"$1"'";
  fi
}

if [ $# = 0 ]; then usage; exit 0; fi	
for arg
do
	case "$arg" in
		--version|-v) show_version; exit 0;;
		--help|-[h?]) usage; exit 0;;
		--licen[cs]e|-l) license; exit 0;;
		--) shift; 
			for arg 
			do 
				rename "$arg"; 
			done; exit 0;;
		*) rename "$arg";;
	esac
done
exit 0;

# Local variables:
# tab-width: 2
# End:
--
Erick Branderhorst@heel.fgg.eur.nl +31-10-4635142
Department of General Surgery (Intensive Care) University Hospital Rotterdam NL
--
Erick Branderhorst@heel.fgg.eur.nl +31-10-4635142
Department of General Surgery (Intensive Care) University Hospital Rotterdam NL


Reply to: