summaryrefslogtreecommitdiff
path: root/ikiwiki.pl
blob: fd9300fbabed31f31413ab7efd6fb044e3ea11ad (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. our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
  6. use warnings;
  7. use strict;
  8. use lib '.'; # For use without installation, removed by Makefile.
  9. use IkiWiki;
  10. sub usage () { #{{{
  11. die "usage: ikiwiki [options] source dest\n";
  12. } #}}}
  13. sub getconfig () { #{{{
  14. if (! exists $ENV{WRAPPED_OPTIONS}) {
  15. %config=defaultconfig();
  16. eval q{use Getopt::Long};
  17. Getopt::Long::Configure('pass_through');
  18. GetOptions(
  19. "setup|s=s" => \$config{setup},
  20. "wikiname=s" => \$config{wikiname},
  21. "verbose|v!" => \$config{verbose},
  22. "rebuild!" => \$config{rebuild},
  23. "refresh!" => \$config{refresh},
  24. "wrappers!" => \$config{wrappers},
  25. "getctime" => \$config{getctime},
  26. "wrappermode=i" => \$config{wrappermode},
  27. "rcs=s" => \$config{rcs},
  28. "no-rcs" => sub { $config{rcs}="" },
  29. "anonok!" => \$config{anonok},
  30. "rss!" => \$config{rss},
  31. "cgi!" => \$config{cgi},
  32. "discussion!" => \$config{discussion},
  33. "w3mmode!" => \$config{w3mmode},
  34. "notify!" => \$config{notify},
  35. "url=s" => \$config{url},
  36. "cgiurl=s" => \$config{cgiurl},
  37. "historyurl=s" => \$config{historyurl},
  38. "diffurl=s" => \$config{diffurl},
  39. "svnrepo" => \$config{svnrepo},
  40. "svnpath" => \$config{svnpath},
  41. "adminemail=s" => \$config{adminemail},
  42. "timeformat=s" => \$config{timeformat},
  43. "exclude=s@" => sub {
  44. $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/;
  45. },
  46. "adminuser=s@" => sub {
  47. push @{$config{adminuser}}, $_[1]
  48. },
  49. "templatedir=s" => sub {
  50. $config{templatedir}=possibly_foolish_untaint($_[1])
  51. },
  52. "underlaydir=s" => sub {
  53. $config{underlaydir}=possibly_foolish_untaint($_[1])
  54. },
  55. "wrapper:s" => sub {
  56. $config{wrapper}=$_[1] ? $_[1] : "ikiwiki-wrap"
  57. },
  58. "plugin=s@" => sub {
  59. push @{$config{plugin}}, $_[1];
  60. },
  61. "disable-plugin=s@" => sub {
  62. $config{plugin}=[grep { $_ ne $_[1] } @{$config{plugin}}];
  63. },
  64. "pingurl" => sub {
  65. push @{$config{pingurl}}, $_[1];
  66. },
  67. "version" => sub {
  68. print "ikiwiki version $version\n";
  69. exit;
  70. },
  71. ) || usage();
  72. if (! $config{setup}) {
  73. loadplugins();
  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;