Split out functionality that gathers system specs
[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-$SMVersion.tar.gz $Plugin" .
71 FindTarExcludes(@Files) . $QuietString);
72
73 #print "\n\n" if ($Verbose);
74 #print "Creating $Plugin.$Version-$SMVersion.zip\n";
75 #system("zip -r $Plugin.$Version-$SMVersion.zip $Plugin/" .
76 # FindZipExcludes(@Files) . $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 .= " --exclude $1";
104 }
105 }
106
107 return $ExcludeStr;
108 }
109
110 sub 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
132 sub 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 }