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";
18 require IkiWiki::Setup;
19 my $verbose=$config{verbose};
20 my $syslog=$config{syslog};
21 IkiWiki::Setup::load($_[1]);
22 $config{setupverbose}=$config{verbose};
23 $config{setupsyslog}=$config{syslog};
24 $config{verbose}=$verbose || $config{setupverbose};
25 $config{syslog}=$syslog;
30 if (! exists $ENV{WRAPPED_OPTIONS}) {
31 %config=defaultconfig();
32 eval q{use Getopt::Long};
33 Getopt::Long::Configure('pass_through');
35 "setup|s=s" => \&setup,
36 "dumpsetup|s=s" => \$config{dumpsetup},
37 "changesetup|s=s" => sub {
38 $config{changesetup}=$_[1];
39 $config{genwrappers}=1;
43 "wikiname=s" => \$config{wikiname},
44 "verbose|v!" => \$config{verbose},
45 "syslog!" => \$config{syslog},
46 "rebuild!" => \$config{rebuild},
47 "refresh!" => \$config{refresh},
48 "clean!" => \$config{clean},
49 "post-commit" => \$config{post_commit},
50 "render=s" => \$config{render},
51 "wrappers!" => \$config{genwrappers},
52 "wrappergroup=s" => \$config{wrappergroup},
53 "usedirs!" => \$config{usedirs},
54 "prefix-directives!" => \$config{prefix_directives},
55 "getctime" => \$config{gettime},
56 "gettime!" => \$config{gettime},
57 "numbacklinks=i" => \$config{numbacklinks},
58 "rcs=s" => \$config{rcs},
59 "no-rcs" => sub { $config{rcs}="" },
60 "cgi!" => \$config{cgi},
61 "discussion!" => \$config{discussion},
62 "w3mmode!" => \$config{w3mmode},
63 "url=s" => \$config{url},
64 "cgiurl=s" => \$config{cgiurl},
65 "historyurl=s" => \$config{historyurl},
66 "diffurl=s" => \$config{diffurl},
67 "svnpath" => \$config{svnpath},
68 "adminemail=s" => \$config{adminemail},
69 "timeformat=s" => \$config{timeformat},
70 "sslcookie!" => \$config{sslcookie},
71 "userdir=s" => \$config{userdir},
72 "htmlext=s" => \$config{htmlext},
73 "libdir=s" => \$config{libdir},
75 push @{$config{wiki_file_prune_regexps}}, $_[1];
78 $config{include}=defined $config{include} && length $config{include} ? "$config{include}|$_[1]" : $_[1];
80 "adminuser=s@" => sub {
81 push @{$config{adminuser}}, $_[1]
83 "templatedir=s" => sub {
84 $config{templatedir}=possibly_foolish_untaint($_[1])
86 "underlaydir=s" => sub {
87 $config{underlaydir}=possibly_foolish_untaint($_[1])
90 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
92 "wrappermode=i" => sub {
93 $config{wrappermode}=possibly_foolish_untaint($_[1])
96 push @{$config{add_plugins}}, $_[1]
97 unless grep { $_ eq $_[1] } @{$config{add_plugins}};
99 "disable-plugin=s@" => sub {
100 push @{$config{disable_plugins}}, $_[1];
103 my ($var, $val)=split('=', $_[1], 2);
104 if (! defined $var || ! defined $val) {
105 die gettext("usage: --set var=value"), "\n";
109 "set-yaml=s" => sub {
110 my ($var, $val)=split('=', $_[1], 2);
111 if (! defined $var || ! defined $val) {
112 die gettext("usage: --set-yaml var=value"), "\n";
114 eval q{use YAML::Any};
115 eval q{use YAML} if $@;
117 eval q{$YAML::Syck::ImplicitUnicode=1};
118 $config{$var}=Load($val."\n");
121 print "ikiwiki version $IkiWiki::version\n";
124 "help|h" => sub { $SIG{__WARN__}=sub {}; die },
127 if (! $config{setup}) {
130 $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
131 $config{destdir} = possibly_foolish_untaint(shift @ARGV);
135 usage() unless $config{dumpsetup};
140 # wrapper passes a full config structure in the environment
142 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
144 error("WRAPPED_OPTIONS: $@");
146 delete $ENV{WRAPPED_OPTIONS};
156 if ($config{setup}) {
157 delete $config{setup};
161 if (@{$config{wrappers}} &&
162 ! $config{render} && ! $config{dumpsetup} &&
164 ((! $config{refresh} && ! $config{post_commit})
165 || $config{genwrappers})) {
166 debug(gettext("generating wrappers.."));
167 require IkiWiki::Wrapper;
168 my %origconfig=(%config);
169 foreach my $wrapper (@{$config{wrappers}}) {
170 %config=(%origconfig, %{$wrapper});
171 $config{verbose}=$config{setupverbose}
172 if exists $config{setupverbose};
173 $config{syslog}=$config{setupsyslog}
174 if exists $config{setupsyslog};
175 delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)};
177 if (! $config{cgi} && ! $config{post_commit} &&
178 ! $config{test_receive}) {
179 $config{post_commit}=1;
183 %config=(%origconfig);
186 # setup implies a wiki rebuild by default
187 if (! $config{refresh} && ! $config{render} &&
188 ! $config{post_commit} && ! $config{clean}) {
193 if ($config{changesetup}) {
194 require IkiWiki::Setup;
195 IkiWiki::Setup::dump($config{changesetup});
198 if ($config{dumpsetup}) {
199 $config{srcdir}="" if ! defined $config{srcdir};
200 $config{destdir}="" if ! defined $config{destdir};
201 $config{syslog}=1 if $config{setupsyslog};
202 require IkiWiki::Setup;
203 IkiWiki::Setup::dump($config{dumpsetup});
205 elsif ($config{wrapper}) {
207 require IkiWiki::Wrapper;
210 elsif ($config{cgi}) {
211 require IkiWiki::CGI;
217 elsif ($config{render}) {
218 require IkiWiki::Render;
219 commandline_render();
221 elsif ($config{post_commit} && ! commit_hook_enabled()) {
224 elsif ($config{clean}) {
225 require IkiWiki::Render;
226 foreach my $wrapper (@{$config{wrappers}}) {
227 prune($wrapper->{wrapper});
230 system("rm", "-rf", $config{wikistatedir});
233 if ($config{rebuild}) {
234 debug(gettext("rebuilding wiki.."));
237 debug(gettext("refreshing wiki.."));
241 require IkiWiki::Render;
245 debug(gettext("done"));