f593bf9bae9e790e9d1081d97af737cc5c160766
[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 $SMVersion = "";
10
11 foreach $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 }
25 elsif ($SMVersion eq "")
26 {
27 $SMVersion = $arg;
28 }
29 else
30 {
31 print "Unrecognized argument: $arg\n";
32 exit(0);
33 }
34 }
35
36 if ($SMVersion eq "")
37 {
38 print "Syntax: make_archive.pl [-v] plugin_name version sm_version\n";
39 print "-v = be verbose\n";
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";
44 exit(0);
45 }
46
47
48 print "Validating name and version\n" if ($Verbose);
49 $Plugin =~ s/\///g;
50 if ($Plugin =~ /[^a-z_]/)
51 {
52 print "Plugin name can only contain a-z and _\n";
53 exit(0);
54 }
55 if ($Version =~ /[^\.0-9]/ || $SMVersion =~ /[^\.0-9]/)
56 {
57 print "Version numbers can only have 0-9 and period\n";
58 exit(0);
59 }
60
61 VerifyPluginDir($Plugin);
62
63 print "Getting file list.\n" if ($Verbose);
64 @Files = RecurseDir($Plugin);
65
66 $QuietString = " > /dev/null 2> /dev/null" if (! $Verbose);
67
68 print "\n\n" if ($Verbose);
69 print "Creating $Plugin.$Version-$SMVersion.tar.gz\n";
70 system("tar cvfz $Plugin-$Version.tar.gz $Plugin" . FindTarExcludes(@Files)
71 . $QuietString);
72
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);
77
78
79
80 sub VerifyPluginDir
81 {
82 local ($Plugin) = @_;
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
93 sub 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
115 sub 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
137 sub 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 }