supernets anope source code & configuration https://www.anope.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extras 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/usr/bin/env perl
  2. #
  3. # Script taken from InspIRCd, www.inspircd.org
  4. #
  5. # This program is distributed in the hope that it will be useful, but WITHOUT
  6. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  7. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  8. # details.
  9. #
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. #
  13. BEGIN { require 5.8.0; }
  14. use strict;
  15. use warnings FATAL => qw(all);
  16. use File::Copy ();
  17. use Cwd;
  18. sub list_extras ();
  19. sub enable_extras (@);
  20. sub disable_extras (@);
  21. # Routine to list out the extra/ modules that have been enabled.
  22. # Note: when getting any filenames out and comparing, it's important to lc it if the
  23. # file system is not case-sensitive (== Epoc, MacOS, OS/2 (incl DOS/DJGPP), VMS, Win32
  24. # (incl NetWare, Symbian)). Cygwin may or may not be case-sensitive, depending on
  25. # configuration, however, File::Spec does not currently tell us (it assumes Unix behavior).
  26. sub list_extras () {
  27. use File::Spec;
  28. # @_ not used
  29. my $srcdir = File::Spec->catdir("modules");
  30. my $abs_srcdir = File::Spec->rel2abs($srcdir);
  31. local $_;
  32. my $dd;
  33. opendir $dd, File::Spec->catdir($abs_srcdir, "extra") or die (File::Spec->catdir($abs_srcdir, "extra") . ": $!\n");
  34. my @extras = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
  35. closedir $dd;
  36. undef $dd;
  37. opendir $dd, $abs_srcdir or die "$abs_srcdir: $!\n";
  38. my @sources = map { File::Spec->case_tolerant() ? lc($_) : $_ } (readdir($dd));
  39. closedir $dd;
  40. undef $dd;
  41. my $maxlen = (sort { $b <=> $a } (map {length($_)} (@extras)))[0];
  42. my %extras = ();
  43. EXTRA: for my $extra (@extras) {
  44. next if (File::Spec->curdir() eq $extra || File::Spec->updir() eq $extra);
  45. my $abs_extra = File::Spec->catfile($abs_srcdir, "extra", $extra);
  46. my $abs_source = File::Spec->catfile($abs_srcdir, $extra);
  47. next unless ($extra =~ m/\.(cpp|h)$/ || (-d $abs_extra)); # C++ Source/Header, or directory
  48. if (-l $abs_source) {
  49. # Symlink, is it in the right place?
  50. my $targ = readlink($abs_source);
  51. my $abs_targ = File::Spec->rel2abs($targ, $abs_srcdir);
  52. if ($abs_targ eq $abs_extra) {
  53. $extras{$extra} = "\e[32;1menabled\e[0m";
  54. } else {
  55. $extras{$extra} = sprintf("\e[31;1mwrong symlink target (%s)\e[0m", $abs_targ);
  56. }
  57. } elsif (-e $abs_source) {
  58. my ($devext, $inoext) = stat($abs_extra);
  59. my ($devsrc, $inosrc, undef, $lnksrc) = stat($abs_source);
  60. if ($lnksrc > 1) {
  61. if ($devsrc == $devext && $inosrc == $inoext) {
  62. $extras{$extra} = "\e[32;1menabled\e[0m";
  63. } else {
  64. $extras{$extra} = sprintf("\e[31;1mwrong hardlink target (%d:%d)\e[0m", $devsrc, $inosrc);
  65. }
  66. } else {
  67. open my $extfd, "<", $abs_extra;
  68. open my $srcfd, "<", $abs_source;
  69. local $/ = undef;
  70. if (scalar(<$extfd>) eq scalar(<$srcfd>)) {
  71. $extras{$extra} = "\e[32;1menabled\e[0m";
  72. } else {
  73. $extras{$extra} = sprintf("\e[31;1mout of synch (re-copy)\e[0m");
  74. }
  75. }
  76. } else {
  77. $extras{$extra} = "\e[33;1mdisabled\e[0m";
  78. }
  79. }
  80. for my $extra (sort {$a cmp $b} keys(%extras)) {
  81. my $text = $extras{$extra};
  82. if ($text =~ m/needed by/ && $text !~ m/enabled/) {
  83. printf "\e[31;1;5m%-*s = %s%s\e[0m\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? ")" : "");
  84. } else {
  85. printf "%-*s = %s%s\n", $maxlen, $extra, $text, ($text =~ m/needed by/ ? "\e[0m)" : "");
  86. }
  87. }
  88. return keys(%extras) if wantarray; # Can be used by manage_extras.
  89. }
  90. sub enable_extras (@) {
  91. my (@extras) = @_;
  92. for my $extra (@extras) {
  93. my $extrapath = "modules/extra/$extra";
  94. if (!-e $extrapath) {
  95. print STDERR "Cannot enable \e[32;1m$extra\e[0m : No such file or directory in modules/extra\n";
  96. next;
  97. }
  98. my $source = "modules/$extra";
  99. if (-e $source) {
  100. print STDERR "Cannot enable \e[32;1m$extra\e[0m : destination in modules exists (might already be enabled?)\n";
  101. next;
  102. }
  103. print "Enabling $extra ... \n";
  104. symlink "extra/$extra", $source or print STDERR "$source: Cannot link to 'extra/$extra': $!\n";
  105. }
  106. }
  107. sub disable_extras (@)
  108. {
  109. opendir my $dd, "modules/extra/";
  110. my @files = readdir($dd);
  111. closedir $dd;
  112. my (@extras) = @_;
  113. EXTRA: for my $extra (@extras) {
  114. my $extrapath = "modules/extra/$extra";
  115. my $source = "modules/$extra";
  116. if (!-e $extrapath) {
  117. print STDERR "Cannot disable \e[32;1m$extra\e[0m : Is not an extra\n";
  118. next;
  119. }
  120. if ((! -l $source) || readlink($source) ne "extra/$extra") {
  121. print STDERR "Cannot disable \e[32;1m$extra\e[0m : Source is not a link or doesn't refer to the right file. Remove manually if this is in error.\n";
  122. next;
  123. }
  124. # Now remove.
  125. print "Disabling $extra ... \n";
  126. unlink "modules/$extra" or print STDERR "Cannot disable \e[32;1m$extra\e[0m : $!\n";
  127. }
  128. }
  129. my $clearscreen = `clear`;
  130. print $clearscreen;
  131. while (1)
  132. {
  133. list_extras; # print the module list
  134. print "\nPlease enter the name of the module or type 'q' to quit.: ";
  135. my $input = <STDIN>;
  136. chop($input); # remove the trailing \n from the user input
  137. if ($input eq "q") {
  138. if (-e "build/CMakeFiles") {
  139. system("cmake", "build/.");
  140. print "\nNow cd build, then run make to build Anope.\n\n";
  141. } else {
  142. print "\nBuild directory not found. You should run ./Config now.\n\n"
  143. }
  144. exit 0;
  145. }
  146. print $clearscreen;
  147. if ($input eq "") {
  148. next;
  149. }
  150. if (-e "modules/$input") {
  151. disable_extras($input)
  152. } else {
  153. enable_extras($input)
  154. }
  155. }