Handle hostnames with upper-case letters
[webmin.git] / makedebian.pl
index 4376ba5..c4502a9 100755 (executable)
@@ -26,48 +26,50 @@ $ucproduct = ucfirst($baseproduct);
 $tmp_dir = "/tmp/debian";
 $debian_dir = "$tmp_dir/DEBIAN";
 $control_file = "$debian_dir/control";
+$doc_dir = "$tmp_dir/usr/share/doc/$baseproduct";
+$copyright_file = "$doc_dir/copyright";
 $usr_dir = "$tmp_dir/usr/share/$baseproduct";
 $pam_dir = "$tmp_dir/etc/pam.d";
 $init_dir = "$tmp_dir/etc/init.d";
-@rc_dirs = ( "$tmp_dir/etc/rc2.d", "$tmp_dir/etc/rc3.d", "$tmp_dir/etc/rc5.d" );
 $pam_file = "$pam_dir/$baseproduct";
 $preinstall_file = "$debian_dir/preinst";
 $postinstall_file = "$debian_dir/postinst";
 $preuninstall_file = "$debian_dir/prerm";
 $postuninstall_file = "$debian_dir/postrm";
-$copyright_file = "$debian_dir/copyright";
+$debian_copyright_file = "$debian_dir/copyright";
 $changelog_file = "$debian_dir/changelog";
+$changelog_doc_file = "$doc_dir/changelog";
 $conffiles_file = "$debian_dir/conffiles";
 
 -d "tarballs" || die "makedebian.pl must be run in the $ucproduct root directory";
 -r "/etc/debian_version" || die "makedebian.pl must be run on Debian";
 chop($webmin_dir = `pwd`);
 
-@ARGV == 1 || die "usage: makedebian.pl [--webmail] <version>";
+@ARGV == 1 || @ARGV == 2 ||
+       die "usage: makedebian.pl [--webmail] <version> [release]";
 $ver = $ARGV[0];
+if ($ARGV[1]) {
+       $rel = "-".$ARGV[1];
+       }
 -r "tarballs/$product-$ver.tar.gz" || die "tarballs/$product-$ver.tar.gz not found";
 
 # Create the base directories
-print "Creating Debian package of ",ucfirst($product)," ",$ver," ...\n";
+print "Creating Debian package of ",ucfirst($product)," ",$ver,$rel," ...\n";
 system("rm -rf $tmp_dir");
 mkdir($tmp_dir, 0755);
 chmod(0755, $tmp_dir);
 mkdir($debian_dir, 0755);
 system("mkdir -p $pam_dir");
-if ($baseproduct eq "usermin") {
-       system("mkdir -p $init_dir");
-       foreach $d (@rc_dirs) {
-               system("mkdir -p $d");
-               }
-       }
+system("mkdir -p $init_dir");
 system("mkdir -p $usr_dir");
+system("mkdir -p $doc_dir");
 
 # Un-tar the package to the correct locations
 system("gunzip -c tarballs/$product-$ver.tar.gz | (cd $tmp_dir ; tar xf -)") &&
        die "un-tar failed!";
 system("mv $tmp_dir/$product-$ver/* $usr_dir");
 rmdir("$tmp_dir/$product-$ver");
-system("mv $usr_dir/$baseproduct-pam $pam_file");
+system("mv $usr_dir/$baseproduct-debian-pam $pam_file");
 system("cd $usr_dir && (find . -name '*.cgi' ; find . -name '*.pl') | perl perlpath.pl /usr/bin/perl -");
 system("cd $usr_dir && rm -f mount/freebsd-mounts*");
 system("cd $usr_dir && rm -f mount/openbsd-mounts*");
@@ -75,14 +77,12 @@ if ($product eq "webmin") {
        system("cd $usr_dir && rm -f mount/macos-mounts*");
        system("cd $usr_dir && rm -f webmin-gentoo-init");
        system("cd $usr_dir && rm -rf format bsdexports hpuxexports sgiexports zones rbac");
+       system("cd $usr_dir && rm -rf acl/Authen-SolarisRBAC-0.1*");
        }
