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