files eingespielt
authorarnold
Thu, 28 Apr 2005 14:28:04 +0000
changeset 1 2ee0eb0ef5d3
parent 0 2b7323a88cff
child 2 5b9ad097c060
files eingespielt
Makefile
config
send-config.pl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Thu Apr 28 14:28:04 2005 +0000
@@ -0,0 +1,15 @@
+# $Id$
+# $URL$
+
+ALL = send-config
+
+.PHONY:	all clean
+
+all:	$(ALL)
+clean:
+	-rm -f $(ALL)
+
+%:	%.pl
+	@perl -cT $<
+	@cp -f $< $@
+	@chmod a=rx $@
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config	Thu Apr 28 14:28:04 2005 +0000
@@ -0,0 +1,15 @@
+!*~
+!*kernel-source*
+!/usr/local/uvscan
+!/usr/local/src
+!/etc/samba/codepages
+!/etc
+!/usr/local
+!/var/cache/debconf
+!/var/lib/dpkg/status
+!/boot/config*
+!/usr/src/*/.config
+!/usr/src/*config*/
+!/root/LOG
+!/home/is/arnold
+/home/is/arnold/Test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/send-config.pl	Thu Apr 28 14:28:04 2005 +0000
@@ -0,0 +1,93 @@
+#! /usr/bin/perl -w
+# $Id$
+# $URL$
+
+my $USAGE = <<'_';
+Usage: $ME [options] host
+       host		destination host
+       -v --[no]verbose	be verbose [$opt_verbose]
+       -k --keepgoing	don't stop on errors [$opt_keepgoing]
+_
+
+use strict;
+use File::Basename;
+use Getopt::Long;
+use Net::SSH qw(sshopen2);
+use Sys::Hostname::Long;
+use Socket;
+
+my $ME = basename $0;
+my $CONFIG = "./config";
+
+my $opt_verbose = 0;
+my $opt_keepgoing = 0;
+
+MAIN: {
+    GetOptions(
+	"verbose!"  => \$opt_verbose,
+	"keepgoing" => \$opt_keepgoing,
+    ) or die eval "\"$USAGE\"";
+
+    unless (scalar(@ARGV) == 1) { die eval "\"$USAGE\""; }
+    
+    (my $host = $ARGV[0]) =~ s/.*\/([a-z0-9.-]+).*/$1/;
+    my $ip = scalar gethostbyname($host);
+    
+    $ip or do {
+	warn "can't resolve $host\n";
+	next;
+    };
+    my $addr = inet_ntoa($ip);
+    my $hostname_long = hostname_long();
+
+    my $user = "root";
+    my $path = "/root/Config/Hosts/$hostname_long";
+    my $ssh_cmd = "mkdir -m 0700 -p $path";
+    
+    sshopen2("$user\@$host", *READER, *WRITER, "$ssh_cmd") || die "ssh: $!";
+    close(READER); close(WRITER);
+
+    open(CONF, $CONFIG) or die "$ME: Can't open $CONFIG: $!\n";
+
+    my @cmd = (
+	qw(rsync --rsh),
+	"ssh -x",
+	qw(--compress --numeric-ids
+	   --delete --delete-excluded
+	   --archive --relative)
+    );
+    push @cmd, "--verbose" if $opt_verbose;
+    
+    # get exclusion list
+    while (<CONF>) {
+	chomp;
+	 /^!(.*)\s*/ or next;
+	 push @cmd, "--exclude", $1;
+    }
+    seek CONF, 0, 0 or die "$ME: Can't seek $CONFIG: $!\n";
+
+    while (<CONF>) {
+	chomp;
+	/^\// or next;
+	my $status = "";
+	my $src = "$_";
+	my $dst = "$user\@$host:$path";
+	print "* $src -> $dst$_\n";
+	system @cmd, $src, $dst;
+	if ($?) {
+	    $status = "ERR " . ($? >> 8);
+	    $status .= " SIGNAL " . ($? & 127);
+	} else { $status = "OK"; };
+
+	if ($status ne "OK") {
+	    warn "$ME: ???. system command ended with $status" unless $opt_keepgoing;
+	}
+    }
+
+    my $STAMP = "/var/tmp/get-config.stamp";
+    open(TOUCH, ">$STAMP") or die "$ME: Can't open >>$STAMP: $!\n";
+    close(TOUCH);
+
+}
+
+# vim:sts=4 sw=4 aw ai sm: