#!/usr/bin/perl
use strict;
use warnings;

# End of term.
# Save a static snaphsot of the various dynamic pages,
# and disable the course wiki mason stuff.

my $courses = [
  { name   => 'statistics',
    pages  => [qw( home syllabus assignments resources )] ,
  },
  { name   => 'algorithms',
    pages  => [qw( home syllabus assignments resources )],
  },
  { name   => 'workshop',
    pages  => [qw( home syllabus )],
  },
  { name   => 'empirical',
    pages  => [qw( home syllabus schedule resources )],
  },
  { name   => 'tango',
    pages  => [qw( home syllabus )],
  },
 ];

my $base_url = "http://cs.marlboro.edu/term/spring05";

foreach my $course (@$courses){
  chdir $course->{name};
  #debug
  #print `pwd` . "\n" . `ls` . "\n";

  # One last fix: move about.html_DISABLE to about.html
  doit("mv about.html_DISABLE about.html");
  chdir("..");
  next;

  enable();

  # Fetch dynamic page and save as static.
  # New name will be page.html.1 since page.html exists.

  #foreach my $page (@{$course->{pages}}){    # This worked on first pass..
  foreach my $page (qw(about)){               # .. but I forgot 'about' pages.
    my $url = $base_url . "/" . $course->{name} . "/" . $page . ".html";
    print "working on $url ...\n";
    # doit("pwd");
    doit("wget $url");
    doit("mv $page.html   $page.html_DISABLE");   # disable dynamic page
    doit("mv $page.html.1 $page.html");           # put static in its place
  }

  disable();

  chdir '..';
}

# Print the unix command line to be executed, executed, and display status.
sub doit {
  my ($command) = @_;
  print " \$ $command \n";
  my $result = `$command`;
  chomp($result);
  print " status: '$result'\n" if $result;
}            


sub disable {
  # Disable dynamic page
  doit("mv autohandler autohandler_DISABLE");     # turn off course wiki here
  doit("mv dhandler dhandler_DISABLE");
}

sub enable {
  # Disable dynamic page
  doit("mv autohandler_DISABLE autohandler");
  doit("mv dhandler_DISABLE dhandler");
}

__END__

=== 1st pass output =====================

working on http://cs.marlboro.edu/term/spring05/statistics/home.html ...
 $ wget http://cs.marlboro.edu/term/spring05/statistics/home.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/statistics/home.html
           => `home.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ..                                                       28.50 MB/s

14:14:39 (28.50 MB/s) - `home.html.1' saved [2,988]

 $ mv home.html   home.html_DISABLE 
 $ mv home.html.1 home.html 
working on http://cs.marlboro.edu/term/spring05/statistics/syllabus.html ...
 $ wget http://cs.marlboro.edu/term/spring05/statistics/syllabus.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/statistics/syllabus.html
           => `syllabus.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ....                                                     81.51 MB/s

14:14:39 (81.51 MB/s) - `syllabus.html.1' saved [4,701]

 $ mv syllabus.html   syllabus.html_DISABLE 
 $ mv syllabus.html.1 syllabus.html 
working on http://cs.marlboro.edu/term/spring05/statistics/assignments.html ...
 $ wget http://cs.marlboro.edu/term/spring05/statistics/assignments.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/statistics/assignments.html
           => `assignments.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K .........                                                89.65 MB/s

14:14:39 (89.65 MB/s) - `assignments.html.1' saved [10,152]

 $ mv assignments.html   assignments.html_DISABLE 
 $ mv assignments.html.1 assignments.html 
working on http://cs.marlboro.edu/term/spring05/statistics/resources.html ...
 $ wget http://cs.marlboro.edu/term/spring05/statistics/resources.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/statistics/resources.html
           => `resources.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K .....                                                    62.46 MB/s

14:14:39 (62.46 MB/s) - `resources.html.1' saved [5,960]

 $ mv resources.html   resources.html_DISABLE 
 $ mv resources.html.1 resources.html 
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
working on http://cs.marlboro.edu/term/spring05/algorithms/home.html ...
 $ wget http://cs.marlboro.edu/term/spring05/algorithms/home.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/algorithms/home.html
           => `home.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ...                                                      30.13 MB/s

14:14:39 (30.13 MB/s) - `home.html.1' saved [3,159]

 $ mv home.html   home.html_DISABLE 
 $ mv home.html.1 home.html 
working on http://cs.marlboro.edu/term/spring05/algorithms/syllabus.html ...
 $ wget http://cs.marlboro.edu/term/spring05/algorithms/syllabus.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/algorithms/syllabus.html
           => `syllabus.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K .....                                                    79.47 MB/s

14:14:39 (79.47 MB/s) - `syllabus.html.1' saved [5,333]

 $ mv syllabus.html   syllabus.html_DISABLE 
 $ mv syllabus.html.1 syllabus.html 
