summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 28eba6f64e98e1298e9a32e61dbe6cb1f2897847 (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. run_hooks(getopt => sub { shift->() });
  68. if (grep /^-/, @ARGV) {
  69. print STDERR "Unknown option: $_\n"
  70. foreach grep /^-/, @ARGV;
  71. usage();
  72. }
  73. usage() unless @ARGV == 2;
  74. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  75. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  76. checkconfig();
  77. }
  78. }
  79. else {
  80. # wrapper passes a full config structure in the environment
  81. # variable
  82. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  83. if ($@) {
  84. error("WRAPPED_OPTIONS: $@");
  85. }
  86. loadplugins();
  87. checkconfig();
  88. }
  89. } #}}}
  90. sub main () { #{{{
  91. getconfig();
  92. if ($config{cgi}) {
  93. lockwiki();
  94. loadindex();
  95. require IkiWiki::CGI;
  96. cgi();
  97. }
  98. elsif ($config{setup}) {
  99. require IkiWiki::Setup;
  100. setup();
  101. }
  102. elsif ($config{wrapper}) {
  103. lockwiki();
  104. require IkiWiki::Wrapper;
  105. gen_wrapper();
  106. }
  107. else {
  108. lockwiki();
  109. loadindex();
  110. require IkiWiki::Render;
  111. rcs_update();
  112. refresh();
  113. rcs_notify() if $config{notify};
  114. saveindex();
  115. }
  116. } #}}}
  117. main;