Skip to content

printer_install_macos.sh

Corey Watson edited this page Dec 1, 2025 · 1 revision

printer_install_macos.sh

Installs network printers on macOS using CUPS/lpadmin with support for local or remote PPD driver files.

Overview

This script automates network printer deployment on macOS systems using CUPS. It supports multiple printers, can download PPD files from URLs or use local files, optionally installs full driver packages, and configures printers with appropriate security settings.

Purpose

Provides standardized printer deployment for managed macOS workstations, supporting both local PPD files and remote driver downloads for flexible deployment scenarios.

Prerequisites

  • Operating System: macOS 10.12 or later
  • Privileges: Root/sudo privileges required
  • Network: Access to printer hosts and PPD/driver URLs (if using URL source)
  • Driver File: PPD file for printer model (local or URL)

Configuration

Required Inputs

Edit these variables in the script before running:

PRINTERS Array:

PRINTERS=(
    "printer1.example.com|Main Office|Office Printer"
    "printer2.example.com|Sales Dept|Sales Printer"
)

Format: "hostname|location|display_name"

  • If display_name is empty, hostname prefix will be used

PROTOCOL: Connection protocol

  • Options: lpd, ipp, ipps
  • Default: lpd

PPD_SOURCE: Source of PPD file

  • Options: local or url
  • Default: local

PPD_PATH: Path to local PPD file (if PPD_SOURCE="local")

  • Example: /Library/Printers/PPDs/Contents/Resources/YourPrinter.ppd.gz
  • Supports .ppd or .ppd.gz files

PPD_URL: URL to download PPD file (if PPD_SOURCE="url")

  • Example: https://example.com/drivers/printer.ppd

DRIVER_URL: Optional URL for full driver package

  • Leave empty if using generic PPD or driver already installed
  • Supports ZIP format, extracts to /Library/Printers/

Behavior

  1. Root Check: Verifies script is run with sudo privileges
  2. Configuration Display: Shows protocol, PPD source, and printer count
  3. Driver Download (optional):
    • Downloads driver package from DRIVER_URL if specified
    • Extracts to /Library/Printers/
    • Installs driver components
  4. PPD Setup:
    • URL Source: Downloads PPD from PPD_URL to /Library/Printers/PPDs/Contents/Resources/
    • Local Source: Verifies PPD_PATH exists
    • Sets appropriate ownership (root:wheel) and permissions (644)
  5. Printer Installation Loop:
    • For each printer in PRINTERS array:
      • Removes existing printer with same name
      • Builds URI based on protocol (lpd, ipp, or ipps)
      • Creates printer using lpadmin
      • Sets location and display name
      • Configures printer-is-shared=false
      • Sets error-policy to abort-job
      • Enables printer
      • Verifies installation with lpstat
  6. Results Display:
    • Shows success/failure count
    • Displays final status

The script exits immediately on critical errors due to set -euo pipefail.

Security Notes

  • Requires root privileges for printer configuration
  • Printer sharing disabled by default (printer-is-shared=false)
  • Downloads over HTTPS for secure driver/PPD retrieval
  • PPD files installed with restricted permissions (root:wheel, 644)
  • No credentials stored in printer configuration
  • Error policy set to abort-job (prevents print queue pile-up on errors)

Exit Codes

  • 0: All printers installed successfully
  • 1: Installation failed:
    • Script not run as root
    • Driver download failed
    • PPD file not found (local) or download failed (URL)
    • Invalid PPD_SOURCE value
    • All printer installations failed

Note: Partial success (some printers installed) returns exit code 1.

Example Output

[ NETWORK PRINTER INSTALL - macOS ]
--------------------------------------------------------------
Protocol   : lpd
PPD Source : local
Printers   : 2

[ SETTING UP PPD ]
--------------------------------------------------------------
Using local PPD: /Library/Printers/PPDs/Contents/Resources/Generic.ppd.gz

[ INSTALLING PRINTERS ]
--------------------------------------------------------------
Installing: Office Printer
  Hostname : printer1.example.com
  Location : Main Office
  Name     : Office_Printer
  Status   : SUCCESS

Installing: Sales Printer
  Hostname : printer2.example.com
  Location : Sales Dept
  Name     : Sales_Printer
  Status   : SUCCESS

[ FINAL STATUS ]
--------------------------------------------------------------
Installed  : 2 printer(s)
Failed     : 0 printer(s)
Result     : SUCCESS

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Version History

  • v1.0.0: Initial release
    • Multi-printer support
    • Local and remote PPD support
    • Optional full driver package installation
    • Protocol selection (lpd, ipp, ipps)
    • Automatic printer name generation from hostname
    • Security-focused default settings
    • Installation verification

Links

Clone this wiki locally