make_archive.pl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/usr/bin/perl
  2. #
  3. # This all could (maybe) be done in a shell script, but I suck at those.
  4. $i = 0;
  5. $Verbose = 0;
  6. $Plugin = "";
  7. $Version = "";
  8. $SMVersion = "";
  9. foreach $arg (@ARGV)
  10. {
  11. if ($arg eq "-v")
  12. {
  13. $Verbose = 1;
  14. }
  15. elsif ($Plugin eq "")
  16. {
  17. $Plugin = $arg;
  18. }
  19. elsif ($Version eq "")
  20. {
  21. $Version = $arg;
  22. }
  23. elsif ($SMVersion eq "")
  24. {
  25. $SMVersion = $arg;
  26. }
  27. else
  28. {
  29. print "Unrecognized argument: $arg\n";
  30. exit(0);
  31. }
  32. }
  33. if ($SMVersion eq "")
  34. {
  35. print "Syntax: make_archive.pl [-v] plugin_name version sm_version\n";
  36. print "-v = be verbose\n";
  37. print "plugin_name: The name of the plugin\n";
  38. print "version: The plugin's version number (1.0, 2.3, etc)\n";
  39. print "sm_version: The oldest version of SquirrelMail that this\n";
  40. print " plugin is for sure compatible with (1.0.1, 0.5, 1.1.0, etc)\n";
  41. exit(0);
  42. }
  43. print "Validating name and version\n" if ($Verbose);
  44. $Plugin =~ s/\///g;
  45. if ($Plugin =~ /[^a-z_]/)
  46. {
  47. print "Plugin name can only contain a-z and _\n";
  48. exit(0);
  49. }
  50. if ($Version =~ /[^\.0-9]/ || $SMVersion =~ /[^\.0-9]/)
  51. {
  52. print "Version numbers can only have 0-9 and period\n";
  53. exit(0);
  54. }
  55. VerifyPluginDir($Plugin);
  56. print "Getting file list.\n" if ($Verbose);
  57. @Files = RecurseDir($Plugin);
  58. $QuietString = " > /dev/null 2> /dev/null" if (! $Verbose);
  59. print "\n\n" if ($Verbose);
  60. print "Creating $Plugin.$Version-$SMVersion.tar.gz\n";
  61. system("tar cvfz $Plugin.$Version-$SMVersion.tar.gz $Plugin" .
  62. FindTarExcludes(@Files) . $QuietString);
  63. #print "\n\n" if ($Verbose);
  64. #print "Creating $Plugin.$Version-$SMVersion.zip\n";
  65. #system("zip -r $Plugin.$Version-$SMVersion.zip $Plugin/" .
  66. # FindZipExcludes(@Files) . $QuietString);
  67. sub VerifyPluginDir
  68. {
  69. local ($Plugin) = @_;
  70. if (! -e $Plugin && ! -d $Plugin)
  71. {
  72. print "The $Plugin directory doesn't exist, " .
  73. "or else it is not a directory.\n";
  74. exit(0);
  75. }
  76. }
  77. sub FindTarExcludes
  78. {
  79. local (@Files) = @_;
  80. $ExcludeStr = "";
  81. foreach $File (@Files)
  82. {
  83. if ($File =~ /^(.*\/CVS)\/$/)
  84. {
  85. $ExcludeStr .= " --exclude $1";
  86. }
  87. }
  88. return $ExcludeStr;
  89. }
  90. sub FindZipExcludes
  91. {
  92. local (@Files) = @_;
  93. $ExcludeStr = "";
  94. foreach $File (@Files)
  95. {
  96. if ($File =~ /^(.*\/CVS)\/$/)
  97. {
  98. $ExcludeStr .= " $1/ $1/*";
  99. }
  100. }
  101. if ($ExcludeStr ne "")
  102. {
  103. $ExcludeStr = " -x" . $ExcludeStr;
  104. }
  105. return $ExcludeStr;
  106. }
  107. sub RecurseDir
  108. {
  109. local ($Dir) = @_;
  110. local (@Files, @Results);
  111. opendir(DIR, $Dir);
  112. @Files = readdir(DIR);
  113. closedir(DIR);
  114. @Results = ("$Dir/");
  115. foreach $file (@Files)
  116. {
  117. next if ($file =~ /^[\.]+/);
  118. if (-d "$Dir/$file")
  119. {
  120. push (@Results, RecurseDir("$Dir/$file"));
  121. }
  122. else
  123. {
  124. push (@Results, "$Dir/$file");
  125. }
  126. }
  127. return @Results;
  128. }