Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add notify email functionality, as well as related logfile ability.

Use --notify|email with a comma-separated list of email addresses
to send the logfile, which is normally deleted after sending, unless
using --log or --keeplog to save and print the location of the log.
  • Loading branch information...
commit a50fc8e1978d5628fc9dc65e6fa8eff755da7978 1 parent 7036406
Stephen Brown II authored

Showing 2 changed files with 70 additions and 14 deletions. Show diff stats Hide diff stats

  1. +8 6 README.md
  2. +62 8 drupal-updater.pl
14 README.md
Source Rendered
@@ -38,12 +38,14 @@ or '--nodb' to simply skip the database update.
38 38 Options:
39 39 --------
40 40 <pre>
41   ---blind | runs through all updates without pausing to check for breakage in between
42   ---dryrun | runs through the motions without actually performing any changes
43   ---nodb | runs through all code updates, but does not update the database
44   ---verbose | shows output from drush up command pertinent to the module being updated
45   ---core-only | shows only core updates (i.e. the project name = drupal)
46   ---security-only | shows only security updates (i.e. the update status =~ SECURITY)
  41 +--blind | runs through all updates without pausing to check for breakage in between
  42 +--dryrun | runs through the motions without actually performing any changes
  43 +--nodb | runs through all code updates, but does not update the database
  44 +--verbose | shows output from drush up command pertinent to the module being updated
  45 +--core-only | shows only core updates (i.e. the project name = drupal)
  46 +--security-only | shows only security updates (i.e. the update status =~ SECURITY)
  47 +--log|keeplog | saves the update log to a file, and prints the location at the end
  48 +--notify|email=<email[,email]> | specify one or email addresses, separated by commas, to send the log to
47 49 </pre>
48 50
49 51 TODO:
70 drupal-updater.pl
@@ -2,22 +2,39 @@
2 2 use warnings;
3 3 use strict;
4 4
  5 +use Cwd qw(abs_path);
  6 +use POSIX qw(strftime);
5 7 use Term::ReadKey;
6 8 use Getopt::Long;
  9 +use Data::Dumper;
7 10
8 11 our $DRUSH_BIN = '';
9 12 our $GIT_BIN = '';
10   -my ($blind,$dryrun,$nodb,$verbose,$author,$coreonly,$securityonly);
  13 +my ($blind,$dryrun,$keeplog,$nodb,$verbose,$author,$coreonly,$securityonly,$notifyemail);
11 14 my $options = GetOptions (
12 15 "blind" => \$blind,
13 16 "test|dryrun" => \$dryrun,
  17 + "log|keeplog" => \$keeplog,
14 18 "nodb" => \$nodb,
15 19 "verbose" => \$verbose,
16 20 "author=s" => \$author,
17 21 "core-only" => \$coreonly,
18   - "security-only" => \$securityonly
  22 + "security-only" => \$securityonly,
  23 + "notify|email=s" => \$notifyemail
19 24 );
20 25
  26 +# Set up logfile
  27 +my $timenow = strftime("%FT%T", localtime);
  28 +my $timefile = $timenow;
  29 + $timefile =~ tr/:/-/;
  30 +my $tmpfile = "/tmp/drupal_updater-$timefile.log";
  31 +
  32 +open(my $log, ">>", $tmpfile);
  33 +
  34 +# Set up INT (Ctrl-C) (Ctrl-C) (Ctrl-C) (Ctrl-C) (Ctrl-C) (Ctrl-C) (Ctrl-C)
  35 +# (Ctrl-C) (Ctrl-C) handler
  36 +$SIG{'INT'} = \&end_sub;
  37 +
21 38 sub get_drush_up_status {
22 39 my %update_info;
23 40
@@ -43,7 +60,7 @@ sub get_drush_up_status {
43 60
44 61 sub module_path {
45 62 my $module = shift;
46   -
  63 +
47 64 my @info = split /\s:|\n/, `$DRUSH_BIN pm-info $module 2>/dev/null`;
48 65
49 66 my $path = 0;
@@ -274,7 +291,7 @@ sub update_module {
274 291 my $module_name = shift;
275 292 my $blank_lines = 0;
276 293 my $blanks_needed = 3;
277   -
  294 +
278 295 if ($dryrun) {
279 296 print "DRYRUN: '$DRUSH_BIN pm-update -n --cache $module_name 2>&1 |'\n";
280 297 open (DRUSHUP, "$DRUSH_BIN pm-update -n --cache $module_name 2>&1 |");
@@ -309,7 +326,7 @@ sub update_module {
309 326 }
310 327
311 328 sub git_proper_user {
312   - my $login = getlogin || getpwuid($<) || "unknown user";
  329 + my $login = getlogin || getpwuid($<) || "unknownuser";
313 330 my $name;
314 331 my $email;
315 332 my %return;
@@ -415,13 +432,21 @@ sub main {
415 432 print "Checking requirements... \n";
416 433 &check_requirements;
417 434
  435 + my %userinfo = &git_proper_user;
  436 +
  437 + print $log "=== DRY RUN ===\n" if $dryrun;
  438 + print $log $timenow."\n";
  439 + print $log "Drupal module updates performed by ".$userinfo{'name'}."\n";
  440 + print $log qx(drush vget --exact site_name);
  441 + print $log "directory: ".abs_path()."\n\n";
  442 +
418 443 print "Getting drush update status... ";
419 444 my $time = time;
420 445 my %info = &get_modules_info;
421 446 $time = time - $time;
422 447 print "took $time seconds.\n";
423 448
424   - my $num_updates = scalar(keys %info);
  449 + our $num_updates = scalar(keys %info);
425 450 print "There are $num_updates updates.\n" if ($num_updates > 1);
426 451
427 452 print "Updating all modules blindly.\n" if $blind;
@@ -435,7 +460,8 @@ sub main {
435 460 $modules .= $info{$k}{'module'}.", ";
436 461 printf "Committing update to %s\n", $info{$k}{'module'};
437 462 &git_commit($info{$k}{'message'});
438   -
  463 + print $log $info{$k}{'message'}."\n\n";
  464 +
439 465 unless ($blind) {
440 466 &post_update($info{$k}{'module'});
441 467 print "\nContinuing...\n";
@@ -453,10 +479,38 @@ sub main {
453 479 $total_time = time - $total_time;
454 480 print "Overall, $total_time seconds\n";
455 481
  482 + &end_sub;
  483 +}
  484 +
  485 +sub end_sub {
  486 + my $interrupt = shift;
  487 +
456 488 unless ($dryrun) {
457 489 print "\nHere is the git log summary:\n\n";
458   - system("$GIT_BIN log -n$num_updates");
  490 + my $gitlog = qx($GIT_BIN log -n$main::num_updates --stat);
  491 + print $gitlog;
  492 + print $log $gitlog;
  493 + }
  494 +
  495 + close $log;
  496 +
  497 + print "\n";
  498 +
  499 + if ($interrupt) {
  500 + print "Interrupted. There may be more updates to perform.\n";
459 501 }
  502 + if ($notifyemail) {
  503 + print "Sending log to $notifyemail\n";
  504 + system("mail -s 'Drupal Module Updates' $notifyemail < $tmpfile");
  505 + }
  506 + if ($keeplog) {
  507 + print "Log stored in $tmpfile\n";
  508 + } else {
  509 + unlink $tmpfile;
  510 + }
  511 +
  512 + print "Finished!\n\n";
  513 + exit;
460 514 }
461 515
462 516 &main;

0 comments on commit a50fc8e

Please sign in to comment.
Something went wrong with that request. Please try again.