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