Changed referer handling
[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 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           "bacula-backup", "ldap-server",
71           );
72         }
73 @dirlist = ( "Webmin" );
74
75 if (-d "/usr/local/webadmin") {
76         chdir("/usr/local/webadmin");
77         system("./koi8-to-cp1251.pl");
78         system("./make-small-icons.pl /usr/local/webadmin");
79         }
80 $dir = "webmin-$vers";
81 system("rm -rf $tardir/$dir");
82 mkdir("$tardir/$dir", 0755);
83
84 # Copy top-level files to directory
85 print "Adding top-level files\n";
86 $flist = join(" ", @files);
87 system("cp -r -L $flist $tardir/$dir");
88 system("touch $tardir/$dir/install-type");
89 system("echo $vers > $tardir/$dir/version");
90 if ($min) {
91         system("touch $tardir/$dir/minimal-install");
92         }
93
94 # Add module files
95 foreach $m (@mlist) {
96         print "Adding module $m\n";
97         mkdir("$tardir/$dir/$m", 0755);
98         $flist = "";
99         opendir(DIR, $m);
100         foreach $f (readdir(DIR)) {
101                 if ($f =~ /^\./ || $f eq "test" || $f =~ /\.bak$/ ||
102                     $f =~ /\.tmp$/ || $f =~ /\.site$/) { next; }
103                 $flist .= " $m/$f";
104                 }
105         closedir(DIR);
106         system("cp -r -L $flist $tardir/$dir/$m");
107         }
108
109 # Remove files that shouldn't be publicly available
110 system("rm -rf $tardir/$dir/status/mailserver*");
111
112 # Add other directories
113 foreach $d (@dirlist) {
114         print "Adding directory $d\n";
115         system("cp -r $d $tardir/$dir");
116         }
117
118 # Update module.info and theme.info files with depends and version
119 opendir(DIR, "$tardir/$dir");
120 while($d = readdir(DIR)) {
121         # set depends in module.info to this version
122         local $minfo = "$tardir/$dir/$d/module.info";
123         local $tinfo = "$tardir/$dir/$d/theme.info";
124         if (-r $minfo) {
125                 local %minfo;
126                 &read_file($minfo, \%minfo);
127                 $minfo{'depends'} = join(" ", split(/\s+/, $minfo{'depends'}),
128                                               $vers);
129                 $minfo{'version'} = $vers;
130                 &write_file($minfo, \%minfo);
131                 }
132         elsif (-r $tinfo) {
133                 local %tinfo;
134                 &read_file($tinfo, \%tinfo);
135                 $tinfo{'depends'} = join(" ", split(/\s+/, $tinfo{'depends'}),
136                                               $vers);
137                 $tinfo{'version'} = $vers;
138                 &write_file($tinfo, \%tinfo);
139                 }
140         }
141 closedir(DIR);
142
143 # Remove useless .bak, test and other files, and create the tar.gz file
144 print "Creating webmin-$vfile.tar.gz\n";
145 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");
146 system("cd $tardir ; tar cvhf - $dir 2>/dev/null | gzip -c >webmin-$vfile.tar.gz");
147
148 if (!$min && -d $zipdir) {
149         # Create a .zip file too
150         print "Creating webmin-$vfile.zip\n";
151         system("rm -rf $zipdir/webmin");
152         system("mkdir $zipdir/webmin");
153         system("cp -rp $tardir/$dir/* $zipdir/webmin");
154         system("rm -rf $zipdir/webmin/{fdisk,exports,bsdexports,hpuxexports,sgiexports,zones,rbac}");
155         system("rm -rf $zipdir/webmin/acl/Authen-SolarisRBAC-0.1/*");
156         system("rm -f $zipdir/webmin/software/msi-lib.pl");
157         system("echo zip >$zipdir/webmin/install-type");
158         open(FIND, "find $zipdir/webmin -name '*\\**' |");
159         while(<FIND>) {
160                 s/\n//g;
161                 $orig = $_;
162                 ($nw = $orig) =~ s/\*/ALL/g;
163                 if ($nw ne $orig) {
164                         rename($orig, $nw);
165                         }
166                 }
167         close(FIND);
168         unlink("$zipdir/webmin-$vfile.zip");
169         system("cd $zipdir && zip -r webmin-$vfile.zip webmin >/dev/null 2>&1");
170         }
171
172 if (!$min && -d "modules") {
173         # Create per-module .wbm files
174         print "Creating modules\n";
175         opendir(DIR, "$tardir/$dir");
176         while($d = readdir(DIR)) {
177                 # create the module.wbm file
178                 local $minfo = "$tardir/$dir/$d/module.info";
179                 next if (!-r $minfo);
180                 unlink("modules/$d.wbm", "modules/$d.wbm.gz");
181                 system("(cd $tardir/$dir ; tar chf - $d | gzip -c) >modules/$d.wbm.gz");
182                 }
183         closedir(DIR);
184         }
185
186 # Create the signature file
187 if (-d "sigs") {
188         unlink("sigs/webmin-$vfile.tar.gz-sig.asc");
189         system("gpg --armor --output sigs/webmin-$vfile.tar.gz-sig.asc --default-key jcameron\@webmin.com --detach-sig $tardir/webmin-$vfile.tar.gz");
190         }
191
192 # Create a change log for this version
193 if (-d "/home/jcameron/webmin.com") {
194         $lastvers = sprintf("%.2f0", $vers - 0.005);    # round down to last stable
195         if ($lastvers == $vers) {
196                 # this is a new full version, so round down to the previous full version
197                 $lastvers = sprintf("%.2f0", $vers-0.006);
198                 }
199         system("./showchangelog.pl --html $lastvers >/home/jcameron/webmin.com/changes-$vers.html");
200         }
201
202 if ($min) {
203         # Delete the tarball directory
204         system("rm -rf $tardir/$dir");
205         }
206
207 # read_file(file, &assoc, [&order])
208 # Fill an associative array with name=value pairs from a file
209 sub read_file
210 {
211 open(ARFILE, $_[0]) || return 0;
212 while(<ARFILE>) {
213         chop;
214         if (!/^#/ && /^([^=]+)=(.*)$/) {
215                 $_[1]->{$1} = $2;
216                 push(@{$_[2]}, $1);
217                 }
218         }
219 close(ARFILE);
220 return 1;
221 }
222  
223 # write_file(file, array)
224 # Write out the contents of an associative array as name=value lines
225 sub write_file
226 {
227 local($arr);
228 $arr = $_[1];
229 open(ARFILE, "> $_[0]");
230 foreach $k (keys %$arr) {
231         print ARFILE "$k=$$arr{$k}\n";
232         }
233 close(ARFILE);
234 }
235
236 sub usage
237 {
238 die "usage: makedist.pl [-minimal] <version>";
239 }
240