# HG changeset patch # User Matthias Förste foerste@schlittermann.de # Date 1335777531 -7200 # Node ID 7b4903ebdee83a56f271d941d78bdcc406d12cb1 # Parent 71d654155a56e7db3d7b8974b3f2b4110554a2f0 rename wgnd-mkstruct to wgnd-watch because the latter is more generic which may be neccessary later diff -r 71d654155a56 -r 7b4903ebdee8 .hgignore --- a/.hgignore Mon Apr 30 11:01:27 2012 +0200 +++ b/.hgignore Mon Apr 30 11:18:51 2012 +0200 @@ -1,5 +1,5 @@ syntax: re -^wgnd-mkstruct -^wgnd-mkstruct.map.pl +^wgnd-watch +^wgnd-watch.map.pl ^debian/files$ -^debian/wgnd-mkstruct[./] +^debian/wgnd-watch[./] diff -r 71d654155a56 -r 7b4903ebdee8 Makefile --- a/Makefile Mon Apr 30 11:01:27 2012 +0200 +++ b/Makefile Mon Apr 30 11:18:51 2012 +0200 @@ -2,7 +2,7 @@ prefix?=/usr/local sbindir = $(prefix)/sbin -scripts = wgnd-mkstruct +scripts = wgnd-watch %: %.pl cp -a $< $@ @@ -11,7 +11,7 @@ install: all install -m 0755 -d $(DESTDIR)$(sbindir) - install -m 0755 wgnd-mkstruct $(DESTDIR)$(sbindir) + install -m 0755 wgnd-watch $(DESTDIR)$(sbindir) clean: -rm -f $(scripts) diff -r 71d654155a56 -r 7b4903ebdee8 debian/changelog --- a/debian/changelog Mon Apr 30 11:01:27 2012 +0200 +++ b/debian/changelog Mon Apr 30 11:18:51 2012 +0200 @@ -1,4 +1,4 @@ -wgnd-mkstruct (0.1) unstable; urgency=low +wgnd-watch (0.1) unstable; urgency=low * Initial Release. diff -r 71d654155a56 -r 7b4903ebdee8 debian/control --- a/debian/control Mon Apr 30 11:01:27 2012 +0200 +++ b/debian/control Mon Apr 30 11:18:51 2012 +0200 @@ -1,16 +1,14 @@ -Source: wgnd-mkstruct +Source: wgnd-watch Section: misc Priority: extra Maintainer: Matthias Förste Build-Depends: debhelper (>= 7.0.50~) Standards-Version: 3.8.4 -Homepage: https://ssl.schlittermann.de/hg/ius/wgnd-mkstruct -#Vcs-hg: https://ssl.schlittermann.de/hg/ius/wgnd-mkstruct -#Vcs-Browser: https://ssl.schlittermann.de/hg/ius/wgnd-mkstruct +Homepage: https://ssl.schlittermann.de/hg/ius/wgnd-watch +#Vcs-hg: https://ssl.schlittermann.de/hg/ius/wgnd-watch +#Vcs-Browser: https://ssl.schlittermann.de/hg/ius/wgnd-watch -Package: wgnd-mkstruct +Package: wgnd-watch Architecture: all Depends: ${misc:Depends}, ${perl:Depends}, liblinux-inotify2-perl, rsync -Description: instantiate a directory structure template - wgnd-mkstruct watches some directories for newly created subdirectories and - synchronises these from a given template directory. +Description: inotify actions for wiegand diff -r 71d654155a56 -r 7b4903ebdee8 debian/copyright --- a/debian/copyright Mon Apr 30 11:01:27 2012 +0200 +++ b/debian/copyright Mon Apr 30 11:18:51 2012 +0200 @@ -4,7 +4,7 @@ It was downloaded from: - https://ssl.schlittermann.de/hg/ius/wgnd-mkstruct + https://ssl.schlittermann.de/hg/ius/wgnd-watch Upstream Author(s): diff -r 71d654155a56 -r 7b4903ebdee8 wgnd-mkstruct.map.pl.ex --- a/wgnd-mkstruct.map.pl.ex Mon Apr 30 11:01:27 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -our $source = { - '/tmp' => './' -}; diff -r 71d654155a56 -r 7b4903ebdee8 wgnd-mkstruct.pl --- a/wgnd-mkstruct.pl Mon Apr 30 11:01:27 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ -#!/usr/bin/perl - -# Copyright (C) 2012 Matthias Förste -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# Matthias Förste - -=encoding utf8 -=cut - -use strict; -use warnings; - -my $VERSION = '0.1'; -my $ME = $0; -use Getopt::Long; -use Pod::Usage; -use Linux::Inotify2; -# File::Rsync in squeeze does not support --xattrs yet -#use File::Rsync; - -my $map = 'wgnd-mkstruct.map.pl'; - -BEGIN { - - use Sys::Syslog; - openlog($ME, 'ndelay,nowait,pid', 'LOG_USER'); - $SIG{__WARN__} = sub { - warn @_ if not defined $^S; - print STDERR "@_"; - syslog('warning', "@_"); - }; - $SIG{__DIE__} = sub { - die @_ if not defined $^S; - print STDERR "@_"; - syslog('err', "@_"); - exit $?; - }; - - sub dolog { print "@_"; syslog('info', "@_"); } - sub trace { print @_ if $ENV{DEBUG}; } - -} - -GetOptions( - "map=s" => \$map, - "h|help" => sub { pod2usage( -verbose => 0, -exitval => 0 ) }, - "m|man" => sub { - pod2usage( - -verbose => 2, - -exitval => 0, - -noperldoc => ( `perldoc -V 2>/dev/null`, $? != 0 )[-1] - ); - }, -) or pod2usage(); - -our $source; -use lib ('.', $ENV{HOME}, '/etc'); -require $map; - -my $inotify = new Linux::Inotify2 - or die "Can't create new inotify object: $!"; -my @rsync = qw(/usr/bin/rsync -ihv -aAX); - -for (keys %{$source}) { - - # add watchers - $inotify->watch ("$_", IN_CREATE, sub { - - my $pid = fork; - - if (not defined $pid) { - warn "Can't fork: $!\n"; - } elsif ($pid == 0) { - my $e = shift; - my $name = $e->fullname; - dolog "$name was created\n" if $e->IN_CREATE; - dolog "$name is no longer mounted\n" if $e->IN_UNMOUNT; - dolog "$name is gone\n" if $e->IN_IGNORED; - dolog "events for $name have been lost\n" if $e->IN_Q_OVERFLOW; - exec @rsync, $source->{$e->{w}->{name}}, $name; - warn "Can't exec: $!\n"; - } - - }) or die "Can't add watch: $!\n"; -} - -while (1) { - - $inotify->poll; - while (-1 != (my $pid = wait)) { - my $e = $? >> 8; - dolog "child ${ME}[$pid]: exit $e\n"; - } - -} - -END { - closelog; -} - -__END__ - -=pod - -=head1 NAME - -wgnd-mkstruct - instantiate a directory structure template - -=head1 SYNOPSIS - -wgnd-mkstruct [--map filename] - -wgnd-mkstruct -m|--man - -h|--help - -=head1 DESCRIPTION - -wgnd-mkstruct watches some directories for newly created subdirectories and -synchronises these from a given template directory. - -=head1 OPTIONS - -=over - -=item B<--map> I - -Name of a file containing mappings between templates and directories. Defaults -to F. - -=back - -=head1 FILES - -=over - -=item F - -default for B<--map> - -=back - -=head1 AUTHOR - -Matthias Förste - -=cut diff -r 71d654155a56 -r 7b4903ebdee8 wgnd-watch.map.pl.ex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wgnd-watch.map.pl.ex Mon Apr 30 11:18:51 2012 +0200 @@ -0,0 +1,3 @@ +our $source = { + '/tmp' => './' +}; diff -r 71d654155a56 -r 7b4903ebdee8 wgnd-watch.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wgnd-watch.pl Mon Apr 30 11:18:51 2012 +0200 @@ -0,0 +1,159 @@ +#!/usr/bin/perl + +# Copyright (C) 2012 Matthias Förste +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Matthias Förste + +=encoding utf8 +=cut + +use strict; +use warnings; + +my $VERSION = '0.1'; +my $ME = $0; +use Getopt::Long; +use Pod::Usage; +use Linux::Inotify2; +# File::Rsync in squeeze does not support --xattrs yet +#use File::Rsync; + +my $map = 'wgnd-watch.map.pl'; + +BEGIN { + + use Sys::Syslog; + openlog($ME, 'ndelay,nowait,pid', 'LOG_USER'); + $SIG{__WARN__} = sub { + warn @_ if not defined $^S; + print STDERR "@_"; + syslog('warning', "@_"); + }; + $SIG{__DIE__} = sub { + die @_ if not defined $^S; + print STDERR "@_"; + syslog('err', "@_"); + exit $?; + }; + + sub dolog { print "@_"; syslog('info', "@_"); } + sub trace { print @_ if $ENV{DEBUG}; } + +} + +GetOptions( + "map=s" => \$map, + "h|help" => sub { pod2usage( -verbose => 0, -exitval => 0 ) }, + "m|man" => sub { + pod2usage( + -verbose => 2, + -exitval => 0, + -noperldoc => ( `perldoc -V 2>/dev/null`, $? != 0 )[-1] + ); + }, +) or pod2usage(); + +our $source; +use lib ('.', $ENV{HOME}, '/etc'); +require $map; + +my $inotify = new Linux::Inotify2 + or die "Can't create new inotify object: $!"; +my @rsync = qw(/usr/bin/rsync -ihv -aAX); + +for (keys %{$source}) { + + # add watchers + $inotify->watch ("$_", IN_CREATE, sub { + + my $pid = fork; + + if (not defined $pid) { + warn "Can't fork: $!\n"; + } elsif ($pid == 0) { + my $e = shift; + my $name = $e->fullname; + dolog "$name was created\n" if $e->IN_CREATE; + dolog "$name is no longer mounted\n" if $e->IN_UNMOUNT; + dolog "$name is gone\n" if $e->IN_IGNORED; + dolog "events for $name have been lost\n" if $e->IN_Q_OVERFLOW; + exec @rsync, $source->{$e->{w}->{name}}, $name; + warn "Can't exec: $!\n"; + } + + }) or die "Can't add watch: $!\n"; +} + +while (1) { + + $inotify->poll; + while (-1 != (my $pid = wait)) { + my $e = $? >> 8; + dolog "child ${ME}[$pid]: exit $e\n"; + } + +} + +END { + closelog; +} + +__END__ + +=pod + +=head1 NAME + +wgnd-watch - inotify actions for wiegand + +=head1 SYNOPSIS + +wgnd-watch [--map filename] + +wgnd-watch -m|--man + -h|--help + +=head1 DESCRIPTION + +wgnd-watch currently watches some directories for newly created subdirectories +and synchronises these from a given template directory. + +=head1 OPTIONS + +=over + +=item B<--map> I + +Name of a file containing mappings between templates and directories. Defaults +to F. + +=back + +=head1 FILES + +=over + +=item F + +default for B<--map> + +=back + +=head1 AUTHOR + +Matthias Förste + +=cut