]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki.pl
releasing version 1.27
[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;
6 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
8 use warnings;
9 use strict;
10 use lib '.'; # For use without installation, removed by Makefile.
11 use IkiWiki;
13 sub usage () { #{{{
14         die "usage: ikiwiki [options] source dest\n";
15 } #}}}
17 sub getconfig () { #{{{
18         if (! exists $ENV{WRAPPED_OPTIONS}) {
19                 %config=defaultconfig();
20                 eval q{use Getopt::Long};
21                 Getopt::Long::Configure('pass_through');
22                 GetOptions(
23                         "setup|s=s" => \$config{setup},
24                         "wikiname=s" => \$config{wikiname},
25                         "verbose|v!" => \$config{verbose},
26                         "syslog!" => \$config{syslog},
27                         "rebuild!" => \$config{rebuild},
28                         "refresh!" => \$config{refresh},
29                         "render=s" => \$config{render},
30                         "wrappers!" => \$config{wrappers},
31                         "getctime" => \$config{getctime},
32                         "wrappermode=i" => \$config{wrappermode},
33                         "rcs=s" => \$config{rcs},
34                         "no-rcs" => sub { $config{rcs}="" },
35                         "anonok!" => \$config{anonok},
36                         "rss!" => \$config{rss},
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                         "exclude=s@" => sub {
51                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
52                         },
53                         "adminuser=s@" => sub {
54                                 push @{$config{adminuser}}, $_[1]
55                         },
56                         "templatedir=s" => sub {
57                                 $config{templatedir}=possibly_foolish_untaint($_[1])
58                         },
59                         "underlaydir=s" => sub {
60                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
61                         },
62                         "wrapper:s" => sub {
63                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
64                         },
65                         "plugin=s@" => sub {
66                                 push @{$config{plugin}}, $_[1];
67                         },
68                         "disable-plugin=s@" => sub {
69                                 $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
70                         },
71                         "pingurl" => sub {
72                                 push @{$config{pingurl}}, $_[1];
73                         },
74                         "version" => sub {
75                                 print "ikiwiki version $version\n";
76                                 exit;
77                         },
78                 ) || usage();
80                 if (! $config{setup} && ! $config{render}) {
81                         loadplugins();
82                         usage() unless @ARGV == 2;
83                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
84                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
85                         checkconfig();
86                 }
87         }
88         else {
89                 # wrapper passes a full config structure in the environment
90                 # variable
91                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
92                 if ($@) {
93                         error("WRAPPED_OPTIONS: $@");
94                 }
95                 loadplugins();
96                 checkconfig();
97         }
98 } #}}}
100 sub main () { #{{{
101         getconfig();
102         
103         if ($config{cgi}) {
104                 lockwiki();
105                 loadindex();
106                 require IkiWiki::CGI;
107                 cgi();
108         }
109         elsif ($config{setup}) {
110                 require IkiWiki::Setup;
111                 setup();
112         }
113         elsif ($config{wrapper}) {
114                 lockwiki();
115                 require IkiWiki::Wrapper;
116                 gen_wrapper();
117         }
118         elsif ($config{render}) {
119                 require IkiWiki::Render;
120                 commandline_render();
121         }
122         else {
123                 lockwiki();
124                 loadindex();
125                 require IkiWiki::Render;
126                 rcs_update();
127                 refresh();
128                 rcs_notify() if $config{notify};
129                 saveindex();
130         }
131 } #}}}
133 main;