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