web commit by tuomov
[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                         "render=s" => \$config{render},
29                         "wrappers!" => \$config{wrappers},
30                         "getctime" => \$config{getctime},
31                         "wrappermode=i" => \$config{wrappermode},
32                         "rcs=s" => \$config{rcs},
33                         "no-rcs" => sub { $config{rcs}="" },
34                         "anonok!" => \$config{anonok},
35                         "cgi!" => \$config{cgi},
36                         "discussion!" => \$config{discussion},
37                         "w3mmode!" => \$config{w3mmode},
38                         "notify!" => \$config{notify},
39                         "url=s" => \$config{url},
40                         "cgiurl=s" => \$config{cgiurl},
41                         "historyurl=s" => \$config{historyurl},
42                         "diffurl=s" => \$config{diffurl},
43                         "svnrepo" => \$config{svnrepo},
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                         "exclude=s@" => sub {
51                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
52                         },
53                         "adminuser=s@" => sub {
54                                 push @{$config{adminuser}}, $_[1]
55                         },
56                         "templatedir=s" => sub {
57                                 $config{templatedir}=possibly_foolish_untaint($_[1])
58                         },
59                         "underlaydir=s" => sub {
60                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
61                         },
62                         "wrapper:s" => sub {
63                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
64                         },
65                         "plugin=s@" => sub {
66                                 push @{$config{plugin}}, $_[1];
67                         },
68                         "disable-plugin=s@" => sub {
69                                 push @{$config{disable_plugins}}, $_[1];
70                         },
71                         "pingurl=s" => sub {
72                                 push @{$config{pingurl}}, $_[1];
73                         },
74                         "version" => sub {
75                                 print "ikiwiki version $IkiWiki::version\n";
76                                 exit;
77                         },
78                 ) || usage();
79
80                 if (! $config{setup} && ! $config{render}) {
81                         loadplugins();
82                         usage() unless @ARGV == 2;
83                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
84                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
85                         checkconfig();
86                 }
87         }
88         else {
89                 # wrapper passes a full config structure in the environment
90                 # variable
91                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
92                 if ($@) {
93                         error("WRAPPED_OPTIONS: $@");
94                 }
95                 loadplugins();
96                 checkconfig();
97         }
98 } #}}}
99
100 sub main () { #{{{
101         getconfig();
102         
103         if ($config{cgi}) {
104                 loadindex();
105                 require IkiWiki::CGI;
106                 cgi();
107         }
108         elsif ($config{setup}) {
109                 require IkiWiki::Setup;
110                 setup();
111         }
112         elsif ($config{wrapper}) {
113                 lockwiki();
114                 require IkiWiki::Wrapper;
115                 gen_wrapper();
116         }
117         elsif ($config{render}) {
118                 require IkiWiki::Render;
119                 commandline_render();
120         }
121         else {
122                 lockwiki();
123                 loadindex();
124                 require IkiWiki::Render;
125                 rcs_update();
126                 refresh();
127                 rcs_notify() if $config{notify};
128                 saveindex();
129         }
130 } #}}}
131
132 main;