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