Forum: Cfengine Help
Subject: Last one, Package management for Solaris 10 (a working example)
Author: kholloway
Link to topic: https://cfengine.com/forum/read.php?3,20818,20818#msg-20818

This is to install and version check Solaris 10 packages for both Blastwave 
(probably works just fine for OpenCSW also) and standard packages.
This is also zone safe and will only install the required package to your 
current zone even if on the global.
Note that I'm assuming you setup pkgutil properly to also be zone safe (add 
pkgaddopts=-G to your pkgutil.conf file).

When you want to guarantee a new version of something just bump the version 
number to reflect what it should be and your package will upgrade properly to 
that version.

Cheers

-Kent

----PUT WHEREVER YOU WANT TO ENSURE A PACKAGE----
bundle agent mystuff
{
        methods:
         solaris|solarisx86::
                "any" usebundle => install_package("SMCwhatever"),
                comment => "Install/upgrade SMCwhatever package if needed";

                "any" usebundle => install_package("CSWgnupg"),
                comment => "Install/upgrade CSWgnupg package if needed";

}


------PUT IN A COMMON BUNDLE BEFORE YOU REFERENCE THEM----
bundle common g
{
    vars:
      solaris|solarisx86:: 
         "pkg_base"             string => "/export/install/pkgs";

         # Global packages list, include name with full path and version for 
every package you want
          "solaris_versions"           string => "1.4.0";
          "solaris_packages"         string => 
"${pkg_base}/sunfreeware/${sunver}/SMCwhatever-${solaris_versions}-sol${sunv}-${platform}-local";

          # CSW packages need at least a /dummy/ entry with the matching 
package name or they throw basename errors later
          "solaris_versions"            string => "1.4.10,REV=2010.09.12";
          "solaris_packages"          string => "/dummy/CSWgnupg";
}


------PUT IN YOUR COMMON LIBRARY--------

#
# NOTE: Package must exist in promises.cf BEFORE you try to install it!!
# NOTE: Filename comes from promises.cf array g.solaris_packages[${package}]
# NOTE: Version comes from promises.cf array g.solaris_versions[${package}]
#
bundle agent install_package(package)
{
        vars:
         solaris|solarisx86::
                "check_version" string => execresult('/usr/bin/pkginfo -l 
${package} | /usr/bin/grep VERSION: | /usr/bin/awk \'{print $2}\'', 'useshell'),
                                policy => "overridable";
                "base_filename" string => execresult('/usr/bin/basename 
${g.solaris_packages[${package}]}','noshell'),
                                policy => "overridable";

        classes:
         solaris|solarisx86::
                "install_pkg"   not => 
regcmp('${g.solaris_versions[${package}]}', '${check_version}');
                "pkg_installed" expression => 
regcmp('${g.solaris_versions[${package}]}', '${check_version}');

                # If pkg name starts with CSW it's a blastwave one and needs to 
be handled differently
                # Otherwise we miss out on package deps and other items
                "blastwave_pkg" expression => regcmp('^CSW.*$', '${package}');

        files:
         install_pkg.!blastwave_pkg::
                "/tmp/${base_filename}"
                 comment => "Copy package to /tmp for update or install",
                 perms => mog("0755","root","other"),
                 copy_from => 
secure_cp("${g.solaris_packages[${package}]}","${g.cf3_server}"),
                 classes => satisfied_or_kept("install_pkg_now");

        commands:
         install_pkg.install_pkg_now.!blastwave_pkg::
                "/usr/sbin/pkgadd -G -a ${g.pkg_admin_file} -d 
\"/tmp/${base_filename}\" ${package}";

         install_pkg.blastwave_pkg::
                "/opt/csw/bin/pkgutil -y -i ${package}";

        reports:
         debug.(solaris|solarisx86)::
                "Package: ${package}";
                "Version: ${g.solaris_versions[${package}]}";
                "Installed Version check: ${check_version}";
                "Basename: ${base_filename}";
                "Full path: ${g.solaris_packages[${package}]}";

         debug.blastwave_pkg.(solaris|solarisx86)::
                "Package is from blastwave, using alternative installer for 
package ${package}";

         debug.pkg_installed.(solaris|solarisx86)::
                "Package already installed: ${package}";

         debug.install_pkg.(solaris|solarisx86)::
                "Installing or updating package: ${package}";

}

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to