summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 878d3506519a02e496fdb13564c4591a8d6fb0ea (plain)
  1. #!/usr/bin/perl -T
  2. $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
  3. delete @ENV{qw{IFS CDPATH ENV BASH_ENV}};
  4. package IkiWiki;
  5. use warnings;
  6. use strict;
  7. use lib '.'; # For use in nonstandard directory, munged by Makefile.
  8. use IkiWiki;
  9. sub usage () { #{{{
  10. die gettext("usage: ikiwiki [options] source dest"), "\n";
  11. } #}}}
  12. sub getconfig () { #{{{
  13. if (! exists $ENV{WRAPPED_OPTIONS}) {
  14. %config=defaultconfig();
  15. eval q{use Getopt::Long};
  16. Getopt::Long::Configure('pass_through');
  17. GetOptions(
  18. "setup|s=s" => sub {
  19. require IkiWiki::Setup;
  20. IkiWiki::Setup::load($_[1]);
  21. $config{setup}=1;
  22. },
  23. "dumpsetup|s=s" => \$config{dumpsetup},
  24. "wikiname=s" => \$config{wikiname},
  25. "verbose|v!" => \$config{verbose},
  26. "syslog!" => \$config{syslog},
  27. "rebuild!" => \$config{rebuild},
  28. "refresh!" => \$config{refresh},
  29. "post-commit" => \$config{post_commit},
  30. "render=s" => \$config{render},
  31. "wrappers!" => \$config{genwrappers},
  32. "usedirs!" => \$config{usedirs},
  33. "prefix-directives!" => \$config{prefix_directives},
  34. "getctime" => \$config{getctime},
  35. "numbacklinks=i" => \$config{numbacklinks},
  36. "rcs=s" => \$config{rcs},
  37. "no-rcs" => sub { $config{rcs}="" },
  38. "cgi!" => \$config{cgi},
  39. "discussion!" => \$config{discussion},
  40. "w3mmode!" => \$config{w3mmode},
  41. "url=s" => \$config{url},
  42. "cgiurl=s" => \$config{cgiurl},
  43. "historyurl=s" => \$config{historyurl},
  44. "diffurl=s" => \$config{diffurl},
  45. "svnpath" => \$config{svnpath},
  46. "adminemail=s" => \$config{adminemail},
  47. "timeformat=s" => \$config{timeformat},
  48. "sslcookie!" => \$config{sslcookie},
  49. "userdir=s" => \$config{userdir},
  50. "htmlext=s" => \$config{htmlext},
  51. "libdir=s" => \$config{libdir},
  52. "exclude=s@" => sub {
  53. push @{$config{wiki_file_prune_regexps}}, $_[1];
  54. },
  55. "adminuser=s@" => sub {
  56. push @{$config{adminuser}}, $_[1]
  57. },
  58. "templatedir=s" => sub {
  59. $config{templatedir}=possibly_foolish_untaint($_[1])
  60. },
  61. "underlaydir=s" => sub {
  62. $config{underlaydir}=possibly_foolish_untaint($_[1])
  63. },
  64. "wrapper:s" => sub {
  65. $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
  66. },
  67. "wrappermode=i" => sub {
  68. $config{wrappermode}=possibly_foolish_untaint($_[1])
  69. },
  70. "plugin=s@" => sub {
  71. push @{$config{add_plugins}}, $_[1];
  72. },
  73. "disable-plugin=s@" => sub {
  74. push @{$config{disable_plugins}}, $_[1];
  75. },
  76. "set=s" => sub {
  77. my ($var, $val)=split('=', $_[1], 2);
  78. if (! defined $var || ! defined $val) {
  79. die gettext("usage: --set var=value"), "\n";
  80. }
  81. $config{$var}=$val;
  82. },
  83. "version" => sub {
  84. print "ikiwiki version $IkiWiki::version\n";
  85. exit;
  86. },
  87. ) || usage();
  88. if (! $config{setup} && ! $config{render}) {
  89. loadplugins();
  90. if (@ARGV == 2) {
  91. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  92. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  93. checkconfig();
  94. }
  95. else {
  96. usage() unless $config{dumpsetup};
  97. }
  98. }
  99. }
  100. else {
  101. # wrapper passes a full config structure in the environment
  102. # variable
  103. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  104. if ($@) {
  105. error("WRAPPED_OPTIONS: $@");
  106. }
  107. delete $ENV{WRAPPED_OPTIONS};
  108. loadplugins();
  109. checkconfig();
  110. }
  111. } #}}}
  112. sub main () { #{{{
  113. getconfig();
  114. if ($config{setup}) {
  115. delete $config{setup};
  116. loadplugins();
  117. checkconfig();
  118. if (@{$config{wrappers}} &&
  119. ! $config{render} && ! $config{dumpsetup} &&
  120. (! $config{refresh} || $config{genwrappers})) {
  121. debug(gettext("generating wrappers.."));
  122. require IkiWiki::Wrapper;
  123. my %origconfig=(%config);
  124. my @wrappers=@{$config{wrappers}};
  125. delete $config{wrappers};
  126. delete $config{genwrappers};
  127. foreach my $wrapper (@wrappers) {
  128. %config=(%origconfig,
  129. rebuild => 0,
  130. verbose => undef,
  131. %{$wrapper},
  132. );
  133. checkconfig();
  134. if (! $config{cgi} && ! $config{post_commit}) {
  135. $config{post_commit}=1;
  136. }
  137. gen_wrapper();
  138. }
  139. %config=(%origconfig);
  140. }
  141. # setup implies a wiki rebuild by default
  142. if (! $config{refresh}) {
  143. $config{rebuild}=1;
  144. }
  145. }
  146. if ($config{dumpsetup}) {
  147. $config{srdir}=$config{destdir}="";
  148. require IkiWiki::Setup;
  149. IkiWiki::Setup::dump($config{dumpsetup});
  150. }
  151. elsif ($config{wrapper}) {
  152. lockwiki();
  153. require IkiWiki::Wrapper;
  154. gen_wrapper();
  155. }
  156. elsif ($config{cgi}) {
  157. require IkiWiki::CGI;
  158. eval {cgi()};
  159. if ($@) {
  160. cgierror($@);
  161. }
  162. }
  163. elsif ($config{render}) {
  164. require IkiWiki::Render;
  165. commandline_render();
  166. }
  167. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  168. # do nothing
  169. }
  170. else {
  171. if (! $config{refresh}) {
  172. debug(gettext("rebuilding wiki.."));
  173. }
  174. else {
  175. debug(gettext("refreshing wiki.."));
  176. }
  177. lockwiki();
  178. loadindex();
  179. require IkiWiki::Render;
  180. rcs_update();
  181. refresh();
  182. saveindex();
  183. debug(gettext("done"));
  184. }
  185. } #}}}
  186. main;