summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 75114bb662925bfa09b9f0d4a3683f11f6d41079 (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. svn => 1,
  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. "svn!" => \$config{svn},
  58. "anonok!" => \$config{anonok},
  59. "hyperestraier" => \$config{hyperestraier},
  60. "rss!" => \$config{rss},
  61. "cgi!" => \$config{cgi},
  62. "notify!" => \$config{notify},
  63. "sanitize!" => \$config{sanitize},
  64. "url=s" => \$config{url},
  65. "cgiurl=s" => \$config{cgiurl},
  66. "historyurl=s" => \$config{historyurl},
  67. "diffurl=s" => \$config{diffurl},
  68. "svnrepo" => \$config{svnrepo},
  69. "svnpath" => \$config{svnpath},
  70. "adminemail=s" => \$config{adminemail},
  71. "exclude=s@" => sub {
  72. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
  73. },
  74. "adminuser=s@" => sub {
  75. push @{$config{adminuser}}, $_[1]
  76. },
  77. "templatedir=s" => sub {
  78. $config{templatedir}=possibly_foolish_untaint($_[1])
  79. },
  80. "underlaydir=s" => sub {
  81. $config{underlaydir}=possibly_foolish_untaint($_[1])
  82. },
  83. "wrapper:s" => sub {
  84. $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
  85. },
  86. "plugin=s@" => sub {
  87. push @{$config{plugin}}, $_[1];
  88. }
  89. ) || usage();
  90. if (! $config{setup}) {
  91. usage() unless @ARGV == 2;
  92. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  93. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  94. checkconfig();
  95. }
  96. }
  97. else {
  98. # wrapper passes a full config structure in the environment
  99. # variable
  100. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  101. checkconfig();
  102. }
  103. } #}}}
  104. sub main () { #{{{
  105. getconfig();
  106. if ($config{cgi}) {
  107. lockwiki();
  108. loadindex();
  109. require IkiWiki::CGI;
  110. cgi();
  111. }
  112. elsif ($config{setup}) {
  113. require IkiWiki::Setup;
  114. setup();
  115. }
  116. elsif ($config{wrapper}) {
  117. lockwiki();
  118. require IkiWiki::Wrapper;
  119. gen_wrapper();
  120. }
  121. else {
  122. lockwiki();
  123. loadindex();
  124. require IkiWiki::Render;
  125. rcs_update();
  126. rcs_getctime() if $config{getctime};
  127. refresh();
  128. rcs_notify() if $config{notify};
  129. saveindex();
  130. }
  131. } #}}}
  132. main;