new dpkg-name and proposal
Hi Ian and other developers,
(Ian: please include this script and manpage in the next dpkg release).
I modified dpkg-name a little (again) because the one included in dpkg
version 1.1.6 is broken. The functionality is best explained by the
(appended) man page and the on-line help:
Usage: dpkg-name file[s]
rename Debian packages to full package names
file.deb changes to <package>-<version>.<architecture>.deb
-a|--no-architecture No architecture part in filename
-o|--overwrite Overwrite if file exists
-s|--subdir Move file into subdir (Use with care)
-c|--create-dir Create target dir if not there (Use with care)
-h|--help|-v|--version|-l|--license Show help/version/license
A (IMO) very usefull way to use dpkg-name is to name your packages in
the format required to upload them to master. If this format changes
(like adding architecture, or dropping architecture, hyphen ->
under_scores, or underscores to hyphens) you shouldn't need to change
your debian.rules.
debian.rules contains:
dpkg --build debian-tmp
dpkg-name debian-tmp.deb && mv *.deb ..
rm -rf debian-tmp
I hope the extension won't change otherwise this trick doesn't work.
ATTENTION: This is not a change of rules or whatever, it's just a
suggestion how we might deal with this easier then we did
before. Please comment on this proposal.
Erick
dpkg-name:
#!/bin/sh
set -e
# Time-stamp: <96/05/07 14:33:24 root>
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
-a|--no-architecture No architecture part in filename
-o|--overwrite Overwrite if file exists
-s|--subdir Move file into subdir (Use with care)
-c|--create-dir Create target dir if not there (Use with care)
-h|--help|-v|--version|-l|--license Show help/version/license"
}
fileexists () {
if [ -f "$1" ];
then
return 0;
else
stderr "can't find \`"$1"'";
return 1;
fi
}
getname () {
if p=`dpkg-deb -f -- "$1" package`;
then
p=`echo $p|sed -e 's/-/_/g'`;
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`;
a=`echo $a|sed -e 's/ *//g'`;
if [ -z "$a" ]; # architecture field empty
then
a=`dpkg --print-architecture`;
stderr "assuming architecture \`"$a"' for \`"`basename "$1"`"'";
fi
if [ -z "$noarchitecture" ];
then
tname=$p-$v.$a.deb;
else
tname=$p-$v.deb
fi
name=`echo $tname|sed -e 's/ //g'`
if [ "$tname" != "$name" ]; # control fields have spaces
then
stderr "bad package control information for \`"`basename "$1"`"'"
fi
return 0;
fi
}
getdir () {
dir=`dirname "$1"`;
if [ -n "$subdir" ];
then
s=`dpkg-deb -f -- "$1" section`;
if [ -z "$s" ];
then
stderr "empty section field, try to guess it from filename";
s=`echo $1|sed -e 's/.*\/binary.*\/\([a-z]*[0-9]*\)\/[^\/]*\.deb/\1/'`;
stderr "assuming section \`"$s"' for \`"`basename "$1"`"'";
fi
s=`echo $s|sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`;
if [ "$s" = "non-free" -o "$s" = "contrib" ];
then
dir=`echo $s/binary-$a`;
elif [ -z "$s" ];
then
dir=`dirname "$1"`;
stderr "can't move accros subdirs";
else
dir=`echo unstable/binary-$a/$s`;
fi
fi
}
move () {
if fileexists "$arg";
then
getname "$arg";
getdir "$arg";
if [ ! -d "$dir" ];
then
if [ -n "$createdir" ];
then
if `mkdir -p $dir`;
then
stderr "created directory \`$dir'";
else
stderr "failed creating directory \`$dir'";
exit 1;
fi
else
stderr "no such dir \`$dir'";
stderr "try dpkg-name -c and invoke it from debian base directory";
exit 1;
fi
fi
newname=`echo $dir/$name`;
if [ $newname -ef "$1" ]; # same device and inode numbers
then
stderr "skipping \`"$1"'";
elif [ -f $newname -a -z "$overwrite" ];
then
stderr "can't move \`"`basename "$1"`"' to existing file";
elif `mv -- "$1" $newname`;
then
echo "moved \``basename "$1"`' to \`$newname'";
else
stderr "mkdir can be used to create directory";
exit 1;
fi
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;;
--create-dir|-c) createdir=1;;
--subdir|-s) subdir=1;;
--overwrite|-o) overwrite=1 ;;
--no-architecture|-a) noarchitecture=1 ;;
--) shift;
for arg
do
move "$arg";
done; exit 0;;
*) move "$arg";;
esac
done
exit 0;
# Local variables:
# tab-width: 2
# End:
dpkg-name.1:
.\" This is an -*- nroff -*- source file.
.\" dpkg-name and this manpage are Copyright 1995,1996 by Erick Branderhorst.
.\"
.\" This is free software; see the GNU General Public Licence version 2
.\" or later for copying conditions. There is NO warranty.
.\" Time-stamp: <96/05/07 11:10:16 root>
.TH dpkg-name 1 "April 1996" "Debian Project" "Debian Linux"
.SH NAME
dpkg\-name \- rename Debian packages to full package names
.SH SYNOPSIS
.B dpkg\-name
[\-a|\-\-no\-architecture] [\-o|\-\-overwrite] [\-s|\-\-subdir]
[\-c|\-\-create\-dir] [\-h|\-\-help] [\-v|\-\-version]
[\-l|\-\-license] [\-[--] [files]
.SH DESCRIPTION
.PP
This manual page documents the
.B dpkg\-name
sh script which provides an easy way to rename
.B Debian
packages into their full package names. A full package name consists
of <package>-<version>.<architecture>.deb as specified in the control
file of the package. The <package> part of the filename will have
hyphens "-" replaced by underscores "_". The <version> part of the
filename consists of the mainstream version information optionally
followed by a hyphen and the revision information.
.SH EXAMPLES
.TP
.B dpkg-name bar-foo.deb
The file `bar-foo.deb' will be renamed to bar_foo-1.0-2.i386.deb or
something similar (depending on whatever information is in the control
part of `bar-foo.deb').
.TP
.B find /root/debian/ \-name '*.deb' | xargs \-n 1 dpkg\-name -a
All files with the extension `deb' in the directory /root/debian and its
subdirectory's will be renamed by dpkg\-name if required into names with no
architecture information.
.TP
.B find -name '*.deb' | xargs \-n 1 dpkg-name -a -o -s -c
.B Don't do this.
Your archive will be messed up completely because a lot of packages
don't come with section information.
.B Don't do this.
.SS OPTIONS
.TP
.B "\-a, \-\-no\-architecture"
The destination filename will not have the architecture information.
.TP
.B "\-o, \-\-overwrite"
Existing files will be overwritten if they have the same name as the
destination filename.
.TP
.B "\-s, \-\-subdir"
Files will be moved into subdir. The name of the target directory is
extracted from the section field in the control part of the
package. The target directory will be
`developement/binary\-<architecture>/<section>'. If the section is
`non\-free', `contrib' the target directory is
`<section>/binary\-<architecture>'. If no section information is
found, dpkg\-name will try to extract the section from the
filename. If that fails the package can be renamed but not moved from
the current directory.
.TP
.B "\-c, \-\-create\-dir"
This option can used together with the \-s option. If a target
directory isn't found it will be created automatically.
.B Use this option with care.
.TP
.B "\-h, \-\-help"
Print a usage message and exit successfully.
.TP
.B "\-v, \-\-version"
Print version information and exit successfully.
.TP
.B "\-l, \-\-license"
Print copyright information and (a reference to the GNU) license
information and exit successfully.
.SH BUGS?
Successfully tested on
.B Debian Linux
systems only. Some packages don't follow the name structure
<package>\-<version>.<architecture>.deb. Packages renamed by dpkg\-name
will follow this structure. Generally this will have no impact on how
packages are installed by dselect/dpkg.
.SH SEE ALSO
.BR deb (5),
.BR deb-control (5),
.BR dpkg (5),
.BR dpkg (8),
.BR dpkg-deb (8).
.SH COPYRIGHT
Copyright 1995,1996 Erick Branderhorst.
.B dpkg-name
is free software; see the GNU General Public Licence version 2 or
later for copying conditions. There is
.B no
warranty.
Reply to: