summaryrefslogtreecommitdiff
path: root/ikiwiki.pl
blob: 6204ff194a0bc9392597f1f5429aa7abbaf5c420 (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 without installation, removed by Makefile.
  8. use IkiWiki;
  9. sub usage () { #{{{
  10. die "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. "render=s" => \$config{render},
  25. "wrappers!" => \$config{wrappers},
  26. "getctime" => \$config{getctime},
  27. "wrappermode=i" => \$config{wrappermode},
  28. "rcs=s" => \$config{rcs},
  29. "no-rcs" => sub { $config{rcs}="" },
  30. "anonok!" => \$config{anonok},
  31. "rss!" => \$config{rss},
  32. "atom!" => \$config{atom},
  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. "exclude=s@" => sub {
  48. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[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] ? $_[1] : "ikiwiki-wrap"
  61. },
  62. "plugin=s@" => sub {
  63. push @{$config{plugin}}, $_[1];
  64. },
  65. "disable-plugin=s@" => sub {
  66. $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
  67. },
  68. "pingurl" => sub {
  69. push @{$config{pingurl}}, $_[1];
  70. },
  71. "version" => sub {
  72. print "ikiwiki version $IkiWiki::version\n";
  73. exit;
  74. },
  75. ) || usage();
  76. if (! $config{setup} && ! $config{render}) {
  77. loadplugins();
  78. usage() unless @ARGV == 2;
  79. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  80. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  81. checkconfig();
  82. }
  83. }
  84. else {
  85. # wrapper passes a full config structure in the environment
  86. # variable
  87. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  88. if ($@) {
  89. error("WRAPPED_OPTIONS: $@");
  90. }
  91. loadplugins();
  92. checkconfig();
  93. }
  94. } #}}}
  95. sub main () { #{{{
  96. getconfig();
  97. if ($config{cgi}) {
  98. lockwiki();
  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. else {
  117. lockwiki();
  118. loadindex();
  119. require IkiWiki::Render;
  120. rcs_update();
  121. refresh();
  122. rcs_notify() if $config{notify};
  123. saveindex();
  124. }
  125. } #}}}
  126. main;