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