* Now supports the new naming scheme
[squirrelmail.git] / plugins / make_archive.pl
CommitLineData
2a6b3977 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 = "";
bb4b69ac 9$SMVersion = "";
2a6b3977 10
11foreach $arg (@ARGV)
12{
13 if ($arg eq "-v")
14 {
15 $Verbose = 1;
16 }
17 elsif ($Plugin eq "")
18 {
19 $Plugin = $arg;
20 }
21 elsif ($Version eq "")
22 {
23 $Version = $arg;
24 }
bb4b69ac 25 elsif ($SMVersion eq "")
26 {
27 $SMVersion = $arg;
28 }
2a6b3977 29 else
30 {
31 print "Unrecognized argument: $arg\n";
32 exit(0);
33 }
34}
35
bb4b69ac 36if ($SMVersion eq "")
2a6b3977 37{
bb4b69ac 38 print "Syntax: make_archive.pl [-v] plugin_name version sm_version\n";
2a6b3977 39 print "-v = be verbose\n";
bb4b69ac 40 print "plugin_name: The name of the plugin\n";
41 print "version: The plugin's version number (1.0, 2.3, etc)\n";
42 print "sm_version: The oldest version of SquirrelMail that this\n";
43 print " plugin is for sure compatible with (1.0.1, 0.5, 1.1.0, etc)\n";
2a6b3977 44 exit(0);
45}
46
47
bb4b69ac 48print "Validating name and version\n" if ($Verbose);
2a6b3977 49$Plugin =~ s/\///g;
bb4b69ac 50if ($Plugin =~ /[^a-z_]/)
51{
52 print "Plugin name can only contain a-z and _\n";
53 exit(0);
54}
55if ($Version =~ /[^\.0-9]/ || $SMVersion =~ /[^\.0-9]/)
56{
57 print "Version numbers can only have 0-9 and period\n";
58 exit(0);
59}
2a6b3977 60
bb4b69ac 61VerifyPluginDir($Plugin);
2a6b3977 62
63print "Getting file list.\n" if ($Verbose);
64@Files = RecurseDir($Plugin);
65
66$QuietString = " > /dev/null 2> /dev/null" if (! $Verbose);
67
68print "\n\n" if ($Verbose);
bb4b69ac 69print "Creating $Plugin.$Version-$SMVersion.tar.gz\n";
2a6b3977 70system("tar cvfz $Plugin-$Version.tar.gz $Plugin" . FindTarExcludes(@Files)
71 . $QuietString);
72
bb4b69ac 73#print "\n\n" if ($Verbose);
74#print "Creating $Plugin-$Version.zip\n";
75#system("zip -r $Plugin-$Version.zip $Plugin/" . FindZipExcludes(@Files)
76# . $QuietString);
2a6b3977 77
78
79
bb4b69ac 80sub VerifyPluginDir
2a6b3977 81{
bb4b69ac 82 local ($Plugin) = @_;
2a6b3977 83
84 if (! -e $Plugin && ! -d $Plugin)
85 {
86 print "The $Plugin directory doesn't exist, " .
87 "or else it is not a directory.\n";
88 exit(0);
89 }
90}
91
92
93sub FindTarExcludes
94{
95 local (@Files) = @_;
96
97 $ExcludeStr = "";
98
99 foreach $File (@Files)
100 {
101 if ($File =~ /^(.*\/CVS)\/$/)
102 {
103 $ExcludeStr .= " $1";
104 }
105 }
106
107 if ($ExcludeStr ne "")
108 {
109 $ExcludeStr = " --exclude" . $ExcludeStr;
110 }
111
112 return $ExcludeStr;
113}
114
115sub FindZipExcludes
116{
117 local (@Files) = @_;
118
119 $ExcludeStr = "";
120
121 foreach $File (@Files)
122 {
123 if ($File =~ /^(.*\/CVS)\/$/)
124 {
125 $ExcludeStr .= " $1/ $1/*";
126 }
127 }
128
129 if ($ExcludeStr ne "")
130 {
131 $ExcludeStr = " -x" . $ExcludeStr;
132 }
133
134 return $ExcludeStr;
135}
136
137sub RecurseDir
138{
139 local ($Dir) = @_;
140 local (@Files, @Results);
141
142 opendir(DIR, $Dir);
143 @Files = readdir(DIR);
144 closedir(DIR);
145
146 @Results = ("$Dir/");
147
148 foreach $file (@Files)
149 {
150 next if ($file =~ /^[\.]+/);
151 if (-d "$Dir/$file")
152 {
153 push (@Results, RecurseDir("$Dir/$file"));
154 }
155 else
156 {
157 push (@Results, "$Dir/$file");
158 }
159 }
160
161 return @Results;
162}