rename the "render" hook to "change", which is clearer
[ikiwiki] / ikiwiki
1 #!/usr/bin/perl -T
2 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
3
4 package IkiWiki;
5 use warnings;
6 use strict;
7 use lib '.'; # For use without installation, removed by Makefile.
8 use IkiWiki;
9
10 sub usage () { #{{{
11         die "usage: ikiwiki [options] source dest\n";
12 } #}}}
13
14 sub getconfig () { #{{{
15         if (! exists $ENV{WRAPPED_OPTIONS}) {
16                 %config=defaultconfig();
17                 eval q{use Getopt::Long};
18                 GetOptions(
19                         "setup|s=s" => \$config{setup},
20                         "wikiname=s" => \$config{wikiname},
21                         "verbose|v!" => \$config{verbose},
22                         "rebuild!" => \$config{rebuild},
23                         "refresh!" => \$config{refresh},
24                         "getctime" => \$config{getctime},
25                         "wrappermode=i" => \$config{wrappermode},
26                         "rcs=s" => \$config{rcs},
27                         "no-rcs" => sub { $config{rcs}="" },
28                         "anonok!" => \$config{anonok},
29                         "rss!" => \$config{rss},
30                         "cgi!" => \$config{cgi},
31                         "notify!" => \$config{notify},
32                         "sanitize!" => \$config{sanitize},
33                         "url=s" => \$config{url},
34                         "cgiurl=s" => \$config{cgiurl},
35                         "historyurl=s" => \$config{historyurl},
36                         "diffurl=s" => \$config{diffurl},
37                         "svnrepo" => \$config{svnrepo},
38                         "svnpath" => \$config{svnpath},
39                         "adminemail=s" => \$config{adminemail},
40                         "exclude=s@" => sub {
41                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
42                         },
43                         "adminuser=s@" => sub {
44                                 push @{$config{adminuser}}, $_[1]
45                         },
46                         "templatedir=s" => sub {
47                                 $config{templatedir}=possibly_foolish_untaint($_[1])
48                         },
49                         "underlaydir=s" => sub {
50                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
51                         },
52                         "wrapper:s" => sub {
53                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
54                         },
55                         "plugin=s@" => sub {
56                                 push @{$config{plugin}}, $_[1];
57                         }
58                 ) || usage();
59
60                 if (! $config{setup}) {
61                         usage() unless @ARGV == 2;
62                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
63                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
64                         checkconfig();
65                 }
66         }
67         else {
68                 # wrapper passes a full config structure in the environment
69                 # variable
70                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
71                 if ($@) {
72                         error("WRAPPED_OPTIONS: $@");
73                 }
74                 checkconfig();
75         }
76 } #}}}
77
78 sub main () { #{{{
79         getconfig();
80         
81         if ($config{cgi}) {
82                 lockwiki();
83                 loadindex();
84                 require IkiWiki::CGI;
85                 cgi();
86         }
87         elsif ($config{setup}) {
88                 require IkiWiki::Setup;
89                 setup();
90         }
91         elsif ($config{wrapper}) {
92                 lockwiki();
93                 require IkiWiki::Wrapper;
94                 gen_wrapper();
95         }
96         else {
97                 lockwiki();
98                 loadindex();
99                 require IkiWiki::Render;
100                 rcs_update();
101                 rcs_getctime() if $config{getctime};
102                 refresh();
103                 rcs_notify() if $config{notify};
104                 saveindex();
105         }
106 } #}}}
107
108 main;