Package: dput
Version: 0.9.5.1
Severity: wishlist
Tags: patch

I am missing a transport for dput that is similar to scp, but allows
for the remote execution of commands after the transfer. The scp
transfer currently uses a separate ssh call to fix permissions,
which could be addressed with this transport.

E.g.:

  [mybuildd]
  method = sshpipetmp
  fqdn = buildd.debian.madduck.net
  receive_command = ~/bin/mybuildscript.sh %c

This would basically do the following:

  tar -chzf- $FILES_TO_COPY | \
    ssh $FQDN 'TEMPDIR=$(mktemp -td dput.XXXXXX); cd $TEMPDIR;
               tar -xzf-;
               $RECEIVE_COMMAND;
               cd /; rm -rf $TEMPDIR'

I have attached a working proof-of-concept (that can surely be
improved). In particular, it hijacks incoming because that seems to
be hardwired.

-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 2.6.32-trunk-686 (SMP w/1 CPU core)
Locale: LANG=en_GB, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages dput depends on:
ii  gnupg                         1.4.10-2   GNU privacy guard - a free PGP rep
ii  python                        2.5.4-9    An interactive high-level object-o

dput recommends no packages.

Versions of packages dput suggests:
ii  lintian                       2.3.1      Debian package checker
pn  mini-dinstall                 <none>     (no description available)
ii  openssh-client                1:5.3p1-1  secure shell (SSH) client, for sec
ii  rsync                         3.0.7-1    fast remote file copy program (lik
pn  yaclc                         <none>     (no description available)

-- no debconf information


-- 
 .''`.   martin f. krafft <[email protected]>      Related projects:
: :'  :  proud Debian developer               http://debiansystem.info
`. `'`   http://people.debian.org/~madduck    http://vcs-pkg.org
  `-  Debian - when you have better things to do than fixing systems
# -*- coding: utf-8 -*-
#
# Upload the files via tar+ssh pipe to a temporary location and execute
# a command (specified by incoming) in that directory.
#
# Copyright © 2010 martin f. krafft <[email protected]>
# Released under the terms of the artistic licence
#
import os,sys,subprocess

def upload(fqdn,login,receive_command,files_to_upload,debug,compress,
           ssh_config_options=[],progress=0):

    basedir = os.path.dirname(files_to_upload[0])
    files = []
    for i in files_to_upload:
        dirname, basename = os.path.dirname(i), os.path.basename(i)
        if dirname != basedir:
            print >>sys.stderr, "E: cannot upload files from more than one directory"
            sys.exit(1)
        files.append(basename)

        if basename.endswith('.changes'):
            changesfile = basename

    if not changesfile:
        print >>sys.stderr, "E: no .changes file in upload"
        sys.exit(1)

    compress = 'z' if compress else ''
    tar_cmd = ['tar', '-ch%sf-' % compress, '-C', basedir] + files
    if debug:
        print >>sys.stderr, 'D: running tar: ' + ' '.join(tar_cmd)

    tar = subprocess.Popen(tar_cmd, stdout=subprocess.PIPE, stderr=sys.stderr)

    ssh_cmd = ['ssh']
    for anopt in ssh_config_options:
        ssh_cmd += ['-o', anopt]

    login_spec = '%s@' % login if (login and login != '*') else ''
    ssh_cmd.append('%s%s' % (login_spec, fqdn))

    receive_command = receive_command.replace('$changesfile', changesfile)
    remote_commands = [  'TMPDIR="$(mktemp -td dput.XXXXXX)"'
                       , 'cd "$TMPDIR"'
                       , 'tar -x%sf-' % compress
                       , receive_command
                       , 'cd /'
                       , 'rm -rf "$TMPDIR"'
                      ]

    ssh_cmd.append("sh -c '" + ';'.join(remote_commands) + "'")
    if debug:
        print >>sys.stderr, 'D: running ssh: ' + ' '.join(ssh_cmd)

    ssh = subprocess.Popen(ssh_cmd, stdin=tar.stdout, stdout=sys.stdout,
                           stderr=sys.stderr)

    ssh.wait()
    tar.wait()

    return ssh.returncode

Attachment: digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/)

Reply via email to