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