sync_website 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/perl
  2. use strict;
  3. use DBI;
  4. #$ENV{PERL5LIB}="plugins-scripts"; # Needed for utils.pm
  5. unless ($ENV{DRUPAL_PASSWORD}) {
  6. die "Must set envvar for DRUPAL_PASSWORD";
  7. }
  8. my $pid = open(F, "-|", qw(ssh -n -N -L 25555:127.0.0.1:3306 nagiosplugins.org));
  9. # Allow time for ssh tunnel to be created
  10. sleep 2;
  11. # To stop the death of ssh tunnel being defunct
  12. $SIG{CHLD} = 'IGNORE';
  13. END { kill 'INT', $pid if $pid };
  14. my $dbh = DBI->connect("DBI:mysql:database=drupal;host=127.0.0.1;port=25555", "drupal", $ENV{DRUPAL_PASSWORD});
  15. my @plugin_paths;
  16. push @plugin_paths, (grep { -x $_ && -f $_ } (<plugins-root/*>, <plugins/*>) );
  17. foreach my $plugin_path (@plugin_paths) {
  18. my $plugin = $plugin_path;
  19. $plugin =~ s%.*/%%;
  20. my $help_option = "--help";
  21. $help_option = "-h" if ($plugin eq "check_icmp");
  22. my $help = `$plugin_path $help_option` || die "Cannot run $plugin -h";
  23. $help =~ s/</&lt;/g;
  24. $help =~ s/>/&gt;/g;
  25. my $rows = $dbh->do("UPDATE node SET created=UNIX_TIMESTAMP(NOW()) WHERE title='$plugin'");
  26. unless ($rows == 1) {
  27. die "Cannot find $plugin in drupal to update - create book page first";
  28. }
  29. $dbh->do("UPDATE node_revisions SET timestamp=UNIX_TIMESTAMP(NOW()), log='Updated by update_online_manpage', teaser='$plugin --help', body=? WHERE title='$plugin'",
  30. {},
  31. "<pre>".$help."</pre>");
  32. }
  33. print "Finished\n";