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