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 require IkiWiki::Wrapper;
170 # setup implies a wiki rebuild by default
171 if (! $config{refresh} && ! $config{render} &&
172 ! $config{post_commit} && ! $config{clean}) {
177 if ($config{changesetup}) {
178 require IkiWiki::Setup;
179 IkiWiki::Setup::dump($config{changesetup});
182 if ($config{dumpsetup}) {
183 $config{srcdir}="" if ! defined $config{srcdir};
184 $config{destdir}="" if ! defined $config{destdir};
185 $config{syslog}=1 if $config{setupsyslog};
186 require IkiWiki::Setup;
187 IkiWiki::Setup::dump($config{dumpsetup});
189 elsif ($config{wrapper}) {
191 require IkiWiki::Wrapper;
194 elsif ($config{cgi}) {
195 require IkiWiki::CGI;
201 elsif ($config{render}) {
202 require IkiWiki::Render;
203 commandline_render();
205 elsif ($config{post_commit} && ! commit_hook_enabled()) {
208 elsif ($config{clean}) {
209 require IkiWiki::Render;
210 foreach my $wrapper (@{$config{wrappers}}) {
211 prune($wrapper->{wrapper});
214 system("rm", "-rf", $config{wikistatedir});
217 if ($config{rebuild}) {
218 debug(gettext("rebuilding wiki.."));
221 debug(gettext("refreshing wiki.."));
225 require IkiWiki::Render;
229 debug(gettext("done"));