summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 5b4972ab7797dec2b6cd6331dff8ccdb70031934 (plain)
  1. #!/usr/bin/perl -T
  2. $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
  3. package IkiWiki;
  4. use warnings;
  5. use strict;
  6. use lib '.'; # For use without installation, removed by Makefile.
  7. use IkiWiki;
  8. sub usage () { #{{{
  9. die "usage: ikiwiki [options] source dest\n";
  10. } #}}}
  11. sub getconfig () { #{{{
  12. if (! exists $ENV{WRAPPED_OPTIONS}) {
  13. %config=(
  14. wiki_file_prune_regexp => qr{((^|/).svn/|\.\.|^\.|\/\.|\.html?$|\.rss$)},
  15. wiki_link_regexp => qr/\[\[(?:([^\s\]\|]+)\|)?([^\s\]]+)\]\]/,
  16. wiki_processor_regexp => qr/\[\[(\w+)\s+([^\]]*)\]\]/,
  17. wiki_file_regexp => qr/(^[-[:alnum:]_.:\/+]+$)/,
  18. verbose => 0,
  19. wikiname => "wiki",
  20. default_pageext => ".mdwn",
  21. cgi => 0,
  22. rcs => 'svn',
  23. notify => 0,
  24. url => '',
  25. cgiurl => '',
  26. historyurl => '',
  27. diffurl => '',
  28. anonok => 0,
  29. rss => 0,
  30. sanitize => 1,
  31. rebuild => 0,
  32. refresh => 0,
  33. getctime => 0,
  34. hyperestraier => 0,
  35. wrapper => undef,
  36. wrappermode => undef,
  37. svnrepo => undef,
  38. svnpath => "trunk",
  39. srcdir => undef,
  40. destdir => undef,
  41. templatedir => "/usr/share/ikiwiki/templates",
  42. underlaydir => "/usr/share/ikiwiki/basewiki",
  43. setup => undef,
  44. adminuser => undef,
  45. adminemail => undef,
  46. plugin => [qw{inline}],
  47. );
  48. eval q{use Getopt::Long};
  49. GetOptions(
  50. "setup|s=s" => \$config{setup},
  51. "wikiname=s" => \$config{wikiname},
  52. "verbose|v!" => \$config{verbose},
  53. "rebuild!" => \$config{rebuild},
  54. "refresh!" => \$config{refresh},
  55. "getctime" => \$config{getctime},
  56. "wrappermode=i" => \$config{wrappermode},
  57. "rcs=s" => \$config{rcs},
  58. "no-rcs" => sub { $config{rcs}="" },
  59. "anonok!" => \$config{anonok},
  60. "hyperestraier" => \$config{hyperestraier},
  61. "rss!" => \$config{rss},
  62. "cgi!" => \$config{cgi},
  63. "notify!" => \$config{notify},
  64. "sanitize!" => \$config{sanitize},
  65. "url=s" => \$config{url},
  66. "cgiurl=s" => \$config{cgiurl},
  67. "historyurl=s" => \$config{historyurl},
  68. "diffurl=s" => \$config{diffurl},
  69. "svnrepo" => \$config{svnrepo},
  70. "svnpath" => \$config{svnpath},
  71. "adminemail=s" => \$config{adminemail},
  72. "exclude=s@" => sub {
  73. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
  74. },
  75. "adminuser=s@" => sub {
  76. push @{$config{adminuser}}, $_[1]
  77. },
  78. "templatedir=s" => sub {
  79. $config{templatedir}=possibly_foolish_untaint($_[1])
  80. },
  81. "underlaydir=s" => sub {
  82. $config{underlaydir}=possibly_foolish_untaint($_[1])
  83. },
  84. "wrapper:s" => sub {
  85. $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
  86. },
  87. "plugin=s@" => sub {
  88. push @{$config{plugin}}, $_[1];
  89. }
  90. ) || usage();
  91. if (! $config{setup}) {
  92. usage() unless @ARGV == 2;
  93. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  94. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  95. checkconfig();
  96. }
  97. }
  98. else {
  99. # wrapper passes a full config structure in the environment
  100. # variable
  101. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  102. checkconfig();
  103. }
  104. } #}}}
  105. sub main () { #{{{
  106. getconfig();
  107. if ($config{cgi}) {
  108. lockwiki();
  109. loadindex();
  110. require IkiWiki::CGI;
  111. cgi();
  112. }
  113. elsif ($config{setup}) {
  114. require IkiWiki::Setup;
  115. setup();
  116. }
  117. elsif ($config{wrapper}) {
  118. lockwiki();
  119. require IkiWiki::Wrapper;
  120. gen_wrapper();
  121. }
  122. else {
  123. lockwiki();
  124. loadindex();
  125. require IkiWiki::Render;
  126. rcs_update();
  127. rcs_getctime() if $config{getctime};
  128. refresh();
  129. rcs_notify() if $config{notify};
  130. saveindex();
  131. }
  132. } #}}}
  133. main;