summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 8c46d5e9f333d09866f993da657df53b819390db (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 in nonstandard directory, munged by Makefile.
  8. use IkiWiki;
  9. sub usage () { #{{{
  10. die gettext("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. "syslog!" => \$config{syslog},
  22. "rebuild!" => \$config{rebuild},
  23. "refresh!" => \$config{refresh},
  24. "post-commit" => \$config{post_commit},
  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. "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. "sslcookie!" => \$config{sslcookie},
  44. "httpauth!" => \$config{httpauth},
  45. "userdir=s" => \$config{userdir},
  46. "exclude=s@" => sub {
  47. push @{$config{wiki_file_prune_regexps}}, $_[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. push @{$config{disable_plugins}}, $_[1];
  66. },
  67. "pingurl=s" => sub {
  68. push @{$config{pingurl}}, $_[1];
  69. },
  70. "version" => sub {
  71. print "ikiwiki version $IkiWiki::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. 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. elsif ($config{render}) {
  111. require IkiWiki::Render;
  112. commandline_render();
  113. }
  114. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  115. if ($config{notify}) {
  116. loadindex();
  117. rcs_notify();
  118. }
  119. }
  120. else {
  121. lockwiki();
  122. loadindex();
  123. require IkiWiki::Render;
  124. rcs_update();
  125. refresh();
  126. rcs_notify() if $config{notify};
  127. saveindex();
  128. }
  129. } #}}}
  130. main;