summaryrefslogtreecommitdiff
path: root/ikiwiki.in
blob: 5dd1064f9fd6900d302dcde2128f35f67cffb09d (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. "render=s" => \$config{render},
  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. "cgi!" => \$config{cgi},
  31. "discussion!" => \$config{discussion},
  32. "w3mmode!" => \$config{w3mmode},
  33. "notify!" => \$config{notify},
  34. "url=s" => \$config{url},
  35. "cgiurl=s" => \$config{cgiurl},
  36. "historyurl=s" => \$config{historyurl},
  37. "diffurl=s" => \$config{diffurl},
  38. "svnrepo" => \$config{svnrepo},
  39. "svnpath" => \$config{svnpath},
  40. "adminemail=s" => \$config{adminemail},
  41. "timeformat=s" => \$config{timeformat},
  42. "sslcookie!" => \$config{sslcookie},
  43. "httpauth!" => \$config{httpauth},
  44. "userdir=s" => \$config{userdir},
  45. "exclude=s@" => sub {
  46. push @{$config{wiki_file_prune_regexps}}, $_[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. push @{$config{disable_plugins}}, $_[1];
  65. },
  66. "pingurl=s" => sub {
  67. push @{$config{pingurl}}, $_[1];
  68. },
  69. "version" => sub {
  70. print "ikiwiki version $IkiWiki::version\n";
  71. exit;
  72. },
  73. ) || usage();
  74. if (! $config{setup} && ! $config{render}) {
  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. 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. elsif ($config{render}) {
  110. require IkiWiki::Render;
  111. commandline_render();
  112. }
  113. elsif ($config{post_commit} && ! commit_hook_enabled()) {
  114. if ($config{notify}) {
  115. loadindex();
  116. rcs_notify();
  117. }
  118. }
  119. else {
  120. lockwiki();
  121. loadindex();
  122. require IkiWiki::Render;
  123. rcs_update();
  124. refresh();
  125. rcs_notify() if $config{notify};
  126. saveindex();
  127. }
  128. } #}}}
  129. main;