]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki.in
* Add a libdir config option to let ikiwiki load perl modules, including
[git.ikiwiki.info.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}};
5 package IkiWiki;
7 use warnings;
8 use strict;
9 use lib '.'; # For use in nonstandard directory, munged by Makefile.
10 use IkiWiki;
12 sub usage () { #{{{
13         die gettext("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                         "post-commit" => \$config{post_commit},
29                         "render=s" => \$config{render},
30                         "wrappers!" => \$config{wrappers},
31                         "usedirs!" => \$config{usedirs},
32                         "getctime" => \$config{getctime},
33                         "wrappermode=i" => \$config{wrappermode},
34                         "numbacklinks=i" => \$config{numbacklinks},
35                         "rcs=s" => \$config{rcs},
36                         "no-rcs" => sub { $config{rcs}="" },
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                         "userdir=s" => \$config{userdir},
52                         "htmlext=s" => \$config{htmlext},
53                         "libdir" => \$config{libdir},
54                         "exclude=s@" => sub {
55                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
56                         },
57                         "adminuser=s@" => sub {
58                                 push @{$config{adminuser}}, $_[1]
59                         },
60                         "templatedir=s" => sub {
61                                 $config{templatedir}=possibly_foolish_untaint($_[1])
62                         },
63                         "underlaydir=s" => sub {
64                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
65                         },
66                         "wrapper:s" => sub {
67                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
68                         },
69                         "plugin=s@" => sub {
70                                 push @{$config{plugin}}, $_[1];
71                         },
72                         "disable-plugin=s@" => sub {
73                                 push @{$config{disable_plugins}}, $_[1];
74                         },
75                         "pingurl=s" => sub {
76                                 push @{$config{pingurl}}, $_[1];
77                         },
78                         "version" => sub {
79                                 print "ikiwiki version $IkiWiki::version\n";
80                                 exit;
81                         },
82                 ) || usage();
84                 if (! $config{setup} && ! $config{render}) {
85                         loadplugins();
86                         usage() unless @ARGV == 2;
87                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
88                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
89                         checkconfig();
90                 }
91         }
92         else {
93                 # wrapper passes a full config structure in the environment
94                 # variable
95                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
96                 if ($@) {
97                         error("WRAPPED_OPTIONS: $@");
98                 }
99                 loadplugins();
100                 checkconfig();
101         }
102 } #}}}
104 sub main () { #{{{
105         getconfig();
106         
107         if ($config{cgi}) {
108                 loadindex();
109                 require IkiWiki::CGI;
110                 cgi();
111         }
112         elsif ($config{setup}) {
113                 require IkiWiki::Setup;
114                 setup();
115         }
116         elsif ($config{wrapper}) {
117                 lockwiki();
118                 require IkiWiki::Wrapper;
119                 gen_wrapper();
120         }
121         elsif ($config{render}) {
122                 require IkiWiki::Render;
123                 commandline_render();
124         }
125         elsif ($config{post_commit} && ! commit_hook_enabled()) {
126                 if ($config{notify}) {
127                         loadindex();
128                         rcs_notify();
129                 }
130         }
131         else {
132                 lockwiki();
133                 loadindex();
134                 require IkiWiki::Render;
135                 rcs_update();
136                 refresh();
137                 rcs_notify() if $config{notify};
138                 saveindex();
139         }
140 } #}}}
142 main;