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