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 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 "clean!" => \$config{clean},
41 "post-commit" => \$config{post_commit},
42 "render=s" => \$config{render},
43 "wrappers!" => \$config{genwrappers},
44 "wrappergroup=s" => \$config{wrappergroup},
45 "usedirs!" => \$config{usedirs},
46 "prefix-directives!" => \$config{prefix_directives},
47 "getctime" => \$config{gettime},
48 "gettime!" => \$config{gettime},
49 "numbacklinks=i" => \$config{numbacklinks},
50 "rcs=s" => \$config{rcs},
51 "no-rcs" => sub { $config{rcs}="" },
52 "cgi!" => \$config{cgi},
53 "discussion!" => \$config{discussion},
54 "w3mmode!" => \$config{w3mmode},
55 "url=s" => \$config{url},
56 "cgiurl=s" => \$config{cgiurl},
57 "historyurl=s" => \$config{historyurl},
58 "diffurl=s" => \$config{diffurl},
59 "svnpath" => \$config{svnpath},
60 "adminemail=s" => \$config{adminemail},
61 "timeformat=s" => \$config{timeformat},
62 "sslcookie!" => \$config{sslcookie},
63 "userdir=s" => \$config{userdir},
64 "htmlext=s" => \$config{htmlext},
65 "libdir=s" => \$config{libdir},
67 push @{$config{wiki_file_prune_regexps}}, $_[1];
70 $config{include}=defined $config{include} && length $config{include} ? "$config{include}|$_[1]" : $_[1];
72 "adminuser=s@" => sub {
73 push @{$config{adminuser}}, $_[1]
75 "templatedir=s" => sub {
76 $config{templatedir}=possibly_foolish_untaint($_[1])
78 "underlaydir=s" => sub {
79 $config{underlaydir}=possibly_foolish_untaint($_[1])
82 $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
84 "wrappermode=i" => sub {
85 $config{wrappermode}=possibly_foolish_untaint($_[1])
88 push @{$config{add_plugins}}, $_[1];
90 "disable-plugin=s@" => sub {
91 push @{$config{disable_plugins}}, $_[1];
94 my ($var, $val)=split('=', $_[1], 2);
95 if (! defined $var || ! defined $val) {
96 die gettext("usage: --set var=value"), "\n";
100 "set-yaml=s" => sub {
101 my ($var, $val)=split('=', $_[1], 2);
102 if (! defined $var || ! defined $val) {
103 die gettext("usage: --set-yaml var=value"), "\n";
105 eval q{use YAML::Any};
106 eval q{use YAML} if $@;
108 eval q{$YAML::Syck::ImplicitUnicode=1};
109 $config{$var}=Load($val."\n");
112 print "ikiwiki version $IkiWiki::version\n";
115 "help|h" => sub { $SIG{__WARN__}=sub {}; die },
118 if (! $config{setup}) {
121 $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
122 $config{destdir} = possibly_foolish_untaint(shift @ARGV);
126 usage() unless $config{dumpsetup};
131 # wrapper passes a full config structure in the environment
133 eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
135 error("WRAPPED_OPTIONS: $@");
137 delete $ENV{WRAPPED_OPTIONS};
147 if ($config{setup}) {
148 delete $config{setup};
152 if (@{$config{wrappers}} &&
153 ! $config{render} && ! $config{dumpsetup} &&
155 ((! $config{refresh} && ! $config{post_commit})
156 || $config{genwrappers})) {
157 debug(gettext("generating wrappers.."));
158 require IkiWiki::Wrapper;
159 my %origconfig=(%config);
160 foreach my $wrapper (@{$config{wrappers}}) {
161 %config=(%origconfig, %{$wrapper});
162 $config{verbose}=$config{setupverbose}
163 if exists $config{setupverbose};
164 $config{syslog}=$config{setupsyslog}
165 if exists $config{setupsyslog};
166 delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)};
168 if (! $config{cgi} && ! $config{post_commit} &&
169 ! $config{test_receive}) {
170 $config{post_commit}=1;
174 %config=(%origconfig);
177 # setup implies a wiki rebuild by default
178 if (! $config{refresh} && ! $config{render} &&
179 ! $config{post_commit} && ! $config{clean}) {
184 if ($config{dumpsetup}) {
185 $config{srcdir}="" if ! defined $config{srcdir};
186 $config{destdir}="" if ! defined $config{destdir};
187 $config{syslog}=1 if $config{setupsyslog};
188 require IkiWiki::Setup;
189 IkiWiki::Setup::dump($config{dumpsetup});
191 elsif ($config{wrapper}) {
193 require IkiWiki::Wrapper;
196 elsif ($config{cgi}) {
197 require IkiWiki::CGI;
203 elsif ($config{render}) {
204 require IkiWiki::Render;
205 commandline_render();
207 elsif ($config{post_commit} && ! commit_hook_enabled()) {
210 elsif ($config{clean}) {
211 require IkiWiki::Render;
212 foreach my $wrapper (@{$config{wrappers}}) {
213 prune($wrapper->{wrapper});
216 system("rm", "-rf", $config{wikistatedir});
219 if ($config{rebuild}) {
220 debug(gettext("rebuilding wiki.."));
223 debug(gettext("refreshing wiki.."));
227 require IkiWiki::Render;
231 debug(gettext("done"));