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