]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki.in
Added a comment
[git.ikiwiki.info.git] / ikiwiki.in
1 #!/usr/bin/perl
2 package IkiWiki;
4 use warnings;
5 use strict;
6 use lib '.'; # For use in nonstandard directory, munged by Makefile.
7 use IkiWiki 3.00;
9 sub usage () {
10         die gettext("usage: ikiwiki [options] source dest"), "\n",
11             gettext("       ikiwiki --setup configfile"), "\n";
12 }
14 sub setup (@) {
15         require IkiWiki::Setup;
16         my $verbose=$config{verbose};
17         my $syslog=$config{syslog};
18         IkiWiki::Setup::load($_[1]);
19         $config{setupverbose}=$config{verbose};
20         $config{setupsyslog}=$config{syslog};
21         $config{verbose}=$verbose || $config{setupverbose};
22         $config{syslog}=$syslog;
23         $config{setup}=1;
24 }
26 sub getconfig () {
27         if (! exists $ENV{WRAPPED_OPTIONS}) {
28                 %config=defaultconfig();
29                 eval q{use Getopt::Long};
30                 Getopt::Long::Configure('pass_through');
31                 GetOptions(
32                         "setup|s=s" => \&setup,
33                         "dumpsetup|s=s" => \$config{dumpsetup},
34                         "changesetup|s=s" => sub {
35                                 $config{changesetup}=$_[1];
36                                 $config{genwrappers}=1;
37                                 $config{refresh}=1;
38                                 setup(@_);
39                         },
40                         "wikiname=s" => \$config{wikiname},
41                         "verbose|v!" => \$config{verbose},
42                         "syslog!" => \$config{syslog},
43                         "rebuild!" => \$config{rebuild},
44                         "refresh!" => \$config{refresh},
45                         "clean!" => \$config{clean},
46                         "post-commit" => \$config{post_commit},
47                         "render=s" => \$config{render},
48                         "wrappers!" => \$config{genwrappers},
49                         "wrappergroup=s" => \$config{wrappergroup},
50                         "usedirs!" => \$config{usedirs},
51                         "prefix-directives!" => \$config{prefix_directives},
52                         "getctime" => \$config{gettime},
53                         "gettime!" => \$config{gettime},
54                         "numbacklinks=i" => \$config{numbacklinks},
55                         "rcs=s" => \$config{rcs},
56                         "no-rcs" => sub { $config{rcs}="" },
57                         "cgi!" => \$config{cgi},
58                         "discussion!" => \$config{discussion},
59                         "w3mmode!" => \$config{w3mmode},
60                         "url=s" => \$config{url},
61                         "cgiurl=s" => \$config{cgiurl},
62                         "historyurl=s" => \$config{historyurl},
63                         "diffurl=s" => \$config{diffurl},
64                         "svnpath" => \$config{svnpath},
65                         "adminemail=s" => \$config{adminemail},
66                         "timeformat=s" => \$config{timeformat},
67                         "sslcookie!" => \$config{sslcookie},
68                         "userdir=s" => \$config{userdir},
69                         "htmlext=s" => \$config{htmlext},
70                         "libdir=s" => \$config{libdir},
71                         "exclude=s@" => sub {
72                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
73                         },
74                         "include=s@" => sub {
75                                 $config{include}=defined $config{include} && length $config{include} ? "$config{include}|$_[1]" : $_[1];
76                         },
77                         "adminuser=s@" => sub {
78                                 push @{$config{adminuser}}, $_[1]
79                         },
80                         "templatedir=s" => sub {
81                                 $config{templatedir}=possibly_foolish_untaint($_[1])
82                         },
83                         "underlaydir=s" => sub {
84                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
85                         },
86                         "wrapper:s" => sub {
87                                 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
88                         },
89                         "wrappermode=i" => sub {
90                                 $config{wrappermode}=possibly_foolish_untaint($_[1])
91                         },
92                         "plugin=s@" => sub {
93                                 push @{$config{add_plugins}}, $_[1]
94                                         unless grep { $_ eq $_[1] } @{$config{add_plugins}};
95                         },
96                         "disable-plugin=s@" => sub {
97                                 push @{$config{disable_plugins}}, $_[1];
98                         },
99                         "set=s" => sub {
100                                 my ($var, $val)=split('=', $_[1], 2);
101                                 if (! defined $var || ! defined $val) {
102                                         die gettext("usage: --set var=value"), "\n";
103                                 }
104                                 $config{$var}=$val;
105                         },
106                         "set-yaml=s" => sub {
107                                 my ($var, $val)=split('=', $_[1], 2);
108                                 if (! defined $var || ! defined $val) {
109                                         die gettext("usage: --set-yaml var=value"), "\n";
110                                 }
111                                 eval q{use YAML::Any};
112                                 eval q{use YAML} if $@;
113                                 die $@ if $@;
114                                 eval q{$YAML::Syck::ImplicitUnicode=1};
115                                 $config{$var}=Load($val."\n");
116                         },
117                         "version" => sub {
118                                 print "ikiwiki version $IkiWiki::version\n";
119                                 exit;
120                         },
121                         "help|h" => sub { $SIG{__WARN__}=sub {}; die },
122                 ) || usage();
124                 if (! $config{setup}) {
125                         loadplugins();
126                         if (@ARGV == 2) {
127                                 $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
128                                 $config{destdir} = possibly_foolish_untaint(shift @ARGV);
129                                 checkconfig();
130                         }
131                         else {
132                                 usage() unless $config{dumpsetup};
133                         }
134                 }
135         }
136         else {
137                 # wrapper passes a full config structure in the environment
138                 # variable
139                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
140                 if ($@) {
141                         error("WRAPPED_OPTIONS: $@");
142                 }
143                 delete $ENV{WRAPPED_OPTIONS};
145                 loadplugins();
146                 checkconfig();
147         }
150 sub main () {
151         getconfig();
152         
153         if ($config{setup}) {
154                 delete $config{setup};
155                 loadplugins();
156                 checkconfig();
158                 if (@{$config{wrappers}} && 
159                     ! $config{render} && ! $config{dumpsetup} &&
160                     ! $config{clean} &&
161                     ((! $config{refresh} && ! $config{post_commit})
162                      || $config{genwrappers})) {
163                         require IkiWiki::Wrapper;
164                         gen_wrappers();
165                 }
166                 
167                 # setup implies a wiki rebuild by default
168                 if (! $config{refresh} && ! $config{render} &&
169                     ! $config{post_commit} && ! $config{clean}) {
170                         $config{rebuild}=1;
171                 }
172         }
174         if ($config{changesetup}) {
175                 require IkiWiki::Setup;
176                 IkiWiki::Setup::dump($config{changesetup});
177         }
179         if ($config{dumpsetup}) {
180                 $config{srcdir}="" if ! defined $config{srcdir};
181                 $config{destdir}="" if ! defined $config{destdir};
182                 $config{syslog}=1 if $config{setupsyslog};
183                 checkconfig();
184                 require IkiWiki::Setup;
185                 IkiWiki::Setup::dump($config{dumpsetup});
186         }
187         elsif ($config{wrapper}) {
188                 lockwiki();
189                 require IkiWiki::Wrapper;
190                 gen_wrapper();
191         }
192         elsif ($config{cgi}) {
193                 require IkiWiki::CGI;
194                 eval {cgi()};
195                 if ($@) {
196                         cgierror($@);
197                 }
198         }
199         elsif ($config{render}) {
200                 require IkiWiki::Render;
201                 commandline_render();
202         }
203         elsif ($config{post_commit} && ! commit_hook_enabled()) {
204                 # do nothing
205         }
206         elsif ($config{clean}) {
207                 require IkiWiki::Render;
208                 foreach my $wrapper (@{$config{wrappers}}) {
209                         prune($wrapper->{wrapper});
210                 }
211                 clean_rendered();
212                 system("rm", "-rf", $config{wikistatedir});
213         }
214         else {
215                 if ($config{rebuild}) {
216                         debug(gettext("rebuilding wiki.."));
217                 }
218                 else {
219                         debug(gettext("refreshing wiki.."));
220                 }
221                 lockwiki();
222                 loadindex();
223                 require IkiWiki::Render;
224                 rcs_update();
225                 refresh();
226                 saveindex();
227                 debug(gettext("done"));
228         }
231 main;