Upgrading printer - remove and add at the same time?

llitz123
Contributor III

Hi all
I'm upgrading Canon production printer copier with new model.
I would like to keep the same name of printer yet uninstall printer and drivers (if possible) from clients, and at the same time add the new printer so users have instant access to the newly updated device.
Because we have a Fiery with a complicated driver, it's easier to install the new printer with presets rather than train users on the complicated driver settings.
We're running MacOS 10.12 and and 10.13.
Does anyone have any experience recently doing such a task? I'm most concerned about the timing.
Would it be 2 scripts? One for removal, update inventory then execute command to run another script for install? Or can I do it using another method. Ive had some issues packaging presets in the past so any tips for printer presets are greatly appreciated. Basically I put presets where they seem to go yet the user never sees them when printing.
Any help is greatly appreciated.

2 REPLIES 2

stevewood
Honored Contributor II
Honored Contributor II

@llitz123 you can do this with one script. You can use a for loop to cycle through the printers on a system and delete the ones you want. Then you can add using lpadmin. You can also check to make sure the proper driver is installed before running the lpadmin commands and install using the jamf binary if it is missing.

#!/bin/bash

if [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ ! -e "/usr/local/bin/jamf" ]]; then
   jamf_binary="/usr/sbin/jamf"
elif [[ "$jamf_binary" == "" ]] && [[ ! -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
   jamf_binary="/usr/local/bin/jamf"
elif [[ "$jamf_binary" == "" ]] && [[ -e "/usr/sbin/jamf" ]] && [[ -e "/usr/local/bin/jamf" ]]; then
   jamf_binary="/usr/local/bin/jamf"
fi

lpa='/usr/sbin/lpadmin'

# Check for printers and re-install
printers=($(lpstat -p | awk '{print $2}' | sed '/^$/d'))

for i in "${printers[@]}"
do
    ## check for partial portions of the printer name
    ## keep adding elif statements for more printers

    if [[ ${i} == *"Name1"* ]]; then
        lpadmin -x ${i}
    elif [[ ${i} == *"Name2"* ]]; then
        lpadmin -x ${i}
    elif [[ ${i} == *"Name3"* ]]; then
        lpadmin -x ${i}
    fi

done

## check for drivers
if [[ ! -f "/Library/Printers/PPDs/Contents/Resources/Xerox WorkCentre 7855.gz" ]]; then

    ${jamf_binary} policy -id <ID>

fi

## now re-add the printers

${lpa} -p NewPrinter1 -E -o printer-is-shared=false -v ipp://1.1.1.1/ipp/print -D "New Printer 1" -P "/Library/Printers/PPDs/Contents/Resources/Xerox WorkCentre 7970.gz"

${lpa} -p NewPrinter2 -E -o printer-is-shared=false -v ipp://1.1.1.1/ipp/print -D "New Printer 2" -P "/Library/Printers/PPDs/Contents/Resources/Xerox WorkCentre 7970.gz"

${lpa} -p NewPrinter3 -E -o printer-is-shared=false -v ipp://1.1.1.1/ipp/print -D "New Printer 3" -P "/Library/Printers/PPDs/Contents/Resources/Xerox WorkCentre 7970.gz"

exit 0

Obviously these are not Fiery printers, but you get the idea. I've found with Fiery controllers you need to use the lpadmin command to set the options like which graphic arts package, what deck, and any other EFI options. Whenever I've tried using the lpoptions command it does not set those options.

Oh, and as far as the Fiery drivers are concerned, I would highly recommend following @foigus blog post on how to use AutoPKG to generate Fiery installs. It has worked 100% of the time for me:

Trial By Fiery

llitz123
Contributor III

@stevewood Thanks. I'll take a look