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