web commit by ThomasSchwinge
[ikiwiki] / ikiwiki
1 #!/usr/bin/perl -T
2 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
3
4 package IkiWiki;
5 use warnings;
6 use strict;
7 use lib '.'; # For use without installation, removed by Makefile.
8 use IkiWiki;
9
10 sub usage () { #{{{
11         die "usage: ikiwiki [options] source dest\n";
12 } #}}}
13
14 sub getconfig () { #{{{
15         if (! exists $ENV{WRAPPED_OPTIONS}) {
16                 %config=(
17                         wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
18                         wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
19                         wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/,
20                         wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
21                         verbose => 0,
22                         wikiname => "wiki",
23                         default_pageext => ".mdwn",
24                         cgi => 0,
25                         rcs => 'svn',
26                         notify => 0,
27                         url => '',
28                         cgiurl => '',
29                         historyurl => '',
30                         diffurl => '',
31                         anonok => 0,
32                         rss => 0,
33                         sanitize => 1,
34                         rebuild => 0,
35                         refresh => 0,
36                         getctime => 0,
37                         wrapper => undef,
38                         wrappermode => undef,
39                         svnrepo => undef,
40                         svnpath => "trunk",
41                         srcdir => undef,
42                         destdir => undef,
43                         templatedir => "/usr/share/ikiwiki/templates",
44                         underlaydir => "/usr/share/ikiwiki/basewiki",
45                         setup => undef,
46                         adminuser => undef,
47                         adminemail => undef,
48                         plugin => [qw{inline}],
49                         headercontent => '',
50                 );
51
52                 eval q{use Getopt::Long};
53                 GetOptions(
54                         "setup|s=s" => \$config{setup},
55                         "wikiname=s" => \$config{wikiname},
56                         "verbose|v!" => \$config{verbose},
57                         "rebuild!" => \$config{rebuild},
58                         "refresh!" => \$config{refresh},
59                         "getctime" => \$config{getctime},
60                         "wrappermode=i" => \$config{wrappermode},
61                         "rcs=s" => \$config{rcs},
62                         "no-rcs" => sub { $config{rcs}="" },
63                         "anonok!" => \$config{anonok},
64                         "rss!" => \$config{rss},
65                         "cgi!" => \$config{cgi},
66                         "notify!" => \$config{notify},
67                         "sanitize!" => \$config{sanitize},
68                         "url=s" => \$config{url},
69                         "cgiurl=s" => \$config{cgiurl},
70                         "historyurl=s" => \$config{historyurl},
71                         "diffurl=s" => \$config{diffurl},
72                         "svnrepo" => \$config{svnrepo},
73                         "svnpath" => \$config{svnpath},
74                         "adminemail=s" => \$config{adminemail},
75                         "exclude=s@" => sub {
76                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[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] ? $_[1] : "ikiwiki-wrap"
89                         },
90                         "plugin=s@" => sub {
91                                 push @{$config{plugin}}, $_[1];
92                         }
93                 ) || usage();
94
95                 if (! $config{setup}) {
96                         usage() unless @ARGV == 2;
97                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
98                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
99                         checkconfig();
100                 }
101         }
102         else {
103                 # wrapper passes a full config structure in the environment
104                 # variable
105                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
106                 if ($@) {
107                         error("WRAPPED_OPTIONS: $@");
108                 }
109                 checkconfig();
110         }
111 } #}}}
112
113 sub main () { #{{{
114         getconfig();
115         
116         if ($config{cgi}) {
117                 lockwiki();
118                 loadindex();
119                 require IkiWiki::CGI;
120                 cgi();
121         }
122         elsif ($config{setup}) {
123                 require IkiWiki::Setup;
124                 setup();
125         }
126         elsif ($config{wrapper}) {
127                 lockwiki();
128                 require IkiWiki::Wrapper;
129                 gen_wrapper();
130         }
131         else {
132                 lockwiki();
133                 loadindex();
134                 require IkiWiki::Render;
135                 rcs_update();
136                 rcs_getctime() if $config{getctime};
137                 refresh();
138                 rcs_notify() if $config{notify};
139                 saveindex();
140         }
141 } #}}}
142
143 main;