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