From: Anthony Towns Date: Mon, 5 Mar 2007 05:39:55 +0000 (+1000) Subject: Add ssh-move script, and use it to sync versioning info across to bugs.debian.org X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d9c9fe2f794caa47f3bf4b7626f2c84108bf50e;p=dak Add ssh-move script, and use it to sync versioning info across to bugs.debian.org --- diff --git a/config/debian/cron.unchecked b/config/debian/cron.unchecked index 04b06156..a98ff086 100644 --- a/config/debian/cron.unchecked +++ b/config/debian/cron.unchecked @@ -30,6 +30,9 @@ if lockfile -r3 $LOCKFILE; then dak process-unchecked -a $changes >> $report echo "--" >> $report + # sync with debbugs + $scriptsdir/ssh-move --server --ssh-identity /srv/ftp.debian.org/s3kr1t/id_debbugs-vt --ssh-move-path /home/debbugs/ssh-move --from-directory $queuedir/bts_version_track --to-directory /org/bugs.debian.org/versions/queue/ftp-master debbugs@bugs.debian.org \*.debinfo \*.versions + if lockfile -r3 $NOTICE; then LOCKDAILY="YES" psql projectb -A -t -q -c "SELECT filename FROM queue_build WHERE queue = 0 AND suite = 5 AND in_queue = true AND filename ~ 'd(sc|eb)$'" > $dbdir/dists/unstable_accepted.list diff --git a/scripts/debian/ssh-move b/scripts/debian/ssh-move new file mode 100755 index 00000000..ab820a7d --- /dev/null +++ b/scripts/debian/ssh-move @@ -0,0 +1,128 @@ +#! /usr/bin/perl -w +use strict; + +use IPC::Open2; + +$ENV{LANG} = "C"; + +# The protocol consists of repeated exchanges of the following: +# +# S: +# S: +# S: . +# C: [writes file] +# C: +# S: [unlinks file] + +my $server = 0; +my $verbose = 0; +my $nonint = 0; +my $sshidentity; +my $sshmovepath = 'ssh-move'; +my $fromdir; +my $todir; + +while (@ARGV) { + local $_ = shift @ARGV; + if (/^--server$/) { + $server = 1; + } elsif (/^--verbose$/) { + $verbose = 1; + } elsif (/^--ssh-identity$/) { + $sshidentity = shift @ARGV; + } elsif (/^--ssh-move-path$/) { + $sshmovepath = shift @ARGV; + } elsif (/^--from-directory$/) { + $fromdir = shift @ARGV; + } elsif (/^--to-directory$/) { + $todir = shift @ARGV; + } elsif (/^--non-interactive$/) { + $nonint = 1; + } else { + unshift @ARGV, $_; + last; + } +} + +local $| = 1; + + +my ($in, $out) = (*STDIN, *STDOUT); + +unless ($nonint) { + my $servername = shift @ARGV; + local (*READER, *WRITER); + + my @args = ('ssh'); + push @args, '-i', $sshidentity if defined $sshidentity; + + push @args, $servername, $sshmovepath; + push @args, '--server' unless ($server); + push @args, '--to-directory', $todir if (defined $todir && $server); + push @args, '--from-directory', $fromdir if (defined $fromdir && !$server); + push @args, '--non-interactive'; + push @args, map quotemeta, @ARGV unless ($server); + + my $pid = open2 (\*READER, \*WRITER, @args); + + ($in, $out) = (*READER, *WRITER); +} + +sub server () +{ + chdir $fromdir if defined $fromdir; + + my @files = map glob, @ARGV; + + for my $file (@files) { + print $out "$file\n" or die "can't print to client: $!"; + open FILE, "< $file" or die "can't open $file: $!\n"; + local $_; + while () { + chomp; + $_ = ".$_" if /^\./; + print $out "$_\n" or die "can't print to client: $!"; + } + print $out ".\n" or die "can't print to client: $!"; + + my $confirm = <$in>; + chomp $confirm if defined $confirm; + unlink $file if defined $confirm and $confirm eq $file; + } +} + +sub client () +{ + chdir $todir if defined $todir; + + my $file; + while (defined ($file = <$in>)) { + chomp $file; + print STDERR $file if $verbose; + (my $tmpfile = $file) =~ s[.*/][]; + $tmpfile .= ".$$.tmp"; + # TODO: unlink $tmpfile if things go wrong + open TMP, "> $tmpfile" or die "can't open $tmpfile: $!"; + local $_; + while (<$in>) { + chomp; + if ($_ eq '.') { + close TMP or die "can't close $tmpfile: $!"; + rename $tmpfile, $file + or die "can't rename $tmpfile to $file: $!"; + print $out "$file\n" or die "can't print to server: $!"; + last; + } else { + s/^\.//; + print TMP "$_\n" or die "can't print to $tmpfile: $!"; + } + } + print STDERR " ok\n" if $verbose; + } +} + +if ($server) { + server (); +} else { + client (); +}