]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki.pl
* Support Text::Markdown from CPAN, which has a different interface from
[ikiwiki.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}};
4
5 package IkiWiki;
6 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
7
8 use warnings;
9 use strict;
10 use lib '.'; # For use without installation, removed by Makefile.
11 use IkiWiki;
12
13 sub usage () { #{{{
14         die "usage: ikiwiki [options] source dest\n";
15 } #}}}
16
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                         "wrappers!" => \$config{wrappers},
30                         "getctime" => \$config{getctime},
31                         "wrappermode=i" => \$config{wrappermode},
32                         "rcs=s" => \$config{rcs},
33                         "no-rcs" => sub { $config{rcs}="" },
34                         "anonok!" => \$config{anonok},
35                         "rss!" => \$config{rss},
36                         "cgi!" => \$config{cgi},
37                         "discussion!" => \$config{discussion},
38                         "w3mmode!" => \$config{w3mmode},
39                         "notify!" => \$config{notify},
40                         "url=s" => \$config{url},
41                         "cgiurl=s" => \$config{cgiurl},
42                         "historyurl=s" => \$config{historyurl},
43                         "diffurl=s" => \$config{diffurl},
44                         "svnrepo" => \$config{svnrepo},
45                         "svnpath" => \$config{svnpath},
46                         "adminemail=s" => \$config{adminemail},
47                         "timeformat=s" => \$config{timeformat},
48                         "sslcookie!" => \$config{sslcookie},
49                         "exclude=s@" => sub {
50                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
51                         },
52                         "adminuser=s@" => sub {
53                                 push @{$config{adminuser}}, $_[1]
54                         },
55                         "templatedir=s" => sub {
56                                 $config{templatedir}=possibly_foolish_untaint($_[1])
57                         },
58                         "underlaydir=s" => sub {
59                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
60                         },
61                         "wrapper:s" => sub {
62                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
63                         },
64                         "plugin=s@" => sub {
65                                 push @{$config{plugin}}, $_[1];
66                         },
67                         "disable-plugin=s@" => sub {
68                                 $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
69                         },
70                         "pingurl" => sub {
71                                 push @{$config{pingurl}}, $_[1];
72                         },
73                         "version" => sub {
74                                 print "ikiwiki version $version\n";
75                                 exit;
76                         },
77                 ) || usage();
78
79                 if (! $config{setup}) {
80                         loadplugins();
81                         usage() unless @ARGV == 2;
82                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
83                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
84                         checkconfig();
85                 }
86         }
87         else {
88                 # wrapper passes a full config structure in the environment
89                 # variable
90                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
91                 if ($@) {
92                         error("WRAPPED_OPTIONS: $@");
93                 }
94                 loadplugins();
95                 checkconfig();
96         }
97 } #}}}
98
99 sub main () { #{{{
100         getconfig();
101         
102         if ($config{cgi}) {
103                 lockwiki();
104                 loadindex();
105                 require IkiWiki::CGI;
106                 cgi();
107         }
108         elsif ($config{setup}) {
109                 require IkiWiki::Setup;
110                 setup();
111         }
112         elsif ($config{wrapper}) {
113                 lockwiki();
114                 require IkiWiki::Wrapper;
115                 gen_wrapper();
116         }
117         else {
118                 lockwiki();
119                 loadindex();
120                 require IkiWiki::Render;
121                 rcs_update();
122                 refresh();
123                 rcs_notify() if $config{notify};
124                 saveindex();
125         }
126 } #}}}
127
128 main;