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