-else {
-       # Need to create init script
-       system("mv $usr_dir/$baseproduct-init $init_dir/$baseproduct");
-       foreach $d (@rc_dirs) {
-               system("ln -s ../init.d/$baseproduct $d/S99$baseproduct");
-               }
-       }
+
+# Create init script
+system("mv $usr_dir/$baseproduct-init $init_dir/$baseproduct");
+chmod(0755, "$init_dir/$baseproduct");
 system("echo deb >$usr_dir/install-type");
 system("echo $product >$usr_dir/deb-name");
 system("cd $usr_dir && chmod -R og-w .");
@@ -92,16 +92,20 @@ if ($< == 0) {
 $size = int(`du -sk $tmp_dir`);
 
 # Create the control file
+@deps = ( "perl", "libnet-ssleay-perl", "openssl", "libauthen-pam-perl", "libpam-runtime", "libio-pty-perl", "apt-show-versions" );
+if ($baseproduct eq "webmin") {
+       push(@deps, "python");
+       }
+$deps = join(", ", @deps);
 open(CONTROL, ">$control_file");
 print CONTROL <<EOF;
 Package: $product
-Version: $ver
+Version: $ver$rel
 Section: admin
 Priority: optional
 Architecture: all
-Essential: no
-Depends: bash, perl, libnet-ssleay-perl, openssl, libauthen-pam-perl, libpam-runtime, libio-pty-perl, libmd5-perl
-Pre-Depends: bash, perl
+Depends: $deps
+Pre-Depends: perl
 Installed-Size: $size
 Maintainer: Jamie Cameron <jcameron\@webmin.com>
 Provides: $baseproduct
@@ -109,18 +113,19 @@ EOF
 if ($product eq "webmin") {
        print CONTROL <<EOF;
 Replaces: webmin-adsl, webmin-apache, webmin-bandwidth, webmin-bind, webmin-burner, webmin-cfengine, webmin-cluster, webmin-core, webmin-cpan, webmin-dhcpd, webmin-exim, webmin-exports, webmin-fetchmail, webmin-firewall, webmin-freeswan, webmin-frox, webmin-fsdump, webmin-grub, webmin-heartbeat, webmin-htaccess, webmin-inetd, webmin-jabber, webmin-ldap-netgroups, webmin-ldap-user-simple, webmin-ldap-useradmin, webmin-lilo, webmin-logrotate, webmin-lpadmin, webmin-lvm, webmin-mailboxes, webmin-mon, webmin-mysql, webmin-nis, webmin-openslp, webmin-postfix, webmin-postgresql, webmin-ppp, webmin-pptp-client, webmin-pptp-server, webmin-procmail, webmin-proftpd, webmin-pserver, webmin-quota, webmin-samba, webmin-sarg, webmin-sendmail, webmin-shorewall, webmin-slbackup, webmin-smart-status, webmin-snort, webmin-software, webmin-spamassassin, webmin-squid, webmin-sshd, webmin-status, webmin-stunnel, webmin-updown, webmin-usermin, webmin-vgetty, webmin-webalizer, webmin-wuftpd, webmin-wvdial, webmin-xinetd
-Description: A web-based administration interface for Unix systems.
-            Using Webmin you can configure DNS, Samba, NFS, local/remote
-            filesystems and more using your web browser.  After installation,
-            enter the URL https://localhost:10000/ into your browser and
-            login as root with your root password.
+Description: web-based administration interface for Unix systems
+  Using Webmin you can configure DNS, Samba, NFS, local/remote filesystems
+  and more using your web browser.  After installation, enter the URL
+  https://localhost:10000/ into your browser and login as root with your root
+  password.
 EOF
        }
 else {
        print CONTROL <<EOF;
 Replaces: usermin-at, usermin-changepass, usermin-chfn, usermin-commands, usermin-cron, usermin-cshrc, usermin-fetchmail, usermin-forward, usermin-gnupg, usermin-htaccess, usermin-htpasswd, usermin-mailbox, usermin-man, usermin-mysql, usermin-plan, usermin-postgresql, usermin-proc, usermin-procmail, usermin-quota, usermin-schedule, usermin-shell, usermin-spamassassin, usermin-ssh, usermin-tunnel, usermin-updown, usermin-usermount
-Description: A web-based user account administration interface for Unix systems.
-            After installation, enter the URL http://localhost:20000/ into your             browser and login as any user on your system.
+Description: web-based user account administration interface for Unix systems
+  After installation, enter the URL http://localhost:20000/ into your browser
+  and login as any user on your system.
 EOF
        }
 close(CONTROL);
@@ -145,11 +150,14 @@ while(<BSD>) {
        }
 close(BSD);
 close(COPY);
+system("cp $copyright_file $debian_copyright_file");
 
 # Create the config files file, for those we don't want to replace
 open(CONF, ">$conffiles_file");
 print CONF "/etc/pam.d/$baseproduct\n";
+print CONF "/etc/init.d/$baseproduct\n";
 close(CONF);
+chmod(0644, $conffiles_file);
 
 # Get the changes for each module and version
 $changes = { };
@@ -211,6 +219,7 @@ foreach $v (sort { $a <=> $b } (keys %$changes)) {
        print CHANGELOG "\n";
        }
 close(CHANGELOG);
+system("iconv -f ISO-8859-1 -t UTF-8 $changelog_file >$changelog_doc_file");
 
 # Get the temp-directory creator script
 open(TEMP, "maketemp.pl");
@@ -254,7 +263,7 @@ inetd=`grep "^inetd=" /etc/$baseproduct/miniserv.conf 2>/dev/null | sed -e 's/in
 if [ "\$1" = "upgrade" ]; then
        # Upgrading the package, so stop the old webmin properly
        if [ "\$inetd" != "1" ]; then
-               /etc/init.d/$baseproduct stop >/dev/null 2>&1 </dev/null
+               /etc/$baseproduct/stop >/dev/null 2>&1 </dev/null
        fi
 fi
 cd /usr/share/$baseproduct
@@ -276,13 +285,18 @@ fi
 host=`hostname`
 ssl=1
 atboot=1
+makeboot=1
 nochown=1
 autothird=1
 noperlpath=1
 nouninstall=1
 nostart=1
-export config_dir var_dir perl autoos port login crypt host ssl nochown autothird noperlpath nouninstall nostart allow atboot
-./setup.sh >/tmp/.webmin/$product-setup.out 2>&1
+export config_dir var_dir perl autoos port login crypt host ssl nochown autothird noperlpath nouninstall nostart allow atboot makeboot
+tempdir=/tmp/.webmin
+if [ ! -d \$tempdir ]; then
+       tempdir=/tmp
+fi
+./setup.sh >$tempdir/$product-setup.out 2>&1
 if [ "$product" = "webmin" ]; then
        grep sudo= /etc/$product/miniserv.conf >/dev/null 2>&1
        if [ "\$?" = 1 ]; then
@@ -295,9 +309,12 @@ if [ "$inetd" != "1" ]; then
        if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
                invoke-rc.d $baseproduct start >/dev/null 2>&1 </dev/null
        else
-               /etc/init.d/$baseproduct start >/dev/null 2>&1 </dev/null
+               /etc/$baseproduct/start >/dev/null 2>&1 </dev/null
        fi
 fi
+if [ "$product" = "usermin" ]; then
+       (insserv $baseproduct || update-rc.d $baseproduct defaults) >/dev/null 2>&1
+fi
 cat >/etc/$baseproduct/uninstall.sh <<EOFF
 #!/bin/sh
 printf "Are you sure you want to uninstall $ucproduct? (y/n) : "
@@ -347,7 +364,6 @@ if [ "\$1" != "upgrade" ]; then
                        echo "Running uninstall scripts .."
                        (cd /usr/share/$baseproduct ; WEBMIN_CONFIG=/etc/$baseproduct WEBMIN_VAR=/var/$baseproduct LANG= /usr/share/$baseproduct/run-uninstalls.pl)
                fi
-               /etc/init.d/$baseproduct stop >/dev/null 2>&1 </dev/null
                /etc/$baseproduct/stop >/dev/null 2>&1 </dev/null
                /bin/true
        fi
@@ -373,11 +389,11 @@ close(SCRIPT);
 system("chmod 755 $postuninstall_file");
 
 # Run the actual build command
-system("fakeroot dpkg --build $tmp_dir deb/${product}_${ver}_all.deb") &&
+system("fakeroot dpkg --build $tmp_dir deb/${product}_${ver}${rel}_all.deb") &&
        die "dpkg failed";
 #system("rm -rf $tmp_dir");
-print "Wrote deb/${product}_${ver}_all.deb\n";
-$md5 = `md5sum tarballs/$product-$ver.tar.gz`;
+print "Wrote deb/${product}_${ver}${rel}_all.deb\n";
+$md5 = `md5sum tarballs/$product-$ver$rel.tar.gz`;
 $md5 =~ s/\s+.*\n//g;
 @st = stat("tarballs/$product-$ver.tar.gz");
 
@@ -387,17 +403,17 @@ $diff_new_dir = "$tmp_dir/$product-$ver";
 mkdir($diff_orig_dir, 0755);
 mkdir($diff_new_dir, 0755);
 system("cp -r $debian_dir $diff_new_dir");
-system("cd $tmp_dir && diff -r -N -u $product-$ver-orig $product-$ver >$webmin_dir/deb/${product}_${ver}.diff");
-$diffmd5 = `md5sum deb/${product}_${ver}.diff`;
+system("cd $tmp_dir && diff -r -N -u $product-$ver-orig $product-$ver >$webmin_dir/deb/${product}_${ver}${rel}.diff");
+$diffmd5 = `md5sum deb/${product}_${ver}${rel}.diff`;
 $diffmd5 =~ s/\s+.*\n//g;
-@diffst = stat("deb/${product}_${ver}.diff");
+@diffst = stat("deb/${product}_${ver}${rel}.diff");
 
 # Create the .dsc file
-open(DSC, ">deb/${product}_$ver.plain");
+open(DSC, ">deb/${product}_$ver$rel.plain");
 print DSC <<EOF;
 Format: 1.0
 Source: $product
-Version: $ver
+Version: $ver$rel
 Binary: $product
 Maintainer: Jamie Cameron <jcameron\@webmin.com>
 Architecture: all
@@ -410,22 +426,23 @@ Files:
 
 EOF
 close(DSC);
-unlink("deb/${product}_$ver.dsc");
-system("gpg --output deb/${product}_$ver.dsc --clearsign deb/${product}_$ver.plain");
-unlink("deb/${product}_$ver.plain");
-print "Wrote source deb/${product}_$ver.dsc\n";
+unlink("deb/${product}_$ver$rel.dsc");
+system("gpg --output deb/${product}_$ver$rel.dsc --clearsign deb/${product}_$ver$rel.plain");
+unlink("deb/${product}_$ver$rel.plain");
+print "Wrote source deb/${product}_$ver$rel.dsc\n";
 
+$dir = "sarge";
 if (-d "/usr/local/webadmin/deb/repository") {
        # Add to our repository
        chdir("/usr/local/webadmin/deb/repository");
-       system("reprepro -Vb . remove sarge $product");
-       system("reprepro -Vb . includedeb sarge ../${product}_${ver}_all.deb");
+       system("reprepro -Vb . remove $dir $product");
+       system("reprepro -Vb . includedeb $dir ../${product}_${ver}${rel}_all.deb");
        chdir("/usr/local/webadmin");
        }
 
 # Create PGP signature
-unlink("sigs/${product}_${ver}_all.deb-sig.asc");
-system("gpg --armor --output sigs/${product}_${ver}_all.deb-sig.asc --default-key jcameron\@webmin.com --detach-sig deb/${product}_${ver}_all.deb");
+unlink("sigs/${product}_${ver}${rel}_all.deb-sig.asc");
+system("gpg --armor --output sigs/${product}_${ver}${rel}_all.deb-sig.asc --default-key jcameron\@webmin.com --detach-sig deb/${product}_${ver}${rel}_all.deb");
 
 # read_file(file, &assoc, [&order], [lowercase])
 # Fill an associative array with name=value pairs from a file