Exim module
[webmin.git] / makedist.pl
1 #!/usr/local/bin/perl
2 # Builds a tar.gz package of a specified Webmin version
3
4 @ARGV == 1 || @ARGV == 2 || usage();
5 if ($ARGV[0] eq "-minimal" || $ARGV[0] eq "--minimal") {
6         $min++;
7         shift(@ARGV);
8         }
9 $vers = $ARGV[0];
10 $vers =~ /^[0-9\.]+$/ || usage();
11 $tardir = $min ? "minimal" : "tarballs";
12 $vfile = $min ? "$vers-minimal" : $vers;
13 $zipdir = "zips";
14
15 @files = ("config.cgi", "config-*-linux",
16           "config-solaris", "images", "index.cgi", "mime.types",
17           "miniserv.pl", "os_list.txt", "perlpath.pl", "setup.sh", "setup.pl",
18           "version", "web-lib.pl", "web-lib-funcs.pl", "README",
19           "config_save.cgi", "chooser.cgi", "miniserv.pem",
20           "config-aix",
21           "newmods.pl", "copyconfig.pl", "config-hpux", "config-freebsd",
22           "changepass.pl", "help.cgi", "user_chooser.cgi",
23           "group_chooser.cgi", "config-irix", "config-osf1", "thirdparty.pl",
24           "oschooser.pl", "config-unixware",
25           "config-openserver", "switch_user.cgi", "lang", "lang_list.txt",
26           "webmin-init", "webmin-caldera-init", "webmin-daemon",
27           "config-openbsd",
28           "config-macos", "LICENCE", "PATENTS",
29           "session_login.cgi", "acl_security.pl",
30           "defaultacl", "rpc.cgi", "date_chooser.cgi", "switch_skill.cgi",
31           "install-module.pl", "LICENCE.ja", 
32           "favicon.ico", "config-netbsd", "fastrpc.cgi",
33           "defaulttheme", "feedback.cgi", "feedback_form.cgi",
34           "javascript-lib.pl", "webmin-pam", "maketemp.pl",
35           "run-uninstalls.pl",
36           "webmin-gentoo-init", "run-postinstalls.pl",
37           "config-lib.pl", "entities_map.txt", "ui-lib.pl",
38           "password_form.cgi", "password_change.cgi", "pam_login.cgi",
39           "module_chooser.cgi", "config-windows", "xmlrpc.cgi",
40           "uptracker.cgi", "create-module.pl", "webmin_search.cgi",
41          );
42 if ($min) {
43         # Only those required by others
44         @mlist = ("cron", "init", "inittab", "proc", "webmin", "acl", "servers",
45                   "man", "webminlog");
46         }
47 else {
48         # All the modules
49         @mlist =
50           ("cron", "dfsadmin", "dnsadmin", "exports", "inetd", "init",
51           "mount", "samba", "useradmin", "fdisk", "format", "proc", "webmin",
52           "quota", "software", "pap", "acl", "apache", "lpadmin", "bind8",
53           "sendmail", "squid", "bsdexports", "hpuxexports", "file",
54           "net", "dhcpd", "majordomo", "custom", "lilo", "telnet", "servers",
55           "time", "wuftpd", "syslog", "mysql", "man",
56           "inittab", "raid", "postfix", "webminlog", "postgresql", "xinetd",
57           "status", "cpan", "caldera", "pam", "nis", "shell", "grub",
58           "fetchmail", "passwd", "at", "proftpd", "sshd",
59           "heartbeat", "cluster-software", "cluster-useradmin", "qmailadmin",
60           "mon", "mscstyle3", "jabber", "stunnel", "burner", "usermin",
61           "fsdump", "lvm", "sentry", "cfengine", "pserver", "procmail",
62           "cluster-webmin", "firewall", "sgiexports", "vgetty", "openslp",
63           "webalizer", "shorewall", "adsl-client", "updown", "ppp-client",
64           "pptp-server", "pptp-client", "ipsec", "ldap-useradmin",
65           "change-user", "cluster-shell", "cluster-cron", "spam",
66           "htaccess-htpasswd", "logrotate", "cluster-passwd", "mailboxes",
67           "ipfw", "frox", "sarg", "bandwidth", "cluster-copy", "backup-config",
68           "smart-status", "idmapd", "krb5", "smf", "ipfilter", "rbac",
69           "tunnel", "zones", "cluster-usermin", "dovecot", "syslog-ng",
70           "mailcap", "blue-theme", "ldap-client", "phpini", "filter",
71           "bacula-backup", "ldap-server", "exim",
72           );
73         }
74 @dirlist = ( "Webmin" );
75
76 if (-d "/usr/local/webadmin") {
77         chdir("/usr/local/webadmin");
78         system("./koi8-to-cp1251.pl");
79         system("./make-small-icons.pl /usr/local/webadmin");
80         }
81 $dir = "webmin-$vers";
82 system("rm -rf $tardir/$dir");
83 mkdir("$tardir/$dir", 0755);
84
85 # Copy top-level files to directory
86 print "Adding top-level files\n";
87 $flist = join(" ", @files);
88 system("cp -r -L $flist $tardir/$dir");
89 system("touch $tardir/$dir/install-type");
90 system("echo $vers > $tardir/$dir/version");
91 if ($min) {
92         system("touch $tardir/$dir/minimal-install");
93         }
94
95 # Add module files
96 foreach $m (@mlist) {
97         print "Adding module $m\n";
98         mkdir("$tardir/$dir/$m", 0755);
99         $flist = "";
100         opendir(DIR, $m);
101         foreach $f (readdir(DIR)) {
102                 if ($f =~ /^\./ || $f eq "test" || $f =~ /\.bak$/ ||
103                     $f =~ /\.tmp$/ || $f =~ /\.site$/) { next; }
104                 $flist .= " $m/$f";
105                 }
106         closedir(DIR);
107         system("cp -r -L $flist $tardir/$dir/$m");
108         }
109
110 # Remove files that shouldn't be publicly available
111 system("rm -rf $tardir/$dir/status/mailserver*");
112
113 # Add other directories
114 foreach $d (@dirlist) {
115         print "Adding directory $d\n";
116         system("cp -r $d $tardir/$dir");
117         }
118
119 # Update module.info and theme.info files with depends and version
120 opendir(DIR, "$tardir/$dir");
121 while($d = readdir(DIR)) {
122         # set depends in module.info to this version
123         local $minfo = "$tardir/$dir/$d/module.info";
124         local $tinfo = "$tardir/$dir/$d/theme.info";
125         if (-r $minfo) {
126                 local %minfo;
127                 &read_file($minfo, \%minfo);
128                 $minfo{'depends'} = join(" ", split(/\s+/, $minfo{'depends'}),
129                                               $vers);
130                 $minfo{'version'} = $vers;
131                 &write_file($minfo, \%minfo);
132                 }
133         elsif (-r $tinfo) {
134                 local %tinfo;
135                 &read_file($tinfo, \%tinfo);
136                 $tinfo{'depends'} = join(" ", split(/\s+/, $tinfo{'depends'}),
137                                               $vers);
138                 $tinfo{'version'} = $vers;
139                 &write_file($tinfo, \%tinfo);
140                 }
141         }
142 closedir(DIR);
143
144 # Remove useless .bak, test and other files, and create the tar.gz file
145 print "Creating webmin-$vfile.tar.gz\n";
146 system("find $tardir/$dir -name '*.bak' -o -name test -o -name '*.tmp' -o -name '*.site' -o -name core -o -name .xvpics -o -name .svn | xargs rm -rf");
147 system("cd $tardir ; tar cvhf - $dir 2>/dev/null | gzip -c >webmin-$vfile.tar.gz");
148
149 if (!$min && -d $zipdir) {
150         # Create a .zip file too
151         print "Creating webmin-$vfile.zip\n";
152         system("rm -rf $zipdir/webmin");
153         system("mkdir $zipdir/webmin");
154         system("cp -rp $tardir/$dir/* $zipdir/webmin");
155         system("rm -rf $zipdir/webmin/{fdisk,exports,bsdexports,hpuxexports,sgiexports,zones,rbac,Webmin}");
156         system("rm -rf $zipdir/webmin/acl/Authen-SolarisRBAC-0.1/*");
157         system("rm -f $zipdir/webmin/software/msi-lib.pl");
158         system("echo zip >$zipdir/webmin/install-type");
159         open(FIND, "find $zipdir/webmin -name '*\\**' |");
160         while(<FIND>) {
161                 s/\n//g;
162                 $orig = $_;
163                 ($nw = $orig) =~ s/\*/ALL/g;
164                 if ($nw ne $orig) {
165                         rename($orig, $nw);
166                         }
167                 }
168         close(FIND);
169         unlink("$zipdir/webmin-$vfile.zip");
170         system("cd $zipdir && zip -r webmin-$vfile.zip webmin >/dev/null 2>&1");
171         }
172
173 if (!$min && -d "modules") {
174         # Create per-module .wbm files
175         print "Creating modules\n";
176         opendir(DIR, "$tardir/$dir");
177         while($d = readdir(DIR)) {
178                 # create the module.wbm file
179                 local $minfo = "$tardir/$dir/$d/module.info";
180                 next if (!-r $minfo);
181                 unlink("modules/$d.wbm", "modules/$d.wbm.gz");
182                 system("(cd $tardir/$dir ; tar chf - $d | gzip -c) >modules/$d.wbm.gz");
183                 }
184         closedir(DIR);
185         }
186
187 # Create the signature file
188 if (-d "sigs") {
189         unlink("sigs/webmin-$vfile.tar.gz-sig.asc");
190         system("gpg --armor --output sigs/webmin-$vfile.tar.gz-sig.asc --default-key jcameron\@webmin.com --detach-sig $tardir/webmin-$vfile.tar.gz");
191         }
192
193 # Create a change log for this version
194 if (-d "/home/jcameron/webmin.com") {
195         $lastvers = sprintf("%.2f0", $vers - 0.005);    # round down to last stable
196         if ($lastvers == $vers) {
197                 # this is a new full version, so round down to the previous full version
198                 $lastvers = sprintf("%.2f0", $vers-0.006);
199                 }
200         system("./showchangelog.pl --html $lastvers >/home/jcameron/webmin.com/changes-$vers.html");
201         }
202
203 if ($min) {
204         # Delete the tarball directory
205         system("rm -rf $tardir/$dir");
206         }
207
208 # read_file(file, &assoc, [&order])
209 # Fill an associative array with name=value pairs from a file
210 sub read_file
211 {
212 open(ARFILE, $_[0]) || return 0;
213 while(<ARFILE>) {
214         chop;
215         if (!/^#/ && /^([^=]+)=(.*)$/) {
216                 $_[1]->{$1} = $2;
217                 push(@{$_[2]}, $1);
218                 }
219         }
220 close(ARFILE);
221 return 1;
222 }
223  
224 # write_file(file, array)
225 # Write out the contents of an associative array as name=value lines
226 sub write_file
227 {
228 local($arr);
229 $arr = $_[1];
230 open(ARFILE, "> $_[0]");
231 foreach $k (keys %$arr) {
232         print ARFILE "$k=$$arr{$k}\n";
233         }
234 close(ARFILE);
235 }
236
237 sub usage
238 {
239 die "usage: makedist.pl [-minimal] <version>";
240 }
241