summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 9d1f6b52077b06e09f5bf7ec97b363c0c17941fb (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. "getctime" => \$config{getctime},
  29. "numbacklinks=i" => \$config{numbacklinks},
  30. "rcs=s" => \$config{rcs},
  31. "no-rcs" => sub { $config{rcs}="" },
  32. "cgi!" => \$config{cgi},
  33. "discussion!" => \$config{discussion},
  34. "w3mmode!" => \$config{w3mmode},
  35. "url=s" => \$config{url},
  36. "cgiurl=s" => \$config{cgiurl},
  37. "historyurl=s" => \$config{historyurl},
  38. "diffurl=s" => \$config{diffurl},
  39. "svnpath" => \$config{svnpath},
  40. "adminemail=s" => \$config{adminemail},
  41. "timeformat=s" => \$config{timeformat},
  42. "sslcookie!" => \$config{sslcookie},
  43. "httpauth!" => \$config{httpauth},
  44. "userdir=s" => \$config{userdir},
  45. "htmlext=s" => \$config{htmlext},
  46. "libdir=s" => \$config{libdir},
  47. "exclude=s@" => sub {
  48. push @{$config{wiki_file_prune_regexps}}, $_[1];
  49. },
  50. "adminuser=s@" => sub {
  51. push @{$config{adminuser}}, $_[1]
  52. },
  53. "templatedir=s" => sub {
  54. $config{templatedir}=possibly_foolish_untaint($_[1])
  55. },
  56. "underlaydir=s" => sub {
  57. $config{underlaydir}=possibly_foolish_untaint($_[1])
  58. },
  59. "wrapper:s" => sub {
  60. $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
  61. },
  62. "wrappermode=i" => sub {
  63. $config{wrappermode}=possibly_foolish_untaint($_[1])
  64. },
  65. "plugin=s@" => sub {
  66. push @{$config{plugin}}, $_[1];
  67. },
  68. "disable-plugin=s@" => sub {
  69. push @{$config{disable_plugins}}, $_[1];
  70. },
  71. "pingurl=s" => sub {
  72. push @{$config{pingurl}}, $_[1];
  73. },
  74. "set=s" => sub {
  75. my ($var, $val)=split('=', $_[1], 2);
  76. if (! defined $var || ! defined $val) {
  77. die gettext("usage: --set var=value"), "\n";
  78. }
  79. $config{$var}=$val;
  80. },
  81. "version" => sub {
  82. print "ikiwiki version $IkiWiki::version\n";
  83. exit;
  84. },
  85. ) || usage();
  86. if (! $config{setup} && ! $config{render}) {
  87. loadplugins();
  88. usage() unless @ARGV == 2;
  89. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  90. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  91. checkconfig();
  92. }
  93. }
  94. else {
  95. # wrapper passes a full config structure in the environment
  96. # variable
  97. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  98. if ($@) {
  99. error("WRAPPED_OPTIONS: $@");
  100. }
  101. loadplugins();
  102. checkconfig();
  103. }
  104. } #}}}
  105. sub main () { #{{{
  106. getconfig();
  107. if ($config{setup}) {
  108. require IkiWiki::Setup;
  109. setup();
  110. }
  111. elsif ($config{wrapper}) {
  112. lockwiki();
  113. require IkiWiki::Wrapper;
  114. gen_wrapper();
  115. }
  116. elsif ($config{cgi}) {
  117. loadindex();
  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;