web commit by NicolasLimare: comment
[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                         "wrappermode=i" => \$config{wrappermode},
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                         "notify!" => \$config{notify},
41                         "url=s" => \$config{url},
42                         "cgiurl=s" => \$config{cgiurl},
43                         "historyurl=s" => \$config{historyurl},
44                         "diffurl=s" => \$config{diffurl},
45                         "svnrepo" => \$config{svnrepo},
46                         "svnpath" => \$config{svnpath},
47                         "adminemail=s" => \$config{adminemail},
48                         "timeformat=s" => \$config{timeformat},
49                         "sslcookie!" => \$config{sslcookie},
50                         "httpauth!" => \$config{httpauth},
51                         "userdir=s" => \$config{userdir},
52                         "htmlext=s" => \$config{htmlext},
53                         "libdir=s" => \$config{libdir},
54                         "exclude=s@" => sub {
55                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
56                         },
57                         "adminuser=s@" => sub {
58                                 push @{$config{adminuser}}, $_[1]
59                         },
60                         "templatedir=s" => sub {
61                                 $config{templatedir}=possibly_foolish_untaint($_[1])
62                         },
63                         "underlaydir=s" => sub {
64                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
65                         },
66                         "wrapper:s" => sub {
67                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
68                         },
69                         "plugin=s@" => sub {
70                                 push @{$config{plugin}}, $_[1];
71                         },
72                         "disable-plugin=s@" => sub {
73                                 push @{$config{disable_plugins}}, $_[1];
74                         },
75                         "pingurl=s" => sub {
76                                 push @{$config{pingurl}}, $_[1];
77                         },
78                         "set=s" => sub {
79                                 my ($var, $val)=split('=', $_[1], 2);
80                                 if (! defined $var || ! defined $val) {
81                                         die gettext("usage: --set var=value"), "\n";
82                                 }
83                                 $config{$var}=$val;
84                         },
85                         "version" => sub {
86                                 print "ikiwiki version $IkiWiki::version\n";
87                                 exit;
88                         },
89                 ) || usage();
90
91                 if (! $config{setup} && ! $config{render}) {
92                         loadplugins();
93                         usage() unless @ARGV == 2;
94                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
95                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
96                         checkconfig();
97                 }
98         }
99         else {
100                 # wrapper passes a full config structure in the environment
101                 # variable
102                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
103                 if ($@) {
104                         error("WRAPPED_OPTIONS: $@");
105                 }
106                 loadplugins();
107                 checkconfig();
108         }
109 } #}}}
110
111 sub main () { #{{{
112         getconfig();
113         
114         if ($config{cgi}) {
115                 loadindex();
116                 require IkiWiki::CGI;
117                 cgi();
118         }
119         elsif ($config{setup}) {
120                 require IkiWiki::Setup;
121                 setup();
122         }
123         elsif ($config{wrapper}) {
124                 lockwiki();
125                 require IkiWiki::Wrapper;
126                 gen_wrapper();
127         }
128         elsif ($config{render}) {
129                 require IkiWiki::Render;
130                 commandline_render();
131         }
132         elsif ($config{post_commit} && ! commit_hook_enabled()) {
133                 if ($config{notify}) {
134                         loadindex();
135                         rcs_notify();
136                 }
137         }
138         else {
139                 lockwiki();
140                 loadindex();
141                 require IkiWiki::Render;
142                 rcs_update();
143                 refresh();
144                 rcs_notify() if $config{notify};
145                 saveindex();
146         }
147 } #}}}
148
149 main;