Control the CUPS web interface with a Munki NoPkg

Back in September 2021 a colleague on the MacAdmins Slack was looking for a way to programmatically enable the CUPS web interface on macOS. I had recently completed my article “Allow standard users to manage printers with a Munki NoPkg” and realized I could easily adapt it to handle this task.

This isn’t something I use in production but read on for the details if you think it could be helpful in your environment.

As written this NoPkg is designed to be used as either a Managed Install or a Managed Uninstall.

The NoPkg consists of four scripts to do the work. For applying the change we first use an installcheck_script to evaluate the status:

#!/bin/sh

# Check to see if the CUPS Web Interface is enabled
enabled=$(/usr/sbin/cupsctl | grep "WebInterface=yes")

# See if the check is empty
if [ -z "$enabled" ]; then
    /bin/echo "CUPS web interface is not enabled, need to install."
    exit 0
else
    /bin/echo "CUPS web interface is enabled, no action needed."
    exit 1
fi

The postinstall_script is executed if installation is needed:

#!/bin/sh

/usr/sbin/cupsctl WebInterface=yes

To remove the configuration the uninstallcheck_script is run first:

#!/bin/sh

# Check to see is the CUPS Web Interface is enabled
enabled=$(/usr/sbin/cupsctl | grep "WebInterface=yes")

# See if the check is empty
if [ -z "$enabled" ]; then
    /bin/echo "CUPS web interface is not enabled, no action needed."
    exit 1
else
    /bin/echo "CUPS web interface is enabled, need to uninstall."
    exit 0
fi

The uninstall_script is then executed if uninstallation is necessary:

#!/bin/sh

/usr/sbin/cupsctl WebInterface=no

The full PkgInfo file is available on GitHub: https://github.com/kevinmcox/Munki-NoPkgs/blob/main/PrinterCupsWebInterface.pkginfo

It could easily be adapted and split up into two separate NoPkgs to be used as on-demand items that allow end users to enable or disable the web interface on their own whenever needed.

1 comment on “Control the CUPS web interface with a Munki NoPkg

  1. Pingback: Weekly News Summary for Admins — 2022-01-28 – Scripting OS X

Leave a Reply

Your email address will not be published.