]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki.in
0f82f77ac538a90cc8c7d7c3d3c6ab9f1433bb00
[ikiwiki.git] / 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                         "dumpsetup|s=s" => \$config{dumpsetup},
24                         "wikiname=s" => \$config{wikiname},
25                         "verbose|v!" => \$config{verbose},
26                         "syslog!" => \$config{syslog},
27                         "rebuild!" => \$config{rebuild},
28                         "refresh!" => \$config{refresh},
29                         "post-commit" => \$config{post_commit},
30                         "render=s" => \$config{render},
31                         "wrappers!" => \$config{wrappers},
32                         "usedirs!" => \$config{usedirs},
33                         "prefix-directives!" => \$config{prefix_directives},
34                         "getctime" => \$config{getctime},
35                         "numbacklinks=i" => \$config{numbacklinks},
36                         "rcs=s" => \$config{rcs},
37                         "no-rcs" => sub { $config{rcs}="" },
38                         "cgi!" => \$config{cgi},
39                         "discussion!" => \$config{discussion},
40                         "w3mmode!" => \$config{w3mmode},
41                         "url=s" => \$config{url},
42                         "cgiurl=s" => \$config{cgiurl},
43                         "historyurl=s" => \$config{historyurl},
44                         "diffurl=s" => \$config{diffurl},
45                         "svnpath" => \$config{svnpath},
46                         "adminemail=s" => \$config{adminemail},
47                         "timeformat=s" => \$config{timeformat},
48                         "sslcookie!" => \$config{sslcookie},
49                         "httpauth!" => \$config{httpauth},
50                         "userdir=s" => \$config{userdir},
51                         "htmlext=s" => \$config{htmlext},
52                         "libdir=s" => \$config{libdir},
53                         "exclude=s@" => sub {
54                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
55                         },
56                         "adminuser=s@" => sub {
57                                 push @{$config{adminuser}}, $_[1]
58                         },
59                         "templatedir=s" => sub {
60                                 $config{templatedir}=possibly_foolish_untaint($_[1])
61                         },
62                         "underlaydir=s" => sub {
63                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
64                         },
65                         "wrapper:s" => sub {
66                                 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
67                         },
68                         "wrappermode=i" => sub {
69                                 $config{wrappermode}=possibly_foolish_untaint($_[1])
70                         },
71                         "plugin=s@" => sub {
72                                 push @{$config{plugin}}, $_[1];
73                         },
74                         "disable-plugin=s@" => sub {
75                                 push @{$config{disable_plugins}}, $_[1];
76                         },
77                         "set=s" => sub {
78                                 my ($var, $val)=split('=', $_[1], 2);
79                                 if (! defined $var || ! defined $val) {
80                                         die gettext("usage: --set var=value"), "\n";
81                                 }
82                                 $config{$var}=$val;
83                         },
84                         "version" => sub {
85                                 print "ikiwiki version $IkiWiki::version\n";
86                                 exit;
87                         },
88                 ) || usage();
89
90                 if (! $config{setup} && ! $config{render}) {
91                         loadplugins();
92                         usage() unless @ARGV == 2;
93                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
94                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
95                         checkconfig();
96                 }
97         }
98         else {
99                 # wrapper passes a full config structure in the environment
100                 # variable
101                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
102                 if ($@) {
103                         error("WRAPPED_OPTIONS: $@");
104                 }
105                 loadplugins();
106                 checkconfig();
107         }
108 } #}}}
109
110 sub main () { #{{{
111         getconfig();
112         
113         if ($config{setup}) {
114                 require IkiWiki::Setup;
115                 IkiWiki::Setup::load($config{setup});
116                 if (! $config{render} && ! $config{dumpsetup} &&
117                     (! $config{refresh} || $config{wrappers})) {
118                         debug(gettext("generating wrappers.."));
119                         require IkiWiki::Wrapper;
120                         my %origconfig=(%config);
121                         my @wrappers=@{$config{wrappers}};
122                         delete $config{wrappers};
123                         foreach my $wrapper (@wrappers) {
124                                 %config=(%origconfig,
125                                         rebuild => 0,
126                                         verbose => 0,
127                                         %{$wrapper},
128                                 );
129                                 checkconfig();
130                                 if (! $config{cgi} && ! $config{post_commit}) {
131                                         $config{post_commit}=1;
132                                 }
133                                 gen_wrapper();
134                         }
135                         %config=(%origconfig);
136                 }
137                 
138                 # setup implies a wiki rebuild by default
139                 if (! $config{refresh}) {
140                         $config{rebuild}=1;
141                 }
142                 
143                 # ignore syslog setting from setup file
144                 # while doing initial setup
145                 $config{syslog}=0;      
146                 
147                 loadplugins();
148                 checkconfig();
149         }
150
151         if ($config{dumpsetup}) {
152                 loadplugins();
153                 checkconfig();
154                 IkiWiki::Setup::dump($config{dumpsetup});
155         }
156         elsif ($config{wrapper}) {
157                 lockwiki();
158                 require IkiWiki::Wrapper;
159                 gen_wrapper();
160         }
161         elsif ($config{cgi}) {
162                 require IkiWiki::CGI;
163                 eval {cgi()};
164                 if ($@) {
165                         cgierror($@);
166                 }
167         }
168         elsif ($config{render}) {
169                 require IkiWiki::Render;
170                 commandline_render();
171         }
172         elsif ($config{post_commit} && ! commit_hook_enabled()) {
173                 # do nothing
174         }
175         else {
176                 if (! $config{refresh}) {
177                         debug(gettext("rebuilding wiki.."));
178                 }
179                 else {
180                         debug(gettext("refreshing wiki.."));
181                 }
182                 lockwiki();
183                 loadindex();
184                 require IkiWiki::Render;
185                 rcs_update();
186                 refresh();
187                 saveindex();
188                 debug(gettext("done"));
189         }
190 } #}}}
191
192 main;