summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: a10876a96ba10b6fb888c13742f32c34ddf97939 (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=defaultconfig();
  14. eval q{use Getopt::Long};
  15. Getopt::Long::Configure('pass_through');
  16. GetOptions(
  17. "setup|s=s" => \$config{setup},
  18. "wikiname=s" => \$config{wikiname},
  19. "verbose|v!" => \$config{verbose},
  20. "rebuild!" => \$config{rebuild},
  21. "refresh!" => \$config{refresh},
  22. "getctime" => \$config{getctime},
  23. "wrappermode=i" => \$config{wrappermode},
  24. "rcs=s" => \$config{rcs},
  25. "no-rcs" => sub { $config{rcs}="" },
  26. "anonok!" => \$config{anonok},
  27. "rss!" => \$config{rss},
  28. "cgi!" => \$config{cgi},
  29. "discussion!" => \$config{discussion},
  30. "w3mmode!" => \$config{w3mmode},
  31. "notify!" => \$config{notify},
  32. "url=s" => \$config{url},
  33. "cgiurl=s" => \$config{cgiurl},
  34. "historyurl=s" => \$config{historyurl},
  35. "diffurl=s" => \$config{diffurl},
  36. "svnrepo" => \$config{svnrepo},
  37. "svnpath" => \$config{svnpath},
  38. "adminemail=s" => \$config{adminemail},
  39. "timeformat=s" => \$config{timeformat},
  40. "exclude=s@" => sub {
  41. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
  42. },
  43. "adminuser=s@" => sub {
  44. push @{$config{adminuser}}, $_[1]
  45. },
  46. "templatedir=s" => sub {
  47. $config{templatedir}=possibly_foolish_untaint($_[1])
  48. },
  49. "underlaydir=s" => sub {
  50. $config{underlaydir}=possibly_foolish_untaint($_[1])
  51. },
  52. "wrapper:s" => sub {
  53. $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
  54. },
  55. "plugin=s@" => sub {
  56. push @{$config{plugin}}, $_[1];
  57. },
  58. "disable-plugin=s@" => sub {
  59. $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
  60. },
  61. "pingurl" => sub {
  62. push @{$config{pingurl}}, $_[1];
  63. }
  64. ) || usage();
  65. if (! $config{setup}) {
  66. loadplugins();
  67. if (exists $hooks{getopt}) {
  68. foreach my $id (keys %{$hooks{getopt}}) {
  69. $hooks{getopt}{$id}{call}->();
  70. }
  71. }
  72. if (grep /^-/, @ARGV) {
  73. print STDERR "Unknown option: $_\n"
  74. foreach grep /^-/, @ARGV;
  75. usage();
  76. }
  77. usage() unless @ARGV == 2;
  78. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  79. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  80. checkconfig();
  81. }
  82. }
  83. else {
  84. # wrapper passes a full config structure in the environment
  85. # variable
  86. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  87. if ($@) {
  88. error("WRAPPED_OPTIONS: $@");
  89. }
  90. loadplugins();
  91. checkconfig();
  92. }
  93. } #}}}
  94. sub main () { #{{{
  95. getconfig();
  96. if ($config{cgi}) {
  97. lockwiki();
  98. loadindex();
  99. require IkiWiki::CGI;
  100. cgi();
  101. }
  102. elsif ($config{setup}) {
  103. require IkiWiki::Setup;
  104. setup();
  105. }
  106. elsif ($config{wrapper}) {
  107. lockwiki();
  108. require IkiWiki::Wrapper;
  109. gen_wrapper();
  110. }
  111. else {
  112. lockwiki();
  113. loadindex();
  114. require IkiWiki::Render;
  115. rcs_update();
  116. refresh();
  117. rcs_notify() if $config{notify};
  118. saveindex();
  119. }
  120. } #}}}
  121. main;