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";
16 sub getconfig () { #{{{
17 if (! exists $ENV{WRAPPED_OPTIONS}) {
18 %config=defaultconfig();
19 eval q{use Getopt::Long};
20 Getopt::Long::Configure('pass_through');
23 require IkiWiki::Setup;
24 my $verbose=$config{verbose};
25 my $syslog=$config{syslog};
26 IkiWiki::Setup::load($_[1]);
27 $config{setupverbose}=$config{verbose};
28 $config{setupsyslog}=$config{syslog};
29 $config{verbose}=$verbose || $config{setupverbose};
30 $config{syslog}=$syslog;
33 "dumpsetup|s=s" => \$config{dumpsetup},
34 "wikiname=s" => \$config{wikiname},
35 "verbose|v!" => \$config{verbose},
36 "syslog!" => \$config{syslog},
37 "rebuild!" => \$config{rebuild},
38 "refresh!" => \$config{refresh},
39 "post-commit" => \$config{post_commit},
40 "render=s" => \$config{render},
41 "wrappers!" => \$config{genwrappers},
42 "usedirs!" => \$config{usedirs},
43 "prefix-directives!" => \$config{prefix_directives},
44 "getctime" => \$config{getctime},
45 "numbacklinks=i" => \$config{numbacklinks},
46 "rcs=s" => \$config{rcs},
47 "no-rcs" => sub { $config{rcs}="" },
48 "cgi!" => \$config{cgi},
49 "discussion!" => \$config{discussion},
50 "w3mmode!" => \$config{w3mmode},
51 "url=s" => \$config{url},
52 "cgiurl=s" => \$config{cgiurl},
53 "historyurl=s" => \$config{historyurl},
54 "diffurl=s" => \$config{diffurl},
55 "svnpath" => \$config{svnpath},
56 "adminemail=s" => \$config{adminemail},
57 "timeformat=s" => \$config{timeformat},
58 "sslcookie!" => \$config{sslcookie},
59 "userdir=s" => \$config{userdir},
60 "htmlext=s" => \$config{htmlext},
61 "libdir=s" => \$config{libdir},
63 push @{$config{wiki_file_prune_regexps}}, $_[1];
65 "adminuser=s@" => sub {
66 push @{$config{adminuser}}, $_[1]
68 "templatedir=s" => sub {
69 $config{templatedir}=possibly_foolish_untaint($_[1])
71 "underlaydir=s" => sub {
72 $config{underlaydir}=possibly_foolish_untaint($_[1])
75 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
77 "wrappermode=i" => sub {
78 $config{wrappermode}=possibly_foolish_untaint($_[1])
81 push @{$config{add_plugins}}, $_[1];
83 "disable-plugin=s@" => sub {
84 push @{$config{disable_plugins}}, $_[1];
87 my ($var, $val)=split('=', $_[1], 2);
88 if (! defined $var || ! defined $val) {
89 die gettext("usage: --set var=value"), "\n";
94 print "ikiwiki version $IkiWiki::version\n";
99 if (! $config{setup} && ! $config{render}) {
102 $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
103 $config{destdir} = possibly_foolish_untaint(shift @ARGV);
107 usage() unless $config{dumpsetup};
112 # wrapper passes a full config structure in the environment
114 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
116 error("WRAPPED_OPTIONS: $@");
118 delete $ENV{WRAPPED_OPTIONS};
127 if ($config{setup}) {
128 delete $config{setup};
132 if (@{$config{wrappers}} &&
133 ! $config{render} && ! $config{dumpsetup} &&
134 (! $config{refresh} || $config{genwrappers})) {
135 debug(gettext("generating wrappers.."));
136 require IkiWiki::Wrapper;
137 my %origconfig=(%config);
138 foreach my $wrapper (@{$config{wrappers}}) {
139 %config=(%origconfig, %{$wrapper});
140 $config{verbose}=$config{setupverbose}
141 if exists $config{setupverbose};
142 $config{syslog}=$config{setupsyslog}
143 if exists $config{setupsyslog};
144 delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)};
146 if (! $config{cgi} && ! $config{post_commit}) {
147 $config{post_commit}=1;
151 %config=(%origconfig);
154 # setup implies a wiki rebuild by default
155 if (! $config{refresh}) {
160 if ($config{dumpsetup}) {
161 $config{srdir}=$config{destdir}="";
162 require IkiWiki::Setup;
163 IkiWiki::Setup::dump($config{dumpsetup});
165 elsif ($config{wrapper}) {
167 require IkiWiki::Wrapper;
170 elsif ($config{cgi}) {
171 require IkiWiki::CGI;
177 elsif ($config{render}) {
178 require IkiWiki::Render;
179 commandline_render();
181 elsif ($config{post_commit} && ! commit_hook_enabled()) {
185 if (! $config{refresh}) {
186 debug(gettext("rebuilding wiki.."));
189 debug(gettext("refreshing wiki.."));
193 require IkiWiki::Render;
197 debug(gettext("done"));