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