summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 61b66374de58924d081218292289c777306e8e0d (plain)
  1. #!/usr/bin/perl -T -CSD
  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. GetOptions(
  16. "setup|s=s" => \$config{setup},
  17. "wikiname=s" => \$config{wikiname},
  18. "verbose|v!" => \$config{verbose},
  19. "rebuild!" => \$config{rebuild},
  20. "refresh!" => \$config{refresh},
  21. "getctime" => \$config{getctime},
  22. "wrappermode=i" => \$config{wrappermode},
  23. "rcs=s" => \$config{rcs},
  24. "no-rcs" => sub { $config{rcs}="" },
  25. "anonok!" => \$config{anonok},
  26. "rss!" => \$config{rss},
  27. "cgi!" => \$config{cgi},
  28. "discussion!" => \$config{discussion},
  29. "notify!" => \$config{notify},
  30. "url=s" => \$config{url},
  31. "cgiurl=s" => \$config{cgiurl},
  32. "historyurl=s" => \$config{historyurl},
  33. "diffurl=s" => \$config{diffurl},
  34. "svnrepo" => \$config{svnrepo},
  35. "svnpath" => \$config{svnpath},
  36. "adminemail=s" => \$config{adminemail},
  37. "timeformat=s" => \$config{timeformat},
  38. "exclude=s@" => sub {
  39. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
  40. },
  41. "adminuser=s@" => sub {
  42. push @{$config{adminuser}}, $_[1]
  43. },
  44. "templatedir=s" => sub {
  45. $config{templatedir}=possibly_foolish_untaint($_[1])
  46. },
  47. "underlaydir=s" => sub {
  48. $config{underlaydir}=possibly_foolish_untaint($_[1])
  49. },
  50. "wrapper:s" => sub {
  51. $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
  52. },
  53. "plugin=s@" => sub {
  54. push @{$config{plugin}}, $_[1];
  55. },
  56. "disable-plugin=s@" => sub {
  57. $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}} ];
  58. },
  59. ) || usage();
  60. if (! $config{setup}) {
  61. usage() unless @ARGV == 2;
  62. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  63. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  64. checkconfig();
  65. }
  66. }
  67. else {
  68. # wrapper passes a full config structure in the environment
  69. # variable
  70. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  71. if ($@) {
  72. error("WRAPPED_OPTIONS: $@");
  73. }
  74. checkconfig();
  75. }
  76. } #}}}
  77. sub main () { #{{{
  78. getconfig();
  79. if ($config{cgi}) {
  80. lockwiki();
  81. loadindex();
  82. require IkiWiki::CGI;
  83. cgi();
  84. }
  85. elsif ($config{setup}) {
  86. require IkiWiki::Setup;
  87. setup();
  88. }
  89. elsif ($config{wrapper}) {
  90. lockwiki();
  91. require IkiWiki::Wrapper;
  92. gen_wrapper();
  93. }
  94. else {
  95. lockwiki();
  96. loadindex();
  97. require IkiWiki::Render;
  98. rcs_update();
  99. refresh();
  100. rcs_notify() if $config{notify};
  101. saveindex();
  102. }
  103. } #}}}
  104. main;