working on http://cs.marlboro.edu/term/spring05/algorithms/assignments.html ...
 $ wget http://cs.marlboro.edu/term/spring05/algorithms/assignments.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/algorithms/assignments.html
           => `assignments.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ..........                                              108.71 MB/s

14:14:39 (108.71 MB/s) - `assignments.html.1' saved [10,373]

 $ mv assignments.html   assignments.html_DISABLE 
 $ mv assignments.html.1 assignments.html 
working on http://cs.marlboro.edu/term/spring05/algorithms/resources.html ...
 $ wget http://cs.marlboro.edu/term/spring05/algorithms/resources.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/algorithms/resources.html
           => `resources.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K .....                                                    93.92 MB/s

14:14:39 (93.92 MB/s) - `resources.html.1' saved [5,515]

 $ mv resources.html   resources.html_DISABLE 
 $ mv resources.html.1 resources.html 
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
working on http://cs.marlboro.edu/term/spring05/workshop/home.html ...
 $ wget http://cs.marlboro.edu/term/spring05/workshop/home.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/workshop/home.html
           => `home.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ..                                                       26.56 MB/s

14:14:39 (26.56 MB/s) - `home.html.1' saved [2,785]

 $ mv home.html   home.html_DISABLE 
 $ mv home.html.1 home.html 
working on http://cs.marlboro.edu/term/spring05/workshop/syllabus.html ...
 $ wget http://cs.marlboro.edu/term/spring05/workshop/syllabus.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/workshop/syllabus.html
           => `syllabus.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ....                                                     71.54 MB/s

14:14:39 (71.54 MB/s) - `syllabus.html.1' saved [4,201]

 $ mv syllabus.html   syllabus.html_DISABLE 
 $ mv syllabus.html.1 syllabus.html 
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
working on http://cs.marlboro.edu/term/spring05/empirical/home.html ...
 $ wget http://cs.marlboro.edu/term/spring05/empirical/home.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/empirical/home.html
           => `home.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ...                                                      34.69 MB/s

14:14:39 (34.69 MB/s) - `home.html.1' saved [3,638]

 $ mv home.html   home.html_DISABLE 
 $ mv home.html.1 home.html 
working on http://cs.marlboro.edu/term/spring05/empirical/syllabus.html ...
 $ wget http://cs.marlboro.edu/term/spring05/empirical/syllabus.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/empirical/syllabus.html
           => `syllabus.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ....                                                     82.55 MB/s

14:14:39 (82.55 MB/s) - `syllabus.html.1' saved [5,107]

 $ mv syllabus.html   syllabus.html_DISABLE 
 $ mv syllabus.html.1 syllabus.html 
working on http://cs.marlboro.edu/term/spring05/empirical/schedule.html ...
 $ wget http://cs.marlboro.edu/term/spring05/empirical/schedule.html 
--14:14:39--  http://cs.marlboro.edu/term/spring05/empirical/schedule.html
           => `schedule.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K .......... .......... .....                              73.56 MB/s

14:14:39 (73.56 MB/s) - `schedule.html.1' saved [25,838]

 $ mv schedule.html   schedule.html_DISABLE 
 $ mv schedule.html.1 schedule.html 
working on http://cs.marlboro.edu/term/spring05/empirical/resources.html ...
 $ wget http://cs.marlboro.edu/term/spring05/empirical/resources.html 
--14:14:40--  http://cs.marlboro.edu/term/spring05/empirical/resources.html
           => `resources.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ....                                                     76.22 MB/s

14:14:40 (76.22 MB/s) - `resources.html.1' saved [4,316]

 $ mv resources.html   resources.html_DISABLE 
 $ mv resources.html.1 resources.html 
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
working on http://cs.marlboro.edu/term/spring05/tango/home.html ...
 $ wget http://cs.marlboro.edu/term/spring05/tango/home.html 
--14:14:40--  http://cs.marlboro.edu/term/spring05/tango/home.html
           => `home.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ...                                                      30.03 MB/s

14:14:40 (30.03 MB/s) - `home.html.1' saved [3,149]

 $ mv home.html   home.html_DISABLE 
 $ mv home.html.1 home.html 
working on http://cs.marlboro.edu/term/spring05/tango/syllabus.html ...
 $ wget http://cs.marlboro.edu/term/spring05/tango/syllabus.html 
