summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 339efd37c3ab8655746bff66c4610924936a4c87 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use lib '.'; # For use in nonstandard directory, munged by Makefile.
  6. use IkiWiki 3.00;
  7. sub usage () {
  8. die gettext("usage: ikiwiki [options] source dest"), "\n",
  9. gettext(" ikiwiki --setup configfile"), "\n";
  10. }
  11. sub setup (@) {
  12. require IkiWiki::Setup;
  13. my $verbose=$config{verbose};
  14. my $syslog=$config{syslog};
  15. IkiWiki::Setup::load($_[1]);
  16. $config{setupverbose}=$config{verbose};
  17. $config{setupsyslog}=$config{syslog};
  18. $config{verbose}=$verbose || $config{setupverbose};
  19. $config{syslog}=$syslog;
  20. $config{setup}=1;
  21. }
  22. sub getconfig () {
  23. if (! exists $ENV{WRAPPED_OPTIONS}) {
  24. %config=defaultconfig();
  25. eval q{use Getopt::Long};
  26. Getopt::Long::Configure('pass_through');
  27. GetOptions(
  28. "setup|s=s" => \&setup,
  29. "dumpsetup|s=s" => \$config{dumpsetup},
  30. "changesetup|s=s" => sub {
  31. $config{changesetup}=$_[1];
  32. $config{genwrappers}=1;
  33. $config{refresh}=1;
  34. setup(@_);
  35. },
  36. "wikiname=s" => \$config{wikiname},
  37. "verbose|v!" => \$config{verbose},
  38. "syslog!" => \$config{syslog},
  39. "rebuild!" => \$config{rebuild},
  40. "refresh!" => \$config{refresh},
  41. "clean!" => \$config{clean},
  42. "post-commit" => \$config{post_commit},
  43. "render=s" => \$config{render},
  44. "wrappers!" => \$config{genwrappers},
  45. "wrappergroup=s" => \$config{wrappergroup},
  46. "usedirs!" => \$config{usedirs},
  47. "prefix-directives!" => \$config{prefix_directives},
  48. "getctime" => \$config{gettime},
  49. "gettime!" => \$config{gettime},
  50. "numbacklinks=i" => \$config{numbacklinks},
  51. "rcs=s" => \$config{rcs},
  52. "no-rcs" => sub { $config{rcs}="" },
  53. "cgi!" => \$config{cgi},
  54. "discussion!" => \$config{discussion},
  55. "w3mmode!" => \$config{w3mmode},
  56. "url=s" => \$config{url},
  57. "cgiurl=s" => \$config{cgiurl},
  58. "historyurl=s" => \$config{historyurl},
  59. "diffurl=s" => \$config{diffurl},
  60. "svnpath" => \$config{svnpath},
  61. "adminemail=s" => \$config{adminemail},
  62. "timeformat=s" => \$config{timeformat},
  63. "sslcookie!" => \$config{sslcookie},
  64. "userdir=s" => \$config{userdir},
  65. "htmlext=s" => \$config{htmlext},
  66. "libdir=s" => \$config{libdir},
  67. "exclude=s@" => sub {
  68. push @{$config{wiki_file_prune_regexps}}, $_[1];
  69. },
  70. "include=s@" => sub {
  71. $config{include}=defined $config{include} && length $config{include} ? "$config{include}|$_[1]" : $_[1];
  72. },
  73. "adminuser=s@" => sub {
  74. push @{$config{adminuser}}, $_[1]
  75. },
  76. "templatedir=s" => sub {
  77. $config{templatedir}=possibly_foolish_untaint($_[1])
  78. },
  79. "underlaydir=s" => sub {
  80. $config{underlaydir}=possibly_foolish_untaint($_[1])
  81. },
  82. "wrapper:s" => sub {
  83. $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
  84. },
  85. "wrappermode=i" => sub {
  86. $config{wrappermode}=possibly_foolish_untaint($_[1])
  87. },
  88. "plugin=s@" => sub {
  89. push @{$config{add_plugins}}, $_[1]
  90. unless grep { $_ eq $_[1] } @{$config{add_plugins}};
  91. },
  92. "disable-plugin=s@" => sub {
  93. push @{$config{disable_plugins}}, $_[1];
  94. },
  95. "set=s" => sub {
  96. my ($var, $val)=split('=', $_[1], 2);
  97. if (! defined $var || ! defined $val) {
  98. die gettext("usage: --set var=value"), "\n";
  99. }
  100. $config{$var}=$val;
  101. },
  102. "set-yaml=s" => sub {
  103. my ($var, $val)=split('=', $_[1], 2);
  104. if (! defined $var || ! defined $val) {
  105. die gettext("usage: --set-yaml var=value"), "\n";
  106. }
  107. eval q{use YAML::Any};
  108. eval q{use YAML} if $@;
  109. die $@ if $@;
  110. eval q{$YAML::Syck::ImplicitUnicode=1};
  111. $config{$var}=Load($val."\n");
  112. },
  113. "version" => sub {
  114. print "ikiwiki version $IkiWiki::version\n";
  115. exit;
  116. },
  117. "help|h" => sub { $SIG{__WARN__}=sub {}; die },
  118. ) || usage();
  119. if (! $config{setup}) {
  120. loadplugins();
  121. if (@ARGV == 2) {
  122. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  123. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  124. checkconfig();
  125. }
  126. else {
  127. usage() unless $config{dumpsetup};
  128. }
  129. }
  130. }
  131. else {
  132. # wrapper passes a full config structure in the environment
  133. # variable
  134. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  135. if ($@) {
  136. error("WRAPPED_OPTIONS: $@");
  137. }
  138. delete $ENV{WRAPPED_OPTIONS};
  139. loadplugins();
  140. checkconfig();
  141. }
  142. }
  143. sub main () {
  144. getconfig();
  145. if ($config{setup}) {
  146. delete $config{setup};
  147. loadplugins();
  148. checkconfig();
  149. if (@{$config{wrappers}} &&
  150. ! $config{render} && ! $config{dumpsetup} &&
  151. ! $config{clean} &&
  152. ((! $config{refresh} && ! $config{post_commit})
  153. || $config{genwrappers})) {
  154. require IkiWiki::Wrapper;
  155. gen_wrappers();
  156. }
  157. # setup implies a wiki rebuild by default
  158. if (! $config{refresh} && ! $config{render} &&
  159. ! $config{post_commit} && ! $config{clean}) {
  160. $config{rebuild}=1;
  161. }
  162. }
  163. if ($config{changesetup}) {
  164. require IkiWiki::Setup;
  165. IkiWiki::Setup::dump($config{changesetup});
  166. }
  167. if ($config{dumpsetup}) {
  168. $config{srcdir}="" if ! defined $config{srcdir};
  169. $config{destdir}="" if ! defined $config{destdir};
  170. $config{syslog}=1 if $config{setupsyslog};
  171. require IkiWiki::Setup;
  172. IkiWiki::Setup::dump($config{dumpsetup});
  173. }
  174. elsif ($config{wrapper}) {
  175. lockwiki();
  176. require IkiWiki::Wrapper;
  177. gen_wrapper();
  178. }
  179. elsif ($config{cgi}) {
  180. require IkiWiki::CGI;
  181. eval {cgi()};
  182. if ($@) {
  183. cgierror($@);
  184. }
  185. }
  186. elsif ($config{render}) {
  187. require IkiWiki::Render;
  188. commandline_render();
  189. }
  190. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  191. # do nothing
  192. }
  193. elsif ($config{clean}) {
  194. require IkiWiki::Render;
  195. foreach my $wrapper (@{$config{wrappers}}) {
  196. prune($wrapper->{wrapper});
  197. }
  198. clean_rendered();
  199. system("rm", "-rf", $config{wikistatedir});
  200. }
  201. else {
  202. if ($config{rebuild}) {
  203. debug(gettext("rebuilding wiki.."));
  204. }
  205. else {
  206. debug(gettext("refreshing wiki.."));
  207. }
  208. lockwiki();
  209. loadindex();
  210. require IkiWiki::Render;
  211. rcs_update();
  212. refresh();
  213. saveindex();
  214. debug(gettext("done"));
  215. }
  216. }
  217. main;