* ikiwiki can now download and aggregate feeds with its new aggregate
[ikiwiki.git] / 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                 Getopt::Long::Configure('pass_through');
19                 GetOptions(
20                         "setup|s=s" => \$config{setup},
21                         "wikiname=s" => \$config{wikiname},
22                         "verbose|v!" => \$config{verbose},
23                         "rebuild!" => \$config{rebuild},
24                         "refresh!" => \$config{refresh},
25                         "wrappers!" => \$config{wrappers},
26                         "getctime" => \$config{getctime},
27                         "wrappermode=i" => \$config{wrappermode},
28                         "rcs=s" => \$config{rcs},
29                         "no-rcs" => sub { $config{rcs}="" },
30                         "anonok!" => \$config{anonok},
31                         "rss!" => \$config{rss},
32                         "cgi!" => \$config{cgi},
33                         "discussion!" => \$config{discussion},
34                         "w3mmode!" => \$config{w3mmode},
35                         "notify!" => \$config{notify},
36                         "url=s" => \$config{url},
37                         "cgiurl=s" => \$config{cgiurl},
38                         "historyurl=s" => \$config{historyurl},
39                         "diffurl=s" => \$config{diffurl},
40                         "svnrepo" => \$config{svnrepo},
41                         "svnpath" => \$config{svnpath},
42                         "adminemail=s" => \$config{adminemail},
43                         "timeformat=s" => \$config{timeformat},
44                         "exclude=s@" => sub {
45                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
46                         },
47                         "adminuser=s@" => sub {
48                                 push @{$config{adminuser}}, $_[1]
49                         },
50                         "templatedir=s" => sub {
51                                 $config{templatedir}=possibly_foolish_untaint($_[1])
52                         },
53                         "underlaydir=s" => sub {
54                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
55                         },
56                         "wrapper:s" => sub {
57                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
58                         },
59                         "plugin=s@" => sub {
60                                 push @{$config{plugin}}, $_[1];
61                         },
62                         "disable-plugin=s@" => sub {
63                                 $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
64                         },
65                         "pingurl" => sub {
66                                 push @{$config{pingurl}}, $_[1];
67                         }
68                 ) || usage();
69
70                 if (! $config{setup}) {
71                         loadplugins();
72                         run_hooks(getopt => sub { shift->() });
73                         if (grep /^-/, @ARGV) {
74                                 print STDERR "Unknown option: $_\n"
75                                         foreach grep /^-/, @ARGV;
76                                 usage();
77                         }
78                         usage() unless @ARGV == 2;
79                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
80                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
81                         checkconfig();
82                 }
83         }
84         else {
85                 # wrapper passes a full config structure in the environment
86                 # variable
87                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
88                 if ($@) {
89                         error("WRAPPED_OPTIONS: $@");
90                 }
91                 loadplugins();
92                 checkconfig();
93         }
94 } #}}}
95
96 sub main () { #{{{
97         getconfig();
98         
99         if ($config{cgi}) {
100                 lockwiki();
101                 loadindex();
102                 require IkiWiki::CGI;
103                 cgi();
104         }
105         elsif ($config{setup}) {
106                 require IkiWiki::Setup;
107                 setup();
108         }
109         elsif ($config{wrapper}) {
110                 lockwiki();
111                 require IkiWiki::Wrapper;
112                 gen_wrapper();
113         }
114         else {
115                 lockwiki();
116                 loadindex();
117                 require IkiWiki::Render;
118                 rcs_update();
119                 refresh();
120                 rcs_notify() if $config{notify};
121                 saveindex();
122         }
123 } #}}}
124
125 main;