]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki.in
improve l10n
[ikiwiki.git] / ikiwiki.in
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
7 use warnings;
8 use strict;
9 use lib '.'; # For use in nonstandard directory, munged by Makefile.
10 use IkiWiki;
11
12 sub usage () { #{{{
13         die gettext("usage: ikiwiki [options] source dest"), "\n";
14 } #}}}
15
16 sub getconfig () { #{{{
17         if (! exists $ENV{WRAPPED_OPTIONS}) {
18                 %config=defaultconfig();
19                 eval q{use Getopt::Long};
20                 Getopt::Long::Configure('pass_through');
21                 GetOptions(
22                         "setup|s=s" => \$config{setup},
23                         "wikiname=s" => \$config{wikiname},
24                         "verbose|v!" => \$config{verbose},
25                         "syslog!" => \$config{syslog},
26                         "rebuild!" => \$config{rebuild},
27                         "refresh!" => \$config{refresh},
28                         "render=s" => \$config{render},
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                         "cgi!" => \$config{cgi},
35                         "discussion!" => \$config{discussion},
36                         "w3mmode!" => \$config{w3mmode},
37                         "notify!" => \$config{notify},
38                         "url=s" => \$config{url},
39                         "cgiurl=s" => \$config{cgiurl},
40                         "historyurl=s" => \$config{historyurl},
41                         "diffurl=s" => \$config{diffurl},
42                         "svnrepo" => \$config{svnrepo},
43                         "svnpath" => \$config{svnpath},
44                         "adminemail=s" => \$config{adminemail},
45                         "timeformat=s" => \$config{timeformat},
46                         "sslcookie!" => \$config{sslcookie},
47                         "httpauth!" => \$config{httpauth},
48                         "userdir=s" => \$config{userdir},
49                         "exclude=s@" => sub {
50                                 push @{$config{wiki_file_prune_regexps}}, $_[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                                 push @{$config{disable_plugins}}, $_[1];
69                         },
70                         "pingurl=s" => sub {
71                                 push @{$config{pingurl}}, $_[1];
72                         },
73                         "version" => sub {
74                                 print "ikiwiki version $IkiWiki::version\n";
75                                 exit;
76                         },
77                 ) || usage();
78
79                 if (! $config{setup} && ! $config{render}) {
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                 loadindex();
104                 require IkiWiki::CGI;
105                 cgi();
106         }
107         elsif ($config{setup}) {
108                 require IkiWiki::Setup;
109                 setup();
110         }
111         elsif ($config{wrapper}) {
112                 lockwiki();
113                 require IkiWiki::Wrapper;
114                 gen_wrapper();
115         }
116         elsif ($config{render}) {
117                 require IkiWiki::Render;
118                 commandline_render();
119         }
120         elsif ($config{post_commit} && ! commit_hook_enabled()) {
121                 if ($config{notify}) {
122                         loadindex();
123                         rcs_notify();
124                 }
125         }
126         else {
127                 lockwiki();
128                 loadindex();
129                 require IkiWiki::Render;
130                 rcs_update();
131                 refresh();
132                 rcs_notify() if $config{notify};
133                 saveindex();
134         }
135 } #}}}
136
137 main;