$out
\n"; } else { print "
\n"; } } else { print "$text{'upgrade_nocheck'}
\n"; } if ($in{'mode'} ne 'gentoo') { # gunzip the file if needed open(FILE, "<$file"); read(FILE, $two, 2); close(FILE); if ($two eq "\037\213") { if (!&has_command("gunzip")) { &inst_error($text{'upgrade_egunzip'}); } $newfile = &transname(); $out = &backquote_command("gunzip -c $qfile 2>&1 >$newfile"); if ($?) { unlink($newfile); &inst_error(&text('upgrade_egzip', "$out")); } unlink($file) if ($need_unlink); $need_unlink = 1; $file = $newfile; } } $qfile = quotemeta($file); if ($in{'mode'} eq 'rpm') { # Check if it is an RPM package $rpmname = "webmin"; if (open(RPM, "<$root_directory/rpm-name")) { chop($rpmname = ); close(RPM); } $out = &backquote_command("rpm -qp $qfile"); $out =~ /(^|\n)\Q$rpmname\E-(\d+\.\d+)-(\d+)/ || /(^|\n)\Q$rpmname\E-(\d+\.\d+)/ || &inst_error($text{'upgrade_erpm'}); $version = $2; $release = $3; $full = $version.($release ? "-$release" : ""); if (!$in{'force'}) { # Is the new version and release actually newer &check_inst_version($full); } # Install the RPM $ENV{'tempdir'} = $gconfig{'tempdir'}; print "",$text{'upgrade_setuprpm'},"\n"; print ""; if ($in{'force'}) { &proc::safe_process_exec( "rpm -Uv --force --nodeps $qfile", 0, 0, STDOUT, undef, 1, 1); } else { &proc::safe_process_exec( "rpm -Uv --ignoreos --ignorearch --nodeps $qfile", 0, 0, STDOUT, undef, 1, 1); } unlink($file) if ($need_unlink); print "\n"; } elsif ($in{'mode'} eq 'deb') { # Check if it is a Debian package $debname = "webmin"; if (open(RPM, "<$root_directory/deb-name")) { chop($debname = ); close(RPM); } $out = &backquote_command("dpkg --info $qfile"); $out =~ /Package:\s+(\S+)/ && $1 eq $debname || &inst_error($text{'upgrade_edeb'}); $out =~ /Version:\s+(\S+)/ || &inst_error($text{'upgrade_edeb'}); $full = $1; ($version, $release) = split(/\-/, $full); if (!$in{'force'}) { &check_inst_version($full); } # Install the package $ENV{'tempdir'} = $gconfig{'tempdir'}; print "",$text{'upgrade_setupdeb'},"\n"; print ""; $ENV{'DEBIAN_FRONTEND'} = 'noninteractive'; my $cmd = "dpkg --install --force-depends $qfile"; if (&has_command("apt-get")) { $cmd = "apt-get install $qfile || $cmd"; } &proc::safe_process_exec($cmd, 0, 0, STDOUT, undef, 1, 1); unlink($file) if ($need_unlink); print "\n"; } elsif ($in{'mode'} eq 'solaris-pkg' || $in{'mode'} eq 'sun-pkg') { # Check if it is a solaris package &foreign_require("software", "software-lib.pl"); &foreign_call("software", "is_package", $file) || &inst_error($text{'upgrade_epackage'}); my @p = &foreign_call("software", "file_packages", $file); # # The package name will always include "webmin" in lower case, # but may be preceded by the source package source ("WS" for the # Webmin.com package, "SUNW" for the Sun distributed package). # and it could have trailing characters to define a set of items # that are installed separately ("r" for the Sun "root" package, # "u" for the Sun "usr" package. # # So the problem is how to match the requested package to the # currently installed package. # foreach $p (@p) { # Hardcode till I can get a better thought for doing this # via a config (or other) file.. ($pkg, $description) = split(/ /, $p); if ($pkg =~ /^(SUNWwebminu|WSwebmin)$/) { break; } else { $pkg =''; } } # Fallthrough error if ($pkg eq '' ) { &inst_error($text{'upgrade_ewpackage'}); } # Install the package print "",$text{'upgrade_setuppackage'},"\n"; print "PKG: $pkg"; $ENV{'KEEP_ETC_WEBMIN'} = 1; # Need to do this inline, otherwise the child process won't install the # package. It would be interesting, however, if this were embedded in # a remote script that could be nohup'd and it would restart the server. chdir("/"); my $pre_install_script = "$config_directory/.pre-install"; my $stop_script = -r $pre_install_script ? $pre_install_script : "$config_directory/stop"; &proc::safe_process_exec_logged( $stop_script, 0, 0, STDOUT, undef, 1,1); $in{'root'} = '/'; $in{'adminfile'} = '$module_root_directory/adminupgrade'; $rv = &software::install_package($file, $pkg); &error($rv) if ($rv); unlink($file) if ($need_unlink); $ENV{'config_dir'} = $config_directory; $ENV{'webmin_upgrade'} = 1; $ENV{'autothird'} = 1; $ENV{'nostop'} = 1; $ENV{'nostart'} = 1; $ENV{'tempdir'} = $gconfig{'tempdir'}; print "",$text{'upgrade_setup'},"\n"; print ""; # We now need to figure out the installed directory for # this package. The best way is to find the basename # for the miniserv.pl file associated with this package # or, in grep context: # grep "miniserv.pl.*$pkg" # and the first element includes the pathname. # $targ = &backquote_command("grep \"miniserv.pl.*$pkg\" /var/sadm/install/contents"); if ($targ =~ /^(.*)\/miniserv.pl.*$/) { $dir = $1; } $setup = $indir ? "./setup.sh '$indir'" : "./setup.sh"; print "Package Directory: $dir"; print "cd $dir && ./setup.sh"; &proc::safe_process_exec( "cd $dir && ./setup.sh", 0, 0, STDOUT, undef, 1, 1); &proc::safe_process_exec_logged( "$config_directory/.post-install", 0, 0, STDOUT, undef, 1,1); print "\n"; } elsif ($in{'mode'} eq 'gentoo') { # Check if it is a gentoo .tar.gz or .ebuild file of webmin open(EMERGE, "emerge --pretend ".quotemeta($file)." 2>/dev/null |"); while() { s/\r|\n//g; s/\033[^m]+m//g; if (/\s+[NRU]\s+\]\s+([^\/]+)\/webmin\-(\d\S+)/) { $version = $2; } } close(EMERGE); $version || &inst_error($text{'upgrade_egentoo'}); if (!$in{'force'}) { &check_inst_version($version); } # Install the Gentoo package print "",$text{'upgrade_setupgentoo'},"\n"; print ""; &proc::safe_process_exec("emerge '$file'", 0, 0, STDOUT, undef, 1, 1); unlink($file) if ($need_unlink); print "\n"; } else { # Check if it is a webmin tarfile open(TAR, "tar tf $qfile 2>&1 |"); while() { s/\r|\n//g; if (/^webmin-([0-9\.]+)\//) { $version = $1; } if (/^usermin-([0-9\.]+)\//) { $usermin_version = $1; } if (/^[^\/]+\/(\S+)$/) { $hasfile{$1}++; } if (/^(webmin-([0-9\.]+)\/([^\/]+))$/ && $3 ne ".") { # Found a top-level file, or *possibly* a directory # under some versions of tar. Keep it so we know which # files to extract. push(@topfiles, $_); } elsif (/^(webmin-[0-9\.]+\/([^\/]+))\// && $2 ne ".") { # Found a sub-directory, like webmin-1.xx/foo/ # Keep this, so that we know which modules to extract. # Also keep the full directory like webmin-1.xx/foo # to avoid treating it as a file. $intar{$2}++; $tardir{$1}++; } } close(TAR); if ($usermin_version) { &inst_error(&text('upgrade_eusermin', $usermin_version)); } if (!$version) { if ($hasfile{'module.info'}) { &inst_error(&text('upgrade_emod', 'edit_mods.cgi')); } else { &inst_error($text{'upgrade_etar'}); } } if (!$in{'force'}) { &check_inst_version($version); } # Work out where to extract if ($indir) { # Since we are currently installed in a fixed directory, # just extract to a temporary location $extract = &transname(); mkdir($extract, 0755); } else { # Next to the current directory $extract = "$root_directory/.."; } # Do the extraction of the tar file, and run setup.sh $| = 1; if ($in{'only'}) { # Extact top-level files like setup.sh and os_list.txt $topfiles = join(" ", map { quotemeta($_) } grep { !$tardir{$_} } @topfiles); $out = &backquote_command("cd $extract && tar xf $file $topfiles 2>&1 >/dev/null"); if ($?) { &inst_error(&text('upgrade_euntar', "$out")); } # Add current modules and current non-module directories # (like themes and lang and images) @mods = grep { $intar{$_} } map { $_->{'dir'} } &get_all_module_infos(1); opendir(DIR, $root_directory); foreach $d (readdir(DIR)) { next if ($d =~ /^\./); my $p = "$root_directory/$d"; if (-d $p && !-r "$p/module.info" && $intar{$d}) { push(@mods, $d); } } closedir(DIR); # Extract current modules and other directories $mods = join(" ", map { quotemeta("webmin-$version/$_") } @mods); $out = &backquote_command("cd $extract && tar xf $file $mods 2>&1 >/dev/null"); if ($?) { &inst_error(&text('upgrade_euntar', "$out")); } } else { # Extract the whole file $out = &backquote_command("cd $extract && tar xf $file 2>&1 >/dev/null"); if ($?) { &inst_error(&text('upgrade_euntar', "$out")); } } unlink($file) if ($need_unlink); $ENV{'config_dir'} = $config_directory; $ENV{'webmin_upgrade'} = 1; $ENV{'autothird'} = 1; $ENV{'tempdir'} = $gconfig{'tempdir'}; $ENV{'deletedold'} = 1 if ($in{'delete'}); print "",$text{'upgrade_setup'},"\n"; print ""; $setup = $indir ? "./setup.sh '$indir'" : "./setup.sh"; &proc::safe_process_exec( "cd $extract/webmin-$version && $setup", 0, 0, STDOUT, undef, 1, 1); print "\n"; if (!$?) { if ($in{'delete'}) { # Can delete the old root directory system("rm -rf ".quotemeta($root_directory)); } elsif ($indir) { # Can delete the temporary source directory system("rm -rf ".quotemeta($extract)); } &lock_file("$config_directory/config"); $gconfig{'upgrade_delete'} = $in{'delete'}; &write_file("$config_directory/config", \%gconfig); &unlock_file("$config_directory/config"); } } &webmin_log("upgrade", undef, undef, { 'version' => $version, 'mode' => $in{'mode'} }); if ($in{'disc'}) { # Forcibly disconnect all other login sessions &foreign_require("acl", "acl-lib.pl"); &get_miniserv_config(\%miniserv); &acl::open_session_db(\%miniserv); foreach $s (keys %acl::sessiondb) { if ($s ne $main::session_id) { delete($acl::sessiondb{$s}); } } dbmclose(%acl::sessiondb); &restart_miniserv(1); } # Find out about any updates for this new version. ($updates) = &fetch_updates($update_url); $updates = &filter_updates($updates, $version); if (scalar(@$updates)) { print "",&text('upgrade_updates', scalar(@$updates), "update.cgi?source=0&show=0&missing=0"),"\n"; } # Force refresh of cached updates, in case webmin was included if (&foreign_check("system-status")) { &foreign_require("system-status"); &system_status::refresh_possible_packages([ "webmin" ]); } if (&foreign_check("virtual-server") && @got) { &foreign_require("virtual-server"); &virtual_server::refresh_possible_packages([ "webmin" ]); } &ui_print_footer("", $text{'index_return'}); sub inst_error { unlink($file) if ($need_unlink); unlink($updatestemp); print "$main::whatfailed : $_[0] \n"; &ui_print_footer("", $text{'index_return'}); exit; } sub check_inst_version { my ($full) = @_; return if ($done_check_inst_version++); # Full version may have been checked # in a previous call my $curr_full = &get_webmin_full_version(); if (&compare_version_numbers($full, $curr_full) == 0) { &inst_error(&text('upgrade_elatest', $full)); } elsif (&compare_version_numbers($full, $curr_full) < 0) { &inst_error(&text('upgrade_eversion', $full)); } }
",$text{'upgrade_setuprpm'},"
\n"; print "
"; if ($in{'force'}) { &proc::safe_process_exec( "rpm -Uv --force --nodeps $qfile", 0, 0, STDOUT, undef, 1, 1); } else { &proc::safe_process_exec( "rpm -Uv --ignoreos --ignorearch --nodeps $qfile", 0, 0, STDOUT, undef, 1, 1); } unlink($file) if ($need_unlink); print "
",$text{'upgrade_setupdeb'},"
"; $ENV{'DEBIAN_FRONTEND'} = 'noninteractive'; my $cmd = "dpkg --install --force-depends $qfile"; if (&has_command("apt-get")) { $cmd = "apt-get install $qfile || $cmd"; } &proc::safe_process_exec($cmd, 0, 0, STDOUT, undef, 1, 1); unlink($file) if ($need_unlink); print "
",$text{'upgrade_setuppackage'},"
\n"; print "PKG: $pkg"; $ENV{'KEEP_ETC_WEBMIN'} = 1; # Need to do this inline, otherwise the child process won't install the # package. It would be interesting, however, if this were embedded in # a remote script that could be nohup'd and it would restart the server. chdir("/"); my $pre_install_script = "$config_directory/.pre-install"; my $stop_script = -r $pre_install_script ? $pre_install_script : "$config_directory/stop"; &proc::safe_process_exec_logged( $stop_script, 0, 0, STDOUT, undef, 1,1); $in{'root'} = '/'; $in{'adminfile'} = '$module_root_directory/adminupgrade'; $rv = &software::install_package($file, $pkg); &error($rv) if ($rv); unlink($file) if ($need_unlink); $ENV{'config_dir'} = $config_directory; $ENV{'webmin_upgrade'} = 1; $ENV{'autothird'} = 1; $ENV{'nostop'} = 1; $ENV{'nostart'} = 1; $ENV{'tempdir'} = $gconfig{'tempdir'}; print "
",$text{'upgrade_setup'},"
"; # We now need to figure out the installed directory for # this package. The best way is to find the basename # for the miniserv.pl file associated with this package # or, in grep context: # grep "miniserv.pl.*$pkg" # and the first element includes the pathname. # $targ = &backquote_command("grep \"miniserv.pl.*$pkg\" /var/sadm/install/contents"); if ($targ =~ /^(.*)\/miniserv.pl.*$/) { $dir = $1; } $setup = $indir ? "./setup.sh '$indir'" : "./setup.sh"; print "Package Directory: $dir"; print "cd $dir && ./setup.sh"; &proc::safe_process_exec( "cd $dir && ./setup.sh", 0, 0, STDOUT, undef, 1, 1); &proc::safe_process_exec_logged( "$config_directory/.post-install", 0, 0, STDOUT, undef, 1,1); print "
",$text{'upgrade_setupgentoo'},"
"; &proc::safe_process_exec("emerge '$file'", 0, 0, STDOUT, undef, 1, 1); unlink($file) if ($need_unlink); print "
"; $setup = $indir ? "./setup.sh '$indir'" : "./setup.sh"; &proc::safe_process_exec( "cd $extract/webmin-$version && $setup", 0, 0, STDOUT, undef, 1, 1); print "
\n"; } # Force refresh of cached updates, in case webmin was included if (&foreign_check("system-status")) { &foreign_require("system-status"); &system_status::refresh_possible_packages([ "webmin" ]); } if (&foreign_check("virtual-server") && @got) { &foreign_require("virtual-server"); &virtual_server::refresh_possible_packages([ "webmin" ]); } &ui_print_footer("", $text{'index_return'}); sub inst_error { unlink($file) if ($need_unlink); unlink($updatestemp); print "$main::whatfailed : $_[0]
\n"; &ui_print_footer("", $text{'index_return'}); exit; } sub check_inst_version { my ($full) = @_; return if ($done_check_inst_version++); # Full version may have been checked # in a previous call my $curr_full = &get_webmin_full_version(); if (&compare_version_numbers($full, $curr_full) == 0) { &inst_error(&text('upgrade_elatest', $full)); } elsif (&compare_version_numbers($full, $curr_full) < 0) { &inst_error(&text('upgrade_eversion', $full)); } }