--14:14:40--  http://cs.marlboro.edu/term/spring05/tango/syllabus.html
           => `syllabus.html.1'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ...                                                      35.74 MB/s

14:14:40 (35.74 MB/s) - `syllabus.html.1' saved [3,748]

 $ mv syllabus.html   syllabus.html_DISABLE 
 $ mv syllabus.html.1 syllabus.html 
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
mahoney@cs spring05 $

=== 2nd pass : getting about.html's ==================

mv: cannot stat `autohandler_DISABLE': No such file or directory
 $ mv dhandler_DISABLE dhandler 
mv: cannot stat `dhandler_DISABLE': No such file or directory
working on http://cs.marlboro.edu/term/spring05/statistics/about.html ...
 $ wget http://cs.marlboro.edu/term/spring05/statistics/about.html 
--14:21:49--  http://cs.marlboro.edu/term/spring05/statistics/about.html
           => `about.html'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 404 Not Found
14:21:49 ERROR 404: Not Found.

 $ mv about.html   about.html_DISABLE 
mv: cannot stat `about.html': No such file or directory
 $ mv about.html.1 about.html 
mv: cannot stat `about.html.1': No such file or directory
 $ mv autohandler autohandler_DISABLE 
mv: cannot stat `autohandler': No such file or directory
 $ mv dhandler dhandler_DISABLE 
mv: cannot stat `dhandler': No such file or directory
 $ mv autohandler_DISABLE autohandler 
 $ mv dhandler_DISABLE dhandler 

### Note: I had done some work in statistics/ by hand,
    ending up with _DISABLED which made things blow up.
    I did it by hand instead, ending up with about.html_DISABLE
    as in these next ones.

working on http://cs.marlboro.edu/term/spring05/algorithms/about.html ...
 $ wget http://cs.marlboro.edu/term/spring05/algorithms/about.html 
--14:21:49--  http://cs.marlboro.edu/term/spring05/algorithms/about.html
           => `about.html'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K .....                                                    63.47 MB/s

14:21:49 (63.47 MB/s) - `about.html' saved [5,191]

 $ mv about.html   about.html_DISABLE 
 $ mv about.html.1 about.html 
mv: cannot stat `about.html.1': No such file or directory
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
 $ mv autohandler_DISABLE autohandler 
 $ mv dhandler_DISABLE dhandler 
working on http://cs.marlboro.edu/term/spring05/workshop/about.html ...
 $ wget http://cs.marlboro.edu/term/spring05/workshop/about.html 
--14:21:49--  http://cs.marlboro.edu/term/spring05/workshop/about.html
           => `about.html'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ....                                                     89.75 MB/s

14:21:49 (89.75 MB/s) - `about.html' saved [4,988]

 $ mv about.html   about.html_DISABLE 
 $ mv about.html.1 about.html 
mv: cannot stat `about.html.1': No such file or directory
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
 $ mv autohandler_DISABLE autohandler 
 $ mv dhandler_DISABLE dhandler 
working on http://cs.marlboro.edu/term/spring05/empirical/about.html ...
 $ wget http://cs.marlboro.edu/term/spring05/empirical/about.html 
--14:21:49--  http://cs.marlboro.edu/term/spring05/empirical/about.html
           => `about.html'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K .....                                                    82.99 MB/s

14:21:49 (82.99 MB/s) - `about.html' saved [5,221]

 $ mv about.html   about.html_DISABLE 
 $ mv about.html.1 about.html 
mv: cannot stat `about.html.1': No such file or directory
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
 $ mv autohandler_DISABLE autohandler 
 $ mv dhandler_DISABLE dhandler 
working on http://cs.marlboro.edu/term/spring05/tango/about.html ...
 $ wget http://cs.marlboro.edu/term/spring05/tango/about.html 
--14:21:49--  http://cs.marlboro.edu/term/spring05/tango/about.html
           => `about.html'
Resolving cs.marlboro.edu... 127.0.0.1
Connecting to cs.marlboro.edu[127.0.0.1]:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

    0K ....                                                     84.57 MB/s

14:21:49 (84.57 MB/s) - `about.html' saved [4,966]

 $ mv about.html   about.html_DISABLE 
 $ mv about.html.1 about.html 
mv: cannot stat `about.html.1': No such file or directory
 $ mv autohandler autohandler_DISABLE 
 $ mv dhandler dhandler_DISABLE 
mahoney@cs spring05$ l
total 68K
4.0K algorithms/	    4.0K empirical/	4.0K template/
4.0K bioinformatics/	    4.0K fix_files*	4.0K tutorials/
4.0K courses.txt	    8.0K schedule.html	4.0K workshop/
4.0K ded_hour/		    4.0K statistics/
 16K dynamic_to_static.pl*  4.0K tango/
mahoney@cs spring05$ 

== 3rd pass ============================
