summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: b8581d880eea398ac10a697c311f36428a18a67c (plain)
  1. #!/usr/bin/perl
  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{post_commit})
  130. || $config{genwrappers})) {
  131. debug(gettext("generating wrappers.."));
  132. require IkiWiki::Wrapper;
  133. my %origconfig=(%config);
  134. foreach my $wrapper (@{$config{wrappers}}) {
  135. %config=(%origconfig, %{$wrapper});
  136. $config{verbose}=$config{setupverbose}
  137. if exists $config{setupverbose};
  138. $config{syslog}=$config{setupsyslog}
  139. if exists $config{setupsyslog};
  140. delete @config{qw(setupsyslog setupverbose wrappers genwrappers rebuild)};
  141. checkconfig();
  142. if (! $config{cgi} && ! $config{post_commit} &&
  143. ! $config{test_receive}) {
  144. $config{post_commit}=1;
  145. }
  146. gen_wrapper();
  147. }
  148. %config=(%origconfig);
  149. }
  150. # setup implies a wiki rebuild by default
  151. if (! $config{refresh} && ! $config{render} &&
  152. ! $config{post_commit}) {
  153. $config{rebuild}=1;
  154. }
  155. }
  156. if ($config{dumpsetup}) {
  157. $config{srcdir}="" if ! defined $config{srcdir};
  158. $config{destdir}="" if ! defined $config{destdir};
  159. $config{syslog}=1 if $config{setupsyslog};
  160. require IkiWiki::Setup;
  161. IkiWiki::Setup::dump($config{dumpsetup});
  162. }
  163. elsif ($config{wrapper}) {
  164. lockwiki();
  165. require IkiWiki::Wrapper;
  166. gen_wrapper();
  167. }
  168. elsif ($config{cgi}) {
  169. require IkiWiki::CGI;
  170. eval {cgi()};
  171. if ($@) {
  172. cgierror($@);
  173. }
  174. }
  175. elsif ($config{render}) {
  176. require IkiWiki::Render;
  177. commandline_render();
  178. }
  179. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  180. # do nothing
  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;