summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 8cec3f5c0bac42c221ecd07c0d01cbc71ed8d9a3 (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. "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] ? $_[1] : "ikiwiki-wrap"
  63. },
  64. "plugin=s@" => sub {
  65. push @{$config{plugin}}, $_[1];
  66. },
  67. "disable-plugin=s@" => sub {
  68. push @{$config{disable_plugins}}, $_[1];
  69. },
  70. "pingurl=s" => sub {
  71. push @{$config{pingurl}}, $_[1];
  72. },
  73. "version" => sub {
  74. print "ikiwiki version $IkiWiki::version\n";
  75. exit;
  76. },
  77. ) || usage();
  78. if (! $config{setup} && ! $config{render}) {
  79. loadplugins();
  80. usage() unless @ARGV == 2;
  81. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  82. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  83. checkconfig();
  84. }
  85. }
  86. else {
  87. # wrapper passes a full config structure in the environment
  88. # variable
  89. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  90. if ($@) {
  91. error("WRAPPED_OPTIONS: $@");
  92. }
  93. loadplugins();
  94. checkconfig();
  95. }
  96. } #}}}
  97. sub main () { #{{{
  98. getconfig();
  99. if ($config{cgi}) {
  100. loadindex();
  101. require IkiWiki::CGI;
  102. cgi();
  103. }
  104. elsif ($config{setup}) {
  105. require IkiWiki::Setup;
  106. setup();
  107. }
  108. elsif ($config{wrapper}) {
  109. lockwiki();
  110. require IkiWiki::Wrapper;
  111. gen_wrapper();
  112. }
  113. elsif ($config{render}) {
  114. require IkiWiki::Render;
  115. commandline_render();
  116. }
  117. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  118. if ($config{notify}) {
  119. loadindex();
  120. rcs_notify();
  121. }
  122. }
  123. else {
  124. lockwiki();
  125. loadindex();
  126. require IkiWiki::Render;
  127. rcs_update();
  128. refresh();
  129. rcs_notify() if $config{notify};
  130. saveindex();
  131. }
  132. } #}}}
  133. main;