]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki.in
only htmlize errors when cgi is actually running
[git.ikiwiki.info.git] / 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}};
5 package IkiWiki;
7 use warnings;
8 use strict;
9 use lib '.'; # For use in nonstandard directory, munged by Makefile.
10 use IkiWiki;
12 sub usage () { #{{{
13         die gettext("usage: ikiwiki [options] source dest"), "\n";
14 } #}}}
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                         "prefix-directives!" => \$config{prefix_directives},
33                         "getctime" => \$config{getctime},
34                         "numbacklinks=i" => \$config{numbacklinks},
35                         "rcs=s" => \$config{rcs},
36                         "no-rcs" => sub { $config{rcs}="" },
37                         "cgi!" => \$config{cgi},
38                         "discussion!" => \$config{discussion},
39                         "w3mmode!" => \$config{w3mmode},
40                         "url=s" => \$config{url},
41                         "cgiurl=s" => \$config{cgiurl},
42                         "historyurl=s" => \$config{historyurl},
43                         "diffurl=s" => \$config{diffurl},
44                         "svnpath" => \$config{svnpath},
45                         "adminemail=s" => \$config{adminemail},
46                         "timeformat=s" => \$config{timeformat},
47                         "sslcookie!" => \$config{sslcookie},
48                         "httpauth!" => \$config{httpauth},
49                         "userdir=s" => \$config{userdir},
50                         "htmlext=s" => \$config{htmlext},
51                         "libdir=s" => \$config{libdir},
52                         "exclude=s@" => sub {
53                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
54                         },
55                         "adminuser=s@" => sub {
56                                 push @{$config{adminuser}}, $_[1]
57                         },
58                         "templatedir=s" => sub {
59                                 $config{templatedir}=possibly_foolish_untaint($_[1])
60                         },
61                         "underlaydir=s" => sub {
62                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
63                         },
64                         "wrapper:s" => sub {
65                                 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
66                         },
67                         "wrappermode=i" => sub {
68                                 $config{wrappermode}=possibly_foolish_untaint($_[1])
69                         },
70                         "plugin=s@" => sub {
71                                 push @{$config{plugin}}, $_[1];
72                         },
73                         "disable-plugin=s@" => sub {
74                                 push @{$config{disable_plugins}}, $_[1];
75                         },
76                         "pingurl=s" => sub {
77                                 push @{$config{pingurl}}, $_[1];
78                         },
79                         "set=s" => sub {
80                                 my ($var, $val)=split('=', $_[1], 2);
81                                 if (! defined $var || ! defined $val) {
82                                         die gettext("usage: --set var=value"), "\n";
83                                 }
84                                 $config{$var}=$val;
85                         },
86                         "version" => sub {
87                                 print "ikiwiki version $IkiWiki::version\n";
88                                 exit;
89                         },
90                 ) || usage();
92                 if (! $config{setup} && ! $config{render}) {
93                         loadplugins();
94                         usage() unless @ARGV == 2;
95                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
96                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
97                         checkconfig();
98                 }
99         }
100         else {
101                 # wrapper passes a full config structure in the environment
102                 # variable
103                 eval {possibly_foolish_untaint($ENV{WRAPPED_OPTIONS})};
104                 if ($@) {
105                         error("WRAPPED_OPTIONS: $@");
106                 }
107                 loadplugins();
108                 checkconfig();
109         }
110 } #}}}
112 sub main () { #{{{
113         getconfig();
114         
115         if ($config{setup}) {
116                 require IkiWiki::Setup;
117                 setup();
118         }
119         elsif ($config{wrapper}) {
120                 lockwiki();
121                 require IkiWiki::Wrapper;
122                 gen_wrapper();
123         }
124         elsif ($config{cgi}) {
125                 require IkiWiki::CGI;
126                 eval {cgi()};
127                 if ($@) {
128                         cgierror($@);
129                 }
130         }
131         elsif ($config{render}) {
132                 require IkiWiki::Render;
133                 commandline_render();
134         }
135         elsif ($config{post_commit} && ! commit_hook_enabled()) {
136                 # do nothing
137         }
138         else {
139                 lockwiki();
140                 loadindex();
141                 require IkiWiki::Render;
142                 rcs_update();
143                 refresh();
144                 saveindex();
145         }
146 } #}}}
148 main;