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