web commit by http://madduck.myopenid.com/
[ikiwiki] / ikiwiki.in
1 #!/usr/bin/perl -T
2 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
3 delete @ENV{qw{IFS CDPATH ENV BASH_ENV}};
4
5 package IkiWiki;
6
7 use warnings;
8 use strict;
9 use lib '.'; # For use in nonstandard directory, munged by Makefile.
10 use IkiWiki;
11
12 sub usage () { #{{{
13         die gettext("usage: ikiwiki [options] source dest"), "\n";
14 } #}}}
15
16 sub getconfig () { #{{{
17         if (! exists $ENV{WRAPPED_OPTIONS}) {
18                 %config=defaultconfig();
19                 eval q{use Getopt::Long};
20                 Getopt::Long::Configure('pass_through');
21                 GetOptions(
22                         "setup|s=s" => \$config{setup},
23                         "wikiname=s" => \$config{wikiname},
24                         "verbose|v!" => \$config{verbose},
25                         "syslog!" => \$config{syslog},
26                         "rebuild!" => \$config{rebuild},
27                         "refresh!" => \$config{refresh},
28                         "post-commit" => \$config{post_commit},
29                         "render=s" => \$config{render},
30                         "wrappers!" => \$config{wrappers},
31                         "usedirs!" => \$config{usedirs},
32                         "getctime" => \$config{getctime},
33                         "numbacklinks=i" => \$config{numbacklinks},
34                         "rcs=s" => \$config{rcs},
35                         "no-rcs" => sub { $config{rcs}="" },
36                         "cgi!" => \$config{cgi},
37                         "discussion!" => \$config{discussion},
38                         "w3mmode!" => \$config{w3mmode},
39                         "notify!" => \$config{notify},
40                         "url=s" => \$config{url},
41                         "cgiurl=s" => \$config{cgiurl},
42                         "historyurl=s" => \$config{historyurl},
43                         "diffurl=s" => \$config{diffurl},
44                         "svnrepo" => \$config{svnrepo},
45                         "svnpath" => \$config{svnpath},
46                         "adminemail=s" => \$config{adminemail},
47                         "timeformat=s" => \$config{timeformat},
48                         "sslcookie!" => \$config{sslcookie},
49                         "httpauth!" => \$config{httpauth},
50                         "userdir=s" => \$config{userdir},
51                         "htmlext=s" => \$config{htmlext},
52                         "libdir=s" => \$config{libdir},
53                         "exclude=s@" => sub {
54                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
55                         },
56                         "adminuser=s@" => sub {
57                                 push @{$config{adminuser}}, $_[1]
58                         },
59                         "templatedir=s" => sub {
60                                 $config{templatedir}=possibly_foolish_untaint($_[1])
61                         },
62                         "underlaydir=s" => sub {
63                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
64                         },
65                         "wrapper:s" => sub {
66                                 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
67                         },
68                         "wrappermode=i" => sub {
69                                 $config{wrappermode}=possibly_foolish_untaint($_[1])
70                         },
71                         "plugin=s@" => sub {
72                                 push @{$config{plugin}}, $_[1];
73                         },
74                         "disable-plugin=s@" => sub {
75                                 push @{$config{disable_plugins}}, $_[1];
76                         },
77                         "pingurl=s" => sub {
78                                 push @{$config{pingurl}}, $_[1];
79                         },
80                         "set=s" => sub {
81                                 my ($var, $val)=split('=', $_[1], 2);
82                                 if (! defined $var || ! defined $val) {
83                                         die gettext("usage: --set var=value"), "\n";
84                                 }
85                                 $config{$var}=$val;
86                         },
87                         "version" => sub {
88                                 print "ikiwiki version $IkiWiki::version\n";
89                                 exit;
90                         },
91                 ) || usage();
92
93                 if (! $config{setup} && ! $config{render}) {
94                         loadplugins();
95                         usage() unless @ARGV == 2;
96                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
97                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
98                         checkconfig();
99                 }
100         }
101         else {
102                 # wrapper passes a full config structure in the environment
103                 # variable
104                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
105                 if ($@) {
106                         error("WRAPPED_OPTIONS: $@");
107                 }
108                 loadplugins();
109                 checkconfig();
110         }
111 } #}}}
112
113 sub main () { #{{{
114         getconfig();
115         
116         if ($config{setup}) {
117                 require IkiWiki::Setup;
118                 setup();
119         }
120         elsif ($config{wrapper}) {
121                 lockwiki();
122                 require IkiWiki::Wrapper;
123                 gen_wrapper();
124         }
125         elsif ($config{cgi}) {
126                 loadindex();
127                 require IkiWiki::CGI;
128                 cgi();
129         }
130         elsif ($config{render}) {
131                 require IkiWiki::Render;
132                 commandline_render();
133         }
134         elsif ($config{post_commit} && ! commit_hook_enabled()) {
135                 if ($config{notify}) {
136                         loadindex();
137                         rcs_notify();
138                 }
139         }
140         else {
141                 lockwiki();
142                 loadindex();
143                 require IkiWiki::Render;
144                 rcs_update();
145                 refresh();
146                 rcs_notify() if $config{notify};
147                 saveindex();
148         }
149 } #}}}
150
151 main;