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