2 $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
3 delete @ENV{qw{IFS CDPATH ENV BASH_ENV}};
9 use lib '.'; # For use in nonstandard directory, munged by Makefile.
13 die gettext("usage: ikiwiki [options] source dest"), "\n",
14 gettext(" ikiwiki --setup configfile"), "\n";
17 sub getconfig () { #{{{
18 if (! exists $ENV{WRAPPED_OPTIONS}) {
19 %config=defaultconfig();
20 eval q{use Getopt::Long};
21 Getopt::Long::Configure('pass_through');
24 require IkiWiki::Setup;
25 my $verbose=$config{verbose};
26 my $syslog=$config{syslog};
27 IkiWiki::Setup::load($_[1]);
28 $config{setupverbose}=$config{verbose};
29 $config{setupsyslog}=$config{syslog};
30 $config{verbose}=$verbose || $config{setupverbose};
31 $config{syslog}=$syslog;
34 "dumpsetup|s=s" => \$config{dumpsetup},
35 "wikiname=s" => \$config{wikiname},
36 "verbose|v!" => \$config{verbose},
37 "syslog!" => \$config{syslog},
38 "rebuild!" => \$config{rebuild},
39 "refresh!" => \$config{refresh},
40 "post-commit" => \$config{post_commit},
41 "render=s" => \$config{render},
42 "wrappers!" => \$config{genwrappers},
43 "usedirs!" => \$config{usedirs},
44 "prefix-directives!" => \$config{prefix_directives},
45 "getctime" => \$config{getctime},
46 "numbacklinks=i" => \$config{numbacklinks},
47 "rcs=s" => \$config{rcs},
48 "no-rcs" => sub { $config{rcs}="" },
49 "cgi!" => \$config{cgi},
50 "discussion!" => \$config{discussion},
51 "w3mmode!" => \$config{w3mmode},
52 "url=s" => \$config{url},
53 "cgiurl=s" => \$config{cgiurl},
54 "historyurl=s" => \$config{historyurl},
55 "diffurl=s" => \$config{diffurl},
56 "svnpath" => \$config{svnpath},
57 "adminemail=s" => \$config{adminemail},
58 "timeformat=s" => \$config{timeformat},
59 "sslcookie!" => \$config{sslcookie},
60 "userdir=s" => \$config{userdir},
61 "htmlext=s" => \$config{htmlext},
62 "libdir=s" => \$config{libdir},
64 push @{$config{wiki_file_prune_regexps}}, $_[1];
66 "adminuser=s@" => sub {
67 push @{$config{adminuser}}, $_[1]
69 "templatedir=s" => sub {
70 $config{templatedir}=possibly_foolish_untaint($_[1])
72 "underlaydir=s" => sub {
73 $config{underlaydir}=possibly_foolish_untaint($_[1])
76 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
78 "wrappermode=i" => sub {
79 $config{wrappermode}=possibly_foolish_untaint($_[1])
82 push @{$config{add_plugins}}, $_[1];
84 "disable-plugin=s@" => sub {
85 push @{$config{disable_plugins}}, $_[1];
88 my ($var, $val)=split('=', $_[1], 2);
89 if (! defined $var || ! defined $val) {
90 die gettext("usage: --set var=value"), "\n";
95 print "ikiwiki version $IkiWiki::version\n";
98 "help|h" => sub { $SIG{__WARN__}=sub {}; die },
101 if (! $config{setup} && ! $config{render}) {
104 $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
105 $config{destdir} = possibly_foolish_untaint(shift @ARGV);
109 usage() unless $config{dumpsetup};
114 # wrapper passes a full config structure in the environment
116 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
118 error("WRAPPED_OPTIONS: $@");
120 delete $ENV{WRAPPED_OPTIONS};
122 # optimisation for no-op post_commit
123 if ($config{post_commit} && ! commit_hook_enabled()) {
135 if ($config{setup}) {
136 delete $config{setup};
140 if (@{$config{wrappers}} &&
141 ! $config{render} && ! $config{dumpsetup} &&
142 (! $config{refresh} || $config{genwrappers})) {
143 debug(gettext("generating wrappers.."));
144 require IkiWiki::Wrapper;
145 my %origconfig=(%config);
146 foreach my $wrapper (@{$config{wrappers}}) {
147 %config=(%origconfig, %{$wrapper});
148 $config{verbose}=$config{setupverbose}
149 if exists $config{setupverbose};
150 $config{syslog}=$config{setupsyslog}
151 if exists $config{setupsyslog};
152 delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)};
154 if (! $config{cgi} && ! $config{post_commit}) {
155 $config{post_commit}=1;
159 %config=(%origconfig);
162 # setup implies a wiki rebuild by default
163 if (! $config{refresh}) {
168 if ($config{dumpsetup}) {
169 $config{srdir}=$config{destdir}="";
170 require IkiWiki::Setup;
171 IkiWiki::Setup::dump($config{dumpsetup});
173 elsif ($config{wrapper}) {
175 require IkiWiki::Wrapper;
178 elsif ($config{cgi}) {
179 require IkiWiki::CGI;
185 elsif ($config{render}) {
186 require IkiWiki::Render;
187 commandline_render();
189 elsif ($config{post_commit} && ! commit_hook_enabled()) {
193 if ($config{rebuild}) {
194 debug(gettext("rebuilding wiki.."));
197 debug(gettext("refreshing wiki.."));
201 require IkiWiki::Render;
205 debug(gettext("done"));