summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 745dfddd4ca870376844d913516d5962e2682f8e (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. wrapper => undef,
  35. wrappermode => undef,
  36. svnrepo => undef,
  37. svnpath => "trunk",
  38. srcdir => undef,
  39. destdir => undef,
  40. templatedir => "/usr/share/ikiwiki/templates",
  41. underlaydir => "/usr/share/ikiwiki/basewiki",
  42. setup => undef,
  43. adminuser => undef,
  44. adminemail => undef,
  45. plugin => [qw{inline}],
  46. headercontent => '',
  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. "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. if ($@) {
  102. error("WRAPPED_OPTIONS: $@");
  103. }
  104. checkconfig();
  105. }
  106. } #}}}
  107. sub main () { #{{{
  108. getconfig();
  109. if ($config{cgi}) {
  110. lockwiki();
  111. loadindex();
  112. require IkiWiki::CGI;
  113. cgi();
  114. }
  115. elsif ($config{setup}) {
  116. require IkiWiki::Setup;
  117. setup();
  118. }
  119. elsif ($config{wrapper}) {
  120. lockwiki();
  121. require IkiWiki::Wrapper;
  122. gen_wrapper();
  123. }
  124. else {
  125. lockwiki();
  126. loadindex();
  127. require IkiWiki::Render;
  128. rcs_update();
  129. rcs_getctime() if $config{getctime};
  130. refresh();
  131. rcs_notify() if $config{notify};
  132. saveindex();
  133. }
  134. } #}}}
  135. main;