summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: d601d2739e64bdba76cfd5a852d18a36876d12ec (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{test_receive}) {
  151. $config{post_commit}=1;
  152. }
  153. gen_wrapper();
  154. }
  155. %config=(%origconfig);
  156. }
  157. # setup implies a wiki rebuild by default
  158. if (! $config{refresh}) {
  159. $config{rebuild}=1;
  160. }
  161. }
  162. if ($config{dumpsetup}) {
  163. $config{srdir}=$config{destdir}="";
  164. require IkiWiki::Setup;
  165. IkiWiki::Setup::dump($config{dumpsetup});
  166. }
  167. elsif ($config{wrapper}) {
  168. lockwiki();
  169. require IkiWiki::Wrapper;
  170. gen_wrapper();
  171. }
  172. elsif ($config{cgi}) {
  173. require IkiWiki::CGI;
  174. eval {cgi()};
  175. if ($@) {
  176. cgierror($@);
  177. }
  178. }
  179. elsif ($config{render}) {
  180. require IkiWiki::Render;
  181. commandline_render();
  182. }
  183. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  184. # do nothing
  185. }
  186. elsif ($config{test_receive}) {
  187. require IkiWiki::Receive;
  188. IkiWiki::Receive::test();
  189. }
  190. else {
  191. if ($config{rebuild}) {
  192. debug(gettext("rebuilding wiki.."));
  193. }
  194. else {
  195. debug(gettext("refreshing wiki.."));
  196. }
  197. lockwiki();
  198. loadindex();
  199. require IkiWiki::Render;
  200. rcs_update();
  201. refresh();
  202. saveindex();
  203. debug(gettext("done"));
  204. }
  205. } #}}}
  206. main;