]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki.pl
releasing version 1.18
[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                         "rebuild!" => \$config{rebuild},
27                         "refresh!" => \$config{refresh},
28                         "wrappers!" => \$config{wrappers},
29                         "getctime" => \$config{getctime},
30                         "wrappermode=i" => \$config{wrappermode},
31                         "rcs=s" => \$config{rcs},
32                         "no-rcs" => sub { $config{rcs}="" },
33                         "anonok!" => \$config{anonok},
34                         "rss!" => \$config{rss},
35                         "cgi!" => \$config{cgi},
36                         "discussion!" => \$config{discussion},
37                         "w3mmode!" => \$config{w3mmode},
38                         "notify!" => \$config{notify},
39                         "url=s" => \$config{url},
40                         "cgiurl=s" => \$config{cgiurl},
41                         "historyurl=s" => \$config{historyurl},
42                         "diffurl=s" => \$config{diffurl},
43                         "svnrepo" => \$config{svnrepo},
44                         "svnpath" => \$config{svnpath},
45                         "adminemail=s" => \$config{adminemail},
46                         "timeformat=s" => \$config{timeformat},
47                         "exclude=s@" => sub {
48                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
49                         },
50                         "adminuser=s@" => sub {
51                                 push @{$config{adminuser}}, $_[1]
52                         },
53                         "templatedir=s" => sub {
54                                 $config{templatedir}=possibly_foolish_untaint($_[1])
55                         },
56                         "underlaydir=s" => sub {
57                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
58                         },
59                         "wrapper:s" => sub {
60                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
61                         },
62                         "plugin=s@" => sub {
63                                 push @{$config{plugin}}, $_[1];
64                         },
65                         "disable-plugin=s@" => sub {
66                                 $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
67                         },
68                         "pingurl" => sub {
69                                 push @{$config{pingurl}}, $_[1];
70                         },
71                         "version" => sub {
72                                 print "ikiwiki version $version\n";
73                                 exit;
74                         },
75                 ) || usage();
77                 if (! $config{setup}) {
78                         loadplugins();
79                         usage() unless @ARGV == 2;
80                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
81                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
82                         checkconfig();
83                 }
84         }
85         else {
86                 # wrapper passes a full config structure in the environment
87                 # variable
88                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
89                 if ($@) {
90                         error("WRAPPED_OPTIONS: $@");
91                 }
92                 loadplugins();
93                 checkconfig();
94         }
95 } #}}}
97 sub main () { #{{{
98         getconfig();
99         
100         if ($config{cgi}) {
101                 lockwiki();
102                 loadindex();
103                 require IkiWiki::CGI;
104                 cgi();
105         }
106         elsif ($config{setup}) {
107                 require IkiWiki::Setup;
108                 setup();
109         }
110         elsif ($config{wrapper}) {
111                 lockwiki();
112                 require IkiWiki::Wrapper;
113                 gen_wrapper();
114         }
115         else {
116                 lockwiki();
117                 loadindex();
118                 require IkiWiki::Render;
119                 rcs_update();
120                 refresh();
121                 rcs_notify() if $config{notify};
122                 saveindex();
123         }
124 } #}}}
126 main;