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