summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: e0a59182422ae0d2aaa1b69d15fa3463f144d9c8 (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. } #}}}
  12. sub getconfig () { #{{{
  13. if (! exists $ENV{WRAPPED_OPTIONS}) {
  14. %config=defaultconfig();
  15. eval q{use Getopt::Long};
  16. Getopt::Long::Configure('pass_through');
  17. GetOptions(
  18. "setup|s=s" => \$config{setup},
  19. "wikiname=s" => \$config{wikiname},
  20. "verbose|v!" => \$config{verbose},
  21. "syslog!" => \$config{syslog},
  22. "rebuild!" => \$config{rebuild},
  23. "refresh!" => \$config{refresh},
  24. "post-commit" => \$config{post_commit},
  25. "render=s" => \$config{render},
  26. "wrappers!" => \$config{wrappers},
  27. "usedirs!" => \$config{usedirs},
  28. "prefix-directives!" => \$config{prefix_directives},
  29. "getctime" => \$config{getctime},
  30. "numbacklinks=i" => \$config{numbacklinks},
  31. "rcs=s" => \$config{rcs},
  32. "no-rcs" => sub { $config{rcs}="" },
  33. "cgi!" => \$config{cgi},
  34. "discussion!" => \$config{discussion},
  35. "w3mmode!" => \$config{w3mmode},
  36. "url=s" => \$config{url},
  37. "cgiurl=s" => \$config{cgiurl},
  38. "historyurl=s" => \$config{historyurl},
  39. "diffurl=s" => \$config{diffurl},
  40. "svnpath" => \$config{svnpath},
  41. "adminemail=s" => \$config{adminemail},
  42. "timeformat=s" => \$config{timeformat},
  43. "sslcookie!" => \$config{sslcookie},
  44. "httpauth!" => \$config{httpauth},
  45. "userdir=s" => \$config{userdir},
  46. "htmlext=s" => \$config{htmlext},
  47. "libdir=s" => \$config{libdir},
  48. "exclude=s@" => sub {
  49. push @{$config{wiki_file_prune_regexps}}, $_[1];
  50. },
  51. "adminuser=s@" => sub {
  52. push @{$config{adminuser}}, $_[1]
  53. },
  54. "templatedir=s" => sub {
  55. $config{templatedir}=possibly_foolish_untaint($_[1])
  56. },
  57. "underlaydir=s" => sub {
  58. $config{underlaydir}=possibly_foolish_untaint($_[1])
  59. },
  60. "wrapper:s" => sub {
  61. $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
  62. },
  63. "wrappermode=i" => sub {
  64. $config{wrappermode}=possibly_foolish_untaint($_[1])
  65. },
  66. "plugin=s@" => sub {
  67. push @{$config{plugin}}, $_[1];
  68. },
  69. "disable-plugin=s@" => sub {
  70. push @{$config{disable_plugins}}, $_[1];
  71. },
  72. "pingurl=s" => sub {
  73. push @{$config{pingurl}}, $_[1];
  74. },
  75. "set=s" => sub {
  76. my ($var, $val)=split('=', $_[1], 2);
  77. if (! defined $var || ! defined $val) {
  78. die gettext("usage: --set var=value"), "\n";
  79. }
  80. $config{$var}=$val;
  81. },
  82. "version" => sub {
  83. print "ikiwiki version $IkiWiki::version\n";
  84. exit;
  85. },
  86. ) || usage();
  87. if (! $config{setup} && ! $config{render}) {
  88. loadplugins();
  89. usage() unless @ARGV == 2;
  90. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  91. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  92. checkconfig();
  93. }
  94. }
  95. else {
  96. # wrapper passes a full config structure in the environment
  97. # variable
  98. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  99. if ($@) {
  100. error("WRAPPED_OPTIONS: $@");
  101. }
  102. loadplugins();
  103. checkconfig();
  104. }
  105. } #}}}
  106. sub main () { #{{{
  107. getconfig();
  108. if ($config{setup}) {
  109. require IkiWiki::Setup;
  110. setup();
  111. }
  112. elsif ($config{wrapper}) {
  113. lockwiki();
  114. require IkiWiki::Wrapper;
  115. gen_wrapper();
  116. }
  117. elsif ($config{cgi}) {
  118. require IkiWiki::CGI;
  119. cgi();
  120. }
  121. elsif ($config{render}) {
  122. require IkiWiki::Render;
  123. commandline_render();
  124. }
  125. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  126. # do nothing
  127. }
  128. else {
  129. lockwiki();
  130. loadindex();
  131. require IkiWiki::Render;
  132. rcs_update();
  133. refresh();
  134. saveindex();
  135. }
  136. } #}}}
  137. main;