summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: bcda2469b515c33a8df91536da895f28841574b3 (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. require IkiWiki::Wrapper;
  157. gen_wrappers();
  158. }
  159. # setup implies a wiki rebuild by default
  160. if (! $config{refresh} && ! $config{render} &&
  161. ! $config{post_commit} && ! $config{clean}) {
  162. $config{rebuild}=1;
  163. }
  164. }
  165. if ($config{changesetup}) {
  166. require IkiWiki::Setup;
  167. IkiWiki::Setup::dump($config{changesetup});
  168. }
  169. if ($config{dumpsetup}) {
  170. $config{srcdir}="" if ! defined $config{srcdir};
  171. $config{destdir}="" if ! defined $config{destdir};
  172. $config{syslog}=1 if $config{setupsyslog};
  173. require IkiWiki::Setup;
  174. IkiWiki::Setup::dump($config{dumpsetup});
  175. }
  176. elsif ($config{wrapper}) {
  177. lockwiki();
  178. require IkiWiki::Wrapper;
  179. gen_wrapper();
  180. }
  181. elsif ($config{cgi}) {
  182. require IkiWiki::CGI;
  183. eval {cgi()};
  184. if ($@) {
  185. cgierror($@);
  186. }
  187. }
  188. elsif ($config{render}) {
  189. require IkiWiki::Render;
  190. commandline_render();
  191. }
  192. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  193. # do nothing
  194. }
  195. elsif ($config{clean}) {
  196. require IkiWiki::Render;
  197. foreach my $wrapper (@{$config{wrappers}}) {
  198. prune($wrapper->{wrapper});
  199. }
  200. clean_rendered();
  201. system("rm", "-rf", $config{wikistatedir});
  202. }
  203. else {
  204. if ($config{rebuild}) {
  205. debug(gettext("rebuilding wiki.."));
  206. }
  207. else {
  208. debug(gettext("refreshing wiki.."));
  209. }
  210. lockwiki();
  211. loadindex();
  212. require IkiWiki::Render;
  213. rcs_update();
  214. refresh();
  215. saveindex();
  216. debug(gettext("done"));
  217. }
  218. }
  219. main;