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