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