Validate package and update systems
authorJamie Cameron <jcameron@webmin.com>
Fri, 23 Jan 2009 23:22:11 +0000 (23:22 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 23 Jan 2009 23:22:11 +0000 (23:22 +0000)
20 files changed:
software/CHANGELOG
software/aix-lib.pl
software/apt-lib.pl
software/csw-lib.pl
software/cygwin-lib.pl
software/debian-lib.pl
software/emerge-lib.pl
software/freebsd-lib.pl
software/hpux-lib.pl
software/index.cgi
software/lang/en
software/msi-lib.pl
software/openbsd-lib.pl
software/pkgadd-lib.pl
software/rhn-lib.pl
software/rpm-lib.pl
software/slackware-lib.pl
software/software-lib.pl
software/urpmi-lib.pl
software/yum-lib.pl

index 7aadebb..5c1dc4a 100644 (file)
@@ -26,3 +26,4 @@ Added an Upgrade All button for CSW packages.
 ---- Changes since 1.440 ----
 Added a Module Config option to not use any update system, even if YUM or APT are installed.
 Added the function package_files for other modules to call, when only a list of files in some package is needed.
+The selected package and update systems are now checked when the module is opened, and an error message displayed if any needed commands are missing.
index dc823af..b76ce93 100644 (file)
@@ -1,6 +1,11 @@
 # aix-lib.pl
 # Functions for aix package management
 
+sub list_package_system_commands
+{
+return ("lslpp", "geninstall", "installp");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with a list of all packages
 sub list_packages
index baacd5f..8f27e3d 100644 (file)
@@ -4,6 +4,11 @@
 $apt_get_command = $config{'apt_mode'} ? "aptitude" : "apt-get";
 $apt_search_command = $config{'apt_mode'} ? "aptitude" : "apt-cache";
 
+sub list_update_system_commands
+{
+return ($apt_get_command, $apt_search_command);
+}
+
 # update_system_install([package])
 # Install some package with apt
 sub update_system_install
index 1facc5b..44b070e 100644 (file)
@@ -4,6 +4,11 @@
 $pkg_get = -x "/opt/csw/bin/pkg-get" ? "/opt/csw/bin/pkg-get"
                                     : &has_command("pkg-get");
 
+sub list_update_system_commands
+{
+return ($pkg_get);
+}
+
 # update_system_install([file])
 # Install some package with pkg-get
 sub update_system_install
index 5ee15c6..82054f8 100644 (file)
@@ -4,6 +4,11 @@
 use vars '$hasrpm'; $hasrpm = (-f "/usr/bin/rpm.exe");
 use vars '$db'; $db = "/etc/setup/installed.db";
 
+sub validate_package_system
+{
+return -r $db ? undef : &text('cygwin_edb', "<tt>$db</tt>");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with all or listed packages
 sub list_packages
index 6d63d82..6df9644 100644 (file)
@@ -1,6 +1,11 @@
 # debian-lib.pl
 # Functions for debian DPKG package management
 
+sub list_package_system_commands
+{
+return ("dpkg");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with a list of all packages
 sub list_packages
index 24a2908..5916eba 100644 (file)
@@ -6,6 +6,16 @@ $pkg_dir = "/var/db/pkg";
 $portage_bin = "/usr/lib/portage/bin";
 $ENV{'TERM'} = "dumb";
 
+sub list_package_system_commands
+{
+return ("$portage_bin/pkglist");
+}
+
+sub list_update_system_commands
+{
+return ("emerge");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with all or listed packages
 sub list_packages
index 1ac18e8..9cce708 100644 (file)
@@ -5,6 +5,11 @@ use POSIX;
 chop($system_arch = `uname -m`);
 $package_dir = "/var/db/pkg";
 
+sub list_package_system_commands
+{
+return ("pkg_info", "pkg_add");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with a list of all packages
 sub list_packages
index 7842b55..be4798b 100644 (file)
@@ -1,6 +1,11 @@
 # hpux-lib.pl
 # Functions for HP-UX package management
 
+sub list_package_system_commands
+{
+return ("swlist", "swinstall");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with all or listed packages
 sub list_packages
index f17fd49..1b65d03 100755 (executable)
@@ -7,6 +7,18 @@ require './software-lib.pl';
        &help_search_link(defined(&package_help) ? ( &package_help() ) : ( ),
                          "man", "doc"));
 
+# Validate the package and update systems
+$err = &check_package_system();
+if ($err) {
+       &ui_print_endpage(&text('index_epackagecheck', $err,
+                               "../config.cgi?$module_name"));
+       }
+$err = &check_update_system();
+if ($err) {
+       &ui_print_endpage(&text('index_eupdatecheck', $err,
+                               "../config.cgi?$module_name"));
+       }
+
 # Show package search and list forms
 print &ui_subheading($text{'index_installed'});
 print "<table width=100%><tr>\n";
index ee58e03..f46cd74 100644 (file)
@@ -16,6 +16,10 @@ index_all=All Packages
 index_return=module index
 index_treturn=package tree
 index_tree=Package Tree
+index_epackagecmd=The $1 package system requires the $2 command
+index_eupdatecmd=The $1 update system requires the $2 command
+index_epackagecheck=The selected package management system is not valid : $1.<br>You may need to select a different system on the <a href='$2'>module configuration</a> page.
+index_eupdatecheck=The selected update system is not valid : $1.<br>You may need to select a different update method on the <a href='$2'>module configuration</a> page.
 
 search_title=Package Search
 search_nomatch=No packages matched $1
@@ -145,6 +149,7 @@ slack_missing=Missing
 slack_root=Root directory
 slack_eroot=Missing or invalid root directory
 slack_manager=Slackware Package Manager
+slack_edir=Missing Slackware packages directory $1
 
 debian_unknown=Unknown
 debian_depends=Ignore dependancy problems?
@@ -323,6 +328,7 @@ cygwin_elstat=Failed to stat symlink: $1
 cygwin_badpostscript=Warning: this script does not appear to have been run
 cygwin_pkgexists=Package $1 already exists.
 cygwin_warnuse=Warning: This is not an official interface for managing Cygwin software.  Use at your own risk.
+cygwin_edb=Missing Cygwin packages database $1
 
 deletes_err=Failed to delete packages
 deletes_enone=No packages selected
index 2b33ba1..7e1a137 100644 (file)
@@ -6,6 +6,11 @@ $sw_discovery_cmd = "$root_directory/SW_Discovery/SW_Discovery.exe";
 $has_sw_discovery = -x $sw_discovery_cmd;
 $no_package_filesearch = 1;
 
+sub list_package_system_commands
+{
+return ($sw_discovery_cmd);
+}
+
 # list_packages([package]*)
 # Fills the array %packages with all or listed packages
 sub list_packages
index 6322546..4104271 100644 (file)
@@ -5,6 +5,11 @@ use POSIX;
 chop($system_arch = `uname -m`);
 $package_dir = "/var/db/pkg";
 
+sub list_package_system_commands
+{
+return ("pkg_info", "pkg_add");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with a list of all packages
 sub list_packages
index 045ecd4..a2fbe17 100644 (file)
@@ -3,6 +3,11 @@
 
 &foreign_require("proc", "proc-lib.pl");
 
+sub list_package_system_commands
+{
+return ("pkginfo", "pkgadd", "pkgrm");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with a list of all packages
 sub list_packages
index 71c07d3..29dec14 100644 (file)
@@ -4,6 +4,11 @@
 $up2date_config = "/etc/sysconfig/rhn/up2date";
 $rhn_sysconfig = "/etc/sysconfig/rhn/rhnsd";
 
+sub list_update_system_commands
+{
+return ("up2date");
+}
+
 # update_system_install([package])
 # Install some package with up2date
 sub update_system_install
index 95611fc..c8540e9 100644 (file)
@@ -1,6 +1,11 @@
 # rpm-lib.pl
 # Functions for redhat linux package management
 
+sub list_package_system_commands
+{
+return ("rpm");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with all or listed packages
 sub list_packages
index a4c339a..ca56355 100644 (file)
@@ -21,6 +21,12 @@ $package_dir = "/var/log/packages";
 use POSIX;
 chop($system_arch = `uname -m`);
 
+sub validate_package_system
+{
+return -d &translate_filename($package_dir) ? undef :
+       &text('slack_edir', "<tt>$package_dir</tt>");
+}
+
 # list_packages([package]*)
 # Fills the array %packages with a list of all packages
 sub list_packages
index 71985a1..ee38242 100644 (file)
@@ -1,6 +1,5 @@
 # software-lib.pl
 # A generalized system for package management on solaris, linux, etc..
-# XXX cluster-software module
 
 do '../web-lib.pl';
 &init_config();
@@ -218,5 +217,47 @@ for(my $i=0; $i<@sp1 || $i<@sp2; $i++) {
 return 0;
 }
 
+# check_package_system()
+# Returns an error message if some command needed by the selected package
+# management system is missing.
+sub check_package_system
+{
+local $err;
+if (defined(&validate_package_system)) {
+       $err = &validate_package_system();
+       }
+if (defined(&list_package_system_commands)) {
+       foreach my $c (&list_package_system_commands()) {
+               if (!&has_command($c)) {
+                       $err ||= &text('index_epackagecmd', &package_system(),
+                                      "<tt>$c</tt>");
+                       }
+               }
+       }
+return $err;
+}
+
+# check_update_system()
+# Returns an error message if some command needed by the selected update
+# system is missing.
+sub check_update_system
+{
+return undef if (!$update_system);
+local $err;
+if (defined(&validate_update_system)) {
+       $err = &validate_update_system();
+       }
+if (defined(&list_update_system_commands)) {
+       foreach my $c (&list_update_system_commands()) {
+               if (!&has_command($c)) {
+                       $err ||= &text('index_eupdatecmd',
+                           $text{$update_system.'_name'} || uc($update_system),
+                           "<tt>$c</tt>");
+                       }
+               }
+       }
+return $err;
+}
+
 1;
 
index 161e876..10d5055 100644 (file)
@@ -1,6 +1,11 @@
 # urpmi-lib.pl
 # Functions for installing packages with Mandrake urpmi
 
+sub list_update_system_commands
+{
+return ("urpmi");
+}
+
 # update_system_install([package])
 # Install some package with urpmi
 sub update_system_install
index ad706c2..77bf743 100644 (file)
@@ -3,6 +3,11 @@
 
 $yum_config = $config{'yum_config'} || "/etc/yum.conf";
 
+sub list_update_system_commands
+{
+return ("yum");
+}
+
 # update_system_install([package], [&in])
 # Install some package with yum
 sub update_system_install