]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki.pl
web commit by shoesorder
[git.ikiwiki.info.git] / ikiwiki.pl
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 without installation, removed by Makefile.
10 use IkiWiki;
12 sub usage () { #{{{
13         die "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                         "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                         "rss!" => \$config{rss},
36                         "atom!" => \$config{atom},
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                         "exclude=s@" => sub {
52                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
53                         },
54                         "adminuser=s@" => sub {
55                                 push @{$config{adminuser}}, $_[1]
56                         },
57                         "templatedir=s" => sub {
58                                 $config{templatedir}=possibly_foolish_untaint($_[1])
59                         },
60                         "underlaydir=s" => sub {
61                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
62                         },
63                         "wrapper:s" => sub {
64                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
65                         },
66                         "plugin=s@" => sub {
67                                 push @{$config{plugin}}, $_[1];
68                         },
69                         "disable-plugin=s@" => sub {
70                                 $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
71                         },
72                         "pingurl=s" => sub {
73                                 push @{$config{pingurl}}, $_[1];
74                         },
75                         "version" => sub {
76                                 print "ikiwiki version $IkiWiki::version\n";
77                                 exit;
78                         },
79                 ) || usage();
81                 if (! $config{setup} && ! $config{render}) {
82                         loadplugins();
83                         usage() unless @ARGV == 2;
84                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
85                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
86                         checkconfig();
87                 }
88         }
89         else {
90                 # wrapper passes a full config structure in the environment
91                 # variable
92                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
93                 if ($@) {
94                         error("WRAPPED_OPTIONS: $@");
95                 }
96                 loadplugins();
97                 checkconfig();
98         }
99 } #}}}
101 sub main () { #{{{
102         getconfig();
103         
104         if ($config{cgi}) {
105                 lockwiki();
106                 loadindex();
107                 require IkiWiki::CGI;
108                 cgi();
109         }
110         elsif ($config{setup}) {
111                 require IkiWiki::Setup;
112                 setup();
113         }
114         elsif ($config{wrapper}) {
115                 lockwiki();
116                 require IkiWiki::Wrapper;
117                 gen_wrapper();
118         }
119         elsif ($config{render}) {
120                 require IkiWiki::Render;
121                 commandline_render();
122         }
123         else {
124                 lockwiki();
125                 loadindex();
126                 require IkiWiki::Render;
127                 rcs_update();
128                 refresh();
129                 rcs_notify() if $config{notify};
130                 saveindex();
131         }
132 } #}}}
134 main;