summaryrefslogtreecommitdiff
path: root/ikiwiki
blob: 1342ec543f3e54c216e16cb615e9493c67484e8a (plain)
  1. #!/usr/bin/perl -T
  2. $ENV{PATH}="/usr/local/bin:/usr/bin:/bin";
  3. delete @ENV{qw{IFS CDPATH ENV BASH_ENV}};
  4. package IkiWiki;
  5. use warnings;
  6. use strict;
  7. use lib '.'; # For use without installation, removed by Makefile.
  8. use IkiWiki;
  9. sub usage () { #{{{
  10. die "usage: ikiwiki [options] source dest\n";
  11. } #}}}
  12. sub getconfig () { #{{{
  13. if (! exists $ENV{WRAPPED_OPTIONS}) {
  14. %config=defaultconfig();
  15. eval q{use Getopt::Long};
  16. Getopt::Long::Configure('pass_through');
  17. GetOptions(
  18. "setup|s=s" => \$config{setup},
  19. "wikiname=s" => \$config{wikiname},
  20. "verbose|v!" => \$config{verbose},
  21. "rebuild!" => \$config{rebuild},
  22. "refresh!" => \$config{refresh},
  23. "wrappers!" => \$config{wrappers},
  24. "getctime" => \$config{getctime},
  25. "wrappermode=i" => \$config{wrappermode},
  26. "rcs=s" => \$config{rcs},
  27. "no-rcs" => sub { $config{rcs}="" },
  28. "anonok!" => \$config{anonok},
  29. "rss!" => \$config{rss},
  30. "cgi!" => \$config{cgi},
  31. "discussion!" => \$config{discussion},
  32. "w3mmode!" => \$config{w3mmode},
  33. "notify!" => \$config{notify},
  34. "url=s" => \$config{url},
  35. "cgiurl=s" => \$config{cgiurl},
  36. "historyurl=s" => \$config{historyurl},
  37. "diffurl=s" => \$config{diffurl},
  38. "svnrepo" => \$config{svnrepo},
  39. "svnpath" => \$config{svnpath},
  40. "adminemail=s" => \$config{adminemail},
  41. "timeformat=s" => \$config{timeformat},
  42. "exclude=s@" => sub {
  43. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
  44. },
  45. "adminuser=s@" => sub {
  46. push @{$config{adminuser}}, $_[1]
  47. },
  48. "templatedir=s" => sub {
  49. $config{templatedir}=possibly_foolish_untaint($_[1])
  50. },
  51. "underlaydir=s" => sub {
  52. $config{underlaydir}=possibly_foolish_untaint($_[1])
  53. },
  54. "wrapper:s" => sub {
  55. $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
  56. },
  57. "plugin=s@" => sub {
  58. push @{$config{plugin}}, $_[1];
  59. },
  60. "disable-plugin=s@" => sub {
  61. $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
  62. },
  63. "pingurl" => sub {
  64. push @{$config{pingurl}}, $_[1];
  65. }
  66. ) || usage();
  67. if (! $config{setup}) {
  68. loadplugins();
  69. usage() unless @ARGV == 2;
  70. $config{srcdir} = possibly_foolish_untaint(shift @ARGV);
  71. $config{destdir} = possibly_foolish_untaint(shift @ARGV);
  72. checkconfig();
  73. }
  74. }
  75. else {
  76. # wrapper passes a full config structure in the environment
  77. # variable
  78. eval possibly_foolish_untaint($ENV{WRAPPED_OPTIONS});
  79. if ($@) {
  80. error("WRAPPED_OPTIONS: $@");
  81. }
  82. loadplugins();
  83. checkconfig();
  84. }
  85. } #}}}
  86. sub main () { #{{{
  87. getconfig();
  88. if ($config{cgi}) {
  89. lockwiki();
  90. loadindex();
  91. require IkiWiki::CGI;
  92. cgi();
  93. }
  94. elsif ($config{setup}) {
  95. require IkiWiki::Setup;
  96. setup();
  97. }
  98. elsif ($config{wrapper}) {
  99. lockwiki();
  100. require IkiWiki::Wrapper;
  101. gen_wrapper();
  102. }
  103. else {
  104. lockwiki();
  105. loadindex();
  106. require IkiWiki::Render;
  107. rcs_update();
  108. refresh();
  109. rcs_notify() if $config{notify};
  110. saveindex();
  111. }
  112. } #}}}
  113. main;