]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - ikiwiki
* Add getopt hook type, this allows plugins to add new command-line options.
[git.ikiwiki.info.git] / ikiwiki
1 #!/usr/bin/perl -T
2 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
4 package IkiWiki;
5 use warnings;
6 use strict;
7 use lib '.'; # For use without installation, removed by Makefile.
8 use IkiWiki;
10 sub usage () { #{{{
11         die "usage: ikiwiki [options] source dest\n";
12 } #}}}
14 sub getconfig () { #{{{
15         if (! exists $ENV{WRAPPED_OPTIONS}) {
16                 %config=defaultconfig();
17                 eval q{use Getopt::Long};
18                 Getopt::Long::Configure('pass_through');
19                 GetOptions(
20                         "setup|s=s" => \$config{setup},
21                         "wikiname=s" => \$config{wikiname},
22                         "verbose|v!" => \$config{verbose},
23                         "rebuild!" => \$config{rebuild},
24                         "refresh!" => \$config{refresh},
25                         "getctime" => \$config{getctime},
26                         "wrappermode=i" => \$config{wrappermode},
27                         "rcs=s" => \$config{rcs},
28                         "no-rcs" => sub { $config{rcs}="" },
29                         "anonok!" => \$config{anonok},
30                         "rss!" => \$config{rss},
31                         "cgi!" => \$config{cgi},
32                         "discussion!" => \$config{discussion},
33                         "w3mmode!" => \$config{w3mmode},
34                         "notify!" => \$config{notify},
35                         "url=s" => \$config{url},
36                         "cgiurl=s" => \$config{cgiurl},
37                         "historyurl=s" => \$config{historyurl},
38                         "diffurl=s" => \$config{diffurl},
39                         "svnrepo" => \$config{svnrepo},
40                         "svnpath" => \$config{svnpath},
41                         "adminemail=s" => \$config{adminemail},
42                         "timeformat=s" => \$config{timeformat},
43                         "exclude=s@" => sub {
44                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
45                         },
46                         "adminuser=s@" => sub {
47                                 push @{$config{adminuser}}, $_[1]
48                         },
49                         "templatedir=s" => sub {
50                                 $config{templatedir}=possibly_foolish_untaint($_[1])
51                         },
52                         "underlaydir=s" => sub {
53                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
54                         },
55                         "wrapper:s" => sub {
56                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
57                         },
58                         "plugin=s@" => sub {
59                                 push @{$config{plugin}}, $_[1];
60                         },
61                         "disable-plugin=s@" => sub {
62                                 $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
63                         },
64                         "pingurl" => sub {
65                                 push @{$config{pingurl}}, $_[1];
66                         }
67                 ) || usage();
69                 if (! $config{setup}) {
70                         loadplugins();
71                         if (exists $hooks{getopt}) {
72                                 foreach my $id (keys %{$hooks{getopt}}) {
73                                         $hooks{getopt}{$id}{call}->();
74                                 }
75                         }
76                         if (grep /^-/, @ARGV) {
77                                 print STDERR "Unknown option: $_\n"
78                                         foreach grep /^-/, @ARGV;
79                                 usage();
80                         }
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 } #}}}
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 } #}}}
128 main;