Convert a mixed upload .changes file to source-only for upload

Asked by Philip Ashmore

I've got a build system that outputs a mixed (source+binary) .changes file.
Since it includes everything in a source-only .changes file, is there a utility that can read a mixed .changes file and output a source-only .changes file?

Question information

Language:
English Edit question
Status:
Solved
For:
Launchpad itself Edit question
Assignee:
No assignee Edit question
Solved by:
Philip Ashmore
Solved:
Last query:
Last reply:
Revision history for this message
William Grant (wgrant) said :
#1

I don't believe there's a utility to do it, but it's possible to trim it manually and resign.

However, you really want to fix the build system. It's probably just a matter of finding the 'debuild' call and adding the -S option.

Revision history for this message
Philip Ashmore (contact-philipashmore) said :
#2

Thanks for your input!

Some comments:

1. The build system isn't "broken" - if you're submitting a project you would most likely want to install it
    somewhere, even if only to check that it installs and uninstalls correctly.
    So the build system builds source and binary packages.
2. Some of my projects won't build without dependent packages being installed - and some of the
    dependent packages are created by other projects the built and installed by me - using the build system.
3. Editing the .changes file will invalidate any embedded signature it has, so you really need another .changes
    file to sign

Here's a script to do it.
I've delimited it with EOF, like you do in shell scripting, so it creates the "dput-c2sc" (changes -> source changes) script.
Please let me know if you spot any problems with it.

I'll let the dput maintainers know about it in case they'd like to include it with the dput package.

cat > dput-c2sc <<EOF
#!/bin/sh
set -e

eecho()
{
 echo "$1" 1>&2
}
Usage()
{
 eecho "Usage: dput-c2sc <some-package.changes> > <some-package-source-only.changes>"
 exit 1
}
# Verify it's a real .changes file.
if test "$1" = "" || test ! -f $1; then
 eecho "Error: \"$1\" : file not found."
 Usage
fi
package="$(cat "$1" | grep '^Source: ' | sed -e 's| |\n|g' | tail -n 1)"
if test "$package" = ""; then
 eecho "Error: package name not found in .changes file."
 eecho "\tIs is really a changes file?"
 Usage
fi
if test "" = "$(echo "$1" | grep "^$package")"; then
 eecho "Error: .changes file name doesn't start with package name."
 Usage
fi

if test "" != "$(cat "$1" | head -n 1 | grep "^-----BEGIN")"; then
 # Strip the signature from top and bottom.
 res="$(cat "$1" | grep -v '.deb$' | grep -v '^Binary:' | grep -v "^ $package-" | sed -re 's|^Architecture: .+$|Architecture: source|g' | head -n -8)"
 lc="$(echo "$res" | wc -l - | sed -e 's| |\n|g' | head -n 1)"
 lc="$(($lc - 3))"
 echo "$res" | tail -n $lc
else
 cat "$1" | grep -v '.deb$' | grep -v '^Binary:' | grep -v "^ $package-" | sed -re 's|^Architecture: .+$|Architecture: source|g'
fi
EOF

Revision history for this message
Max Bowsher (maxb) said :
#3

Re 1.: You could consider making the build system execute (debuild -S; debuild -b) then, to build source and binary packages in separate executions with separate .changes files

Re 3.: The command 'debsign --re-sign foo.changes' will strip any existing valid or invalid signature from foo.changes and re-sign it.

Revision history for this message
Philip Ashmore (contact-philipashmore) said :
#4

My build system creates Debian/Ubuntu packages from the package source .tar.gz.
I used this and the .debian.tar.gz to create the _source.changes file.

I've updated the dput-c2sc script - the one that inputs a mixed changes file and outputs a source-only changes file.
Its output compares identical to the one created above.

Here it is <<EOF
#!/bin/sh
set -e

eecho()
{
 echo "$1" 1>&2
}
Usage()
{
 eecho "Usage: dput-c2sc <some-package.changes> > <some-package-source-only.changes>"
 exit 1
}
# Verify it's a real .changes file.
if test "$1" = "" || test ! -f $1; then
 eecho "Error: \"$1\" : file not found."
 Usage
fi
package="$(cat "$1" | grep '^Source: ' | sed -e 's| |\n|g' | tail -n 1)"
if test "$package" = ""; then
 eecho "Error: package name not found in .changes file."
 eecho "\tIs is really a changes file?"
 Usage
fi
if test "" = "$(echo "$1" | grep "^$package")"; then
 eecho "Error: .changes file name doesn't start with package name."
 Usage
fi

if test "" != "$(cat "$1" | head -n 1 | grep "^-----BEGIN")"; then
 # Strip the signature from top and bottom.
 res="$(cat "$1" | grep -v '.deb$' | sed -re 's|^Architecture: .+$|Architecture: source|g' | head -n -8)"
 lc="$(echo "$res" | wc -l - | sed -e 's| |\n|g' | head -n 1)"
 lc="$(($lc - 3))"
 echo "$res" | tail -n $lc
else
 cat "$1" | grep -v '.deb$' | sed -re 's|^Architecture: .+$|Architecture: source|g'
fi
EOF