summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 1a6d18a6089b8e98cb83433e1c5ada1a6f26c917 (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}) {
  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. loadplugins();
  117. checkconfig();
  118. }
  119. } #}}}
  120. sub main () { #{{{
  121. getconfig();
  122. if ($config{setup}) {
  123. delete $config{setup};
  124. loadplugins();
  125. checkconfig();
  126. if (@{$config{wrappers}} &&
  127. ! $config{render} && ! $config{dumpsetup} &&
  128. (! $config{refresh} || $config{genwrappers})) {
  129. debug(gettext("generating wrappers.."));
  130. require IkiWiki::Wrapper;
  131. my %origconfig=(%config);
  132. foreach my $wrapper (@{$config{wrappers}}) {
  133. %config=(%origconfig, %{$wrapper});
  134. $config{verbose}=$config{setupverbose}
  135. if exists $config{setupverbose};
  136. $config{syslog}=$config{setupsyslog}
  137. if exists $config{setupsyslog};
  138. delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)};
  139. checkconfig();
  140. if (! $config{cgi} && ! $config{post_commit} &&
  141. ! $config{test_receive}) {
  142. $config{post_commit}=1;
  143. }
  144. gen_wrapper();
  145. }
  146. %config=(%origconfig);
  147. }
  148. # setup implies a wiki rebuild by default
  149. if (! $config{refresh} && ! $config{render}) {
  150. $config{rebuild}=1;
  151. }
  152. }
  153. if ($config{dumpsetup}) {
  154. $config{srdir}=$config{destdir}="";
  155. $config{syslog}=1 if $config{setupsyslog};
  156. require IkiWiki::Setup;
  157. IkiWiki::Setup::dump($config{dumpsetup});
  158. }
  159. elsif ($config{wrapper}) {
  160. lockwiki();
  161. require IkiWiki::Wrapper;
  162. gen_wrapper();
  163. }
  164. elsif ($config{cgi}) {
  165. require IkiWiki::CGI;
  166. eval {cgi()};
  167. if ($@) {
  168. cgierror($@);
  169. }
  170. }
  171. elsif ($config{render}) {
  172. require IkiWiki::Render;
  173. commandline_render();
  174. }
  175. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  176. # do nothing
  177. }
  178. elsif ($config{test_receive}) {
  179. require IkiWiki::Receive;
  180. IkiWiki::Receive::test();
  181. }
  182. else {
  183. if ($config{rebuild}) {
  184. debug(gettext("rebuilding wiki.."));
  185. }
  186. else {
  187. debug(gettext("refreshing wiki.."));
  188. }
  189. lockwiki();
  190. loadindex();
  191. require IkiWiki::Render;
  192. rcs_update();
  193. refresh();
  194. saveindex();
  195. debug(gettext("done"));
  196. }
  197. } #}}}
  198. main;