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