summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 3ea6b7aa05109ab47234a73eb161f023ee049c58 (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. "exclude=s@" => sub {
  38. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
  39. },
  40. "adminuser=s@" => sub {
  41. push @{$config{adminuser}}, $_[1]
  42. },
  43. "templatedir=s" => sub {
  44. $config{templatedir}=possibly_foolish_untaint($_[1])
  45. },
  46. "underlaydir=s" => sub {
  47. $config{underlaydir}=possibly_foolish_untaint($_[1])
  48. },
  49. "wrapper:s" => sub {
  50. $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
  51. },
  52. "plugin=s@" => sub {
  53. push @{$config{plugin}}, $_[1];
  54. },
  55. "disable-plugin=s@" => sub {
  56. $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}} ];
  57. },
  58. ) || usage();
  59. if (! $config{setup}) {
  60. usage() unless @ARGV == 2;
  61. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  62. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  63. checkconfig();
  64. }
  65. }
  66. else {
  67. # wrapper passes a full config structure in the environment
  68. # variable
  69. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  70. if ($@) {
  71. error("WRAPPED_OPTIONS: $@");
  72. }
  73. checkconfig();
  74. }
  75. } #}}}
  76. sub main () { #{{{
  77. getconfig();
  78. if ($config{cgi}) {
  79. lockwiki();
  80. loadindex();
  81. require IkiWiki::CGI;
  82. cgi();
  83. }
  84. elsif ($config{setup}) {
  85. require IkiWiki::Setup;
  86. setup();
  87. }
  88. elsif ($config{wrapper}) {
  89. lockwiki();
  90. require IkiWiki::Wrapper;
  91. gen_wrapper();
  92. }
  93. else {
  94. lockwiki();
  95. loadindex();
  96. require IkiWiki::Render;
  97. rcs_update();
  98. refresh();
  99. rcs_notify() if $config{notify};
  100. saveindex();
  101. }
  102. } #}}}
  103. main;