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