Typo
[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";
a42ccc65 70system("tar cvfz $Plugin.$Version-$SMVersion.tar.gz $Plugin" .
71 FindTarExcludes(@Files) . $QuietString);
2a6b3977 72
bb4b69ac 73#print "\n\n" if ($Verbose);
a42ccc65 74#print "Creating $Plugin.$Version-$SMVersion.zip\n";
75#system("zip -r $Plugin.$Version-$SMVersion.zip $Plugin/" .
76# FindZipExcludes(@Files) . $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 {
a42ccc65 103 $ExcludeStr .= " --exclude $1";
2a6b3977 104 }
105 }
106
2a6b3977 107 return $ExcludeStr;
108}
109
110sub FindZipExcludes
111{
112 local (@Files) = @_;
113
114 $ExcludeStr = "";
115
116 foreach $File (@Files)
117 {
118 if ($File =~ /^(.*\/CVS)\/$/)
119 {
120 $ExcludeStr .= " $1/ $1/*";
121 }
122 }
123
124 if ($ExcludeStr ne "")
125 {
126 $ExcludeStr = " -x" . $ExcludeStr;
127 }
128
129 return $ExcludeStr;
130}
131
132sub RecurseDir
133{
134 local ($Dir) = @_;
135 local (@Files, @Results);
136
137 opendir(DIR, $Dir);
138 @Files = readdir(DIR);
139 closedir(DIR);
140
141 @Results = ("$Dir/");
142
143 foreach $file (@Files)
144 {
145 next if ($file =~ /^[\.]+/);
146 if (-d "$Dir/$file")
147 {
148 push (@Results, RecurseDir("$Dir/$file"));
149 }
150 else
151 {
152 push (@Results, "$Dir/$file");
153 }
154 }
155
156 return @Results;
157}