#!/usr/bin/perl -w # # $Id: shovel.txt,v 1.1.1.1 2002/11/20 16:51:34 sklar Exp $ # ## This program comes with absolutely no warranty. ## Copyright 1998 David Sklar / Student.Net Publishing ## ## This program will use rdist over ssh to copy all the files in a module ## to one or more live webservers. ## ## For the ssh connection to work properly in batch mode, you should make ## sure that the authorized_keys file of each user listed in @hosts contains ## the public key of each user that may run this program. ## use strict; use POSIX qw(tmpnam); use Getopt::Long; my @hosts = qw( someuser@webserver1.example.com someuser@webserver2.example.com someuser@webserver3.example.com ); my %shovelers = ( 'larry' =>1, 'moe' => 1, 'curly' => 1 ); my $shoveler = getpwuid($<); my @tmp_files; my $tag; my $cvs_output; my $cvs = '/usr/bin/cvs'; my $module = 'example'; unless ($shovelers{$shoveler}) { print<<_EOM_; Sorry, $shoveler, you can not shovel content. Talk to the system administrator if you think this is incorrect. _EOM_ exit; } GetOptions( 'tag=s' => \$tag, 'module=s' => \$module ); if (! $tag) { usage("No tag!") && exit; } # make sure there's no nasty business in the tag unless ($tag =~ /^[A-Za-z0-9_\-]+$/) { usage("Illegal tag!") && exit; } # make sure there's no nasty business in the module unless ($module =~ /^[A-Za-z0-9_\-]+$/) { usage("Illegal module!") && exit; } # make temp dir for files to be shoveled my $tmp_dir = POSIX::tmpnam(); mkdir($tmp_dir,0777); push(@tmp_files,$tmp_dir); chdir($tmp_dir); # attempt to export with the tag $cvs_output = `$cvs export -r $tag $module 2>&1`; if ($cvs_output =~ /cvs [export aborted]: no such tag $tag/) { usage("Tag $tag doesn't exist"); clean_tmp(); exit; } # now use rdist to send the files open(RDIST,"|/usr/bin/rdist -f - -p /usr/sbin/rdistd -P /usr/bin/ssh") or die "Can't rdist: $!"; print RDIST<<_EOM_; HOSTS = ( @hosts ) FILES = ( $tmp_dir/* ) \${FILES} -> \${HOSTS} install /www; _EOM_ close(RDIST); clean_tmp(); sub usage { if ($_[0]) { print "Error: $_[0]\n\n"; } print<<_USAGE_; $0 --tag=TAG [--module=MODULE] Shovels the files tagged with tag TAG in module MODULE. MODULE is '$module' if not specified. _USAGE_ } sub clean_tmp() { foreach (@tmp_files) { system('/bin/rm','-rf',$_); } }