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