]> sipb.mit.edu Git - ikiwiki.git/blob - ikiwiki
tone back claims of what tidy can do, it's not perfect
[ikiwiki.git] / ikiwiki
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 use warnings;
7 use strict;
8 use lib '.'; # For use without installation, removed by Makefile.
9 use IkiWiki;
10
11 sub usage () { #{{{
12         die "usage: ikiwiki [options] source dest\n";
13 } #}}}
14
15 sub getconfig () { #{{{
16         if (! exists $ENV{WRAPPED_OPTIONS}) {
17                 %config=defaultconfig();
18                 eval q{use Getopt::Long};
19                 Getopt::Long::Configure('pass_through');
20                 GetOptions(
21                         "setup|s=s" => \$config{setup},
22                         "wikiname=s" => \$config{wikiname},
23                         "verbose|v!" => \$config{verbose},
24                         "rebuild!" => \$config{rebuild},
25                         "refresh!" => \$config{refresh},
26                         "wrappers!" => \$config{wrappers},
27                         "getctime" => \$config{getctime},
28                         "wrappermode=i" => \$config{wrappermode},
29                         "rcs=s" => \$config{rcs},
30                         "no-rcs" => sub { $config{rcs}="" },
31                         "anonok!" => \$config{anonok},
32                         "rss!" => \$config{rss},
33                         "cgi!" => \$config{cgi},
34                         "discussion!" => \$config{discussion},
35                         "w3mmode!" => \$config{w3mmode},
36                         "notify!" => \$config{notify},
37                         "url=s" => \$config{url},
38                         "cgiurl=s" => \$config{cgiurl},
39                         "historyurl=s" => \$config{historyurl},
40                         "diffurl=s" => \$config{diffurl},
41                         "svnrepo" => \$config{svnrepo},
42                         "svnpath" => \$config{svnpath},
43                         "adminemail=s" => \$config{adminemail},
44                         "timeformat=s" => \$config{timeformat},
45                         "exclude=s@" => sub {
46                                 $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
47                         },
48                         "adminuser=s@" => sub {
49                                 push @{$config{adminuser}}, $_[1]
50                         },
51                         "templatedir=s" => sub {
52                                 $config{templatedir}=possibly_foolish_untaint($_[1])
53                         },
54                         "underlaydir=s" => sub {
55                                 $config{underlaydir}=possibly_foolish_untaint($_[1])
56                         },
57                         "wrapper:s" => sub {
58                                 $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
59                         },
60                         "plugin=s@" => sub {
61                                 push @{$config{plugin}}, $_[1];
62                         },
63                         "disable-plugin=s@" => sub {
64                                 $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
65                         },
66                         "pingurl" => sub {
67                                 push @{$config{pingurl}}, $_[1];
68                         }
69                 ) || usage();
70
71                 if (! $config{setup}) {
72                         loadplugins();
73                         usage() unless @ARGV == 2;
74                         $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
75                         $config{destdir} = possibly_foolish_untaint(shift @ARGV);
76                         checkconfig();
77                 }
78         }
79         else {
80                 # wrapper passes a full config structure in the environment
81                 # variable
82                 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
83                 if ($@) {
84                         error("WRAPPED_OPTIONS: $@");
85                 }
86                 loadplugins();
87                 checkconfig();
88         }
89 } #}}}
90
91 sub main () { #{{{
92         getconfig();
93         
94         if ($config{cgi}) {
95                 lockwiki();
96                 loadindex();
97                 require IkiWiki::CGI;
98                 cgi();
99         }
100         elsif ($config{setup}) {
101                 require IkiWiki::Setup;
102                 setup();
103         }
104         elsif ($config{wrapper}) {
105                 lockwiki();
106                 require IkiWiki::Wrapper;
107                 gen_wrapper();
108         }
109         else {
110                 lockwiki();
111                 loadindex();
112                 require IkiWiki::Render;
113                 rcs_update();
114                 refresh();
115                 rcs_notify() if $config{notify};
116                 saveindex();
117         }
118 } #}}}
119
120 main;