summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 2aeaf94ecedc4ffd210d9c774dab983a58050f2d (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. "notify!" => \$config{notify},
  36. "url=s" => \$config{url},
  37. "cgiurl=s" => \$config{cgiurl},
  38. "historyurl=s" => \$config{historyurl},
  39. "diffurl=s" => \$config{diffurl},
  40. "svnrepo" => \$config{svnrepo},
  41. "svnpath" => \$config{svnpath},
  42. "adminemail=s" => \$config{adminemail},
  43. "timeformat=s" => \$config{timeformat},
  44. "sslcookie!" => \$config{sslcookie},
  45. "httpauth!" => \$config{httpauth},
  46. "userdir=s" => \$config{userdir},
  47. "htmlext=s" => \$config{htmlext},
  48. "libdir=s" => \$config{libdir},
  49. "exclude=s@" => sub {
  50. push @{$config{wiki_file_prune_regexps}}, $_[1];
  51. },
  52. "adminuser=s@" => sub {
  53. push @{$config{adminuser}}, $_[1]
  54. },
  55. "templatedir=s" => sub {
  56. $config{templatedir}=possibly_foolish_untaint($_[1])
  57. },
  58. "underlaydir=s" => sub {
  59. $config{underlaydir}=possibly_foolish_untaint($_[1])
  60. },
  61. "wrapper:s" => sub {
  62. $config{wrapper}=$_[1] ? possibly_foolish_untaint($_[1]) : "ikiwiki-wrap"
  63. },
  64. "wrappermode=i" => sub {
  65. $config{wrappermode}=possibly_foolish_untaint($_[1])
  66. },
  67. "plugin=s@" => sub {
  68. push @{$config{plugin}}, $_[1];
  69. },
  70. "disable-plugin=s@" => sub {
  71. push @{$config{disable_plugins}}, $_[1];
  72. },
  73. "pingurl=s" => sub {
  74. push @{$config{pingurl}}, $_[1];
  75. },
  76. "set=s" => sub {
  77. my ($var, $val)=split('=', $_[1], 2);
  78. if (! defined $var || ! defined $val) {
  79. die gettext("usage: --set var=value"), "\n";
  80. }
  81. $config{$var}=$val;
  82. },
  83. "version" => sub {
  84. print "ikiwiki version $IkiWiki::version\n";
  85. exit;
  86. },
  87. ) || usage();
  88. if (! $config{setup} && ! $config{render}) {
  89. loadplugins();
  90. usage() unless @ARGV == 2;
  91. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  92. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  93. checkconfig();
  94. }
  95. }
  96. else {
  97. # wrapper passes a full config structure in the environment
  98. # variable
  99. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  100. if ($@) {
  101. error("WRAPPED_OPTIONS: $@");
  102. }
  103. loadplugins();
  104. checkconfig();
  105. }
  106. } #}}}
  107. sub main () { #{{{
  108. getconfig();
  109. if ($config{setup}) {
  110. require IkiWiki::Setup;
  111. setup();
  112. }
  113. elsif ($config{wrapper}) {
  114. lockwiki();
  115. require IkiWiki::Wrapper;
  116. gen_wrapper();
  117. }
  118. elsif ($config{cgi}) {
  119. loadindex();
  120. require IkiWiki::CGI;
  121. cgi();
  122. }
  123. elsif ($config{render}) {
  124. require IkiWiki::Render;
  125. commandline_render();
  126. }
  127. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  128. if ($config{notify}) {
  129. loadindex();
  130. rcs_notify();
  131. }
  132. }
  133. else {
  134. lockwiki();
  135. loadindex();
  136. require IkiWiki::Render;
  137. rcs_update();
  138. refresh();
  139. rcs_notify() if $config{notify};
  140. saveindex();
  141. }
  142. } #}}}
  143. main;