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