Multi-step deployment for new printers

dreinold
New Contributor II

Hey all,

So we're using JAMF 10.10 on an Azure server. Which is also several other things; our AD (which we don't use across the whole company), DNS (just so in-network devices can get to JAMF and printers (if Windows)), and print server.

We've recently installed Papercut, and started getting it setup. Now comes that hard part.

We need to figure out how to script, or maybe create a new QuickAdd.pkg, to do the following:
0. Remove old printers/queues
1. Deploy new printer driver package
2. Create/deploy new virtual printer queue
3. Deploy Papercut client
4. Adjust a single script in the client

Now, I am not one to shy away from random new scripts, but I am not a very good scripter/programmer.

All of our Mac (some staff iMacs, mostly MacBooks) user accounts are locally created and maintained, so no need for AD authentication, but out installation of Papercut is using Google Directory Sync as a sync source. I have been assure that once a user tries to print the first time, it should ask for their credentials, which should be their Google account name and password.

I'd like to get this kinda running before next week, but unfortunately, the printers Papercut will be servicing are not assembled and working as yet. That happens this coming Friday.

Any pointers? Anyone else done a 'migration' like this? I've also asked out vendor to reach out to another deployment they did in a similar situation, but I'd like to get ahead of this as much as I can, if possible.

6 REPLIES 6

stevewood
Honored Contributor II
Honored Contributor II

@jdionne

If your machines are already in Jamf, you won't want to create a new QuickAdd.pkg file. That is only for enrolling, or re-enrolling systems. You can utilize a script to do all of this, or multiple scripts if you want to keep it modular and be able to re-use for other purposes.

Remove - you can loop through a listing of printers on a system and remove based on name of printer or connection (IP address for example). If your users had the ability to add printers on their own, and there was no standard naming, using IP address might be the best way, although you can do partial name matches as well.

Remove by name:

printers=($(lpstat -p | awk '{print $2}' | sed '/^$/d'))

for i in "${printers[@]}"
do

        ## if name contains East
    if [[ ${i} == *"East"* ]]; then
        lpadmin -x ${i}

        ## else if name contains West
    elif [[ ${i} == *"West"* ]]; then
        lpadmin -x ${i}
    fi

done

Remove by IP:

Printer1=`${lps} -s | grep 10.50.32.225 | awk {'print $3'} | sed s'/.$//'`
if [[ ${Printer1} ]]; then

    ${lpa} -x ${Printer1}

fi

You can also use some regex-fu to locate the printers by IP or by name if you want.

Deploy driver - in the same script, after you have removed the printers, or before, you can use an if/then statement to check if the printer driver is already installed and if not, call a policy from Jamf to install the printer:

if [[ ! -f "/Library/Printers/PPDs/Contents/Resources/en.lproj/Canon iR-ADV C9200s GX400V1.0US" ]]; then

    /usr/local/bin/jamf policy -event iRAC9200_GX400v1

fi

Deploy queue - now you can create the printer:

/usr/sbin/lpadmin -p My_New_Printer -E -o printer-is-shared=false -v ipp://10.50.32.230/ipp/print -D "My New Printer" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/Canon iR-ADV C9200s GX400V1.0US"

Finally, you can deploy the PaperCut client by calling the policy:

/usr/local/bin/jamf policy -event installpapercut

As far as adjusting a script, not exactly sure what you are referring to there. Could you elaborate?

I have some of this written up on my blog:

Deploying Printers via Script

Identify EFI Fiery Driver

Using lpoptions To Identify Printer Options

Hope this helps!

dreinold
New Contributor II

@stevewood Thanks for the starters! I would like to re-use the current static IPs of the printers as-is, which I guess we can remove and re-add later.

As for the adjustment of the script, there is a config file that has a single statement that we need to uncomment for it to work as a mobile device. As I understand it, they don't currently have an automated way to alter this file pre- or post-install, besides a manual edit. Otherwise, as I've been told, the Papercut client will throw up an error, if, for instance, you take a Macbook home, or to another building where they do not have access to the printers on the network.

stevewood
Honored Contributor II
Honored Contributor II

@jdionne

If you are removing and re-adding using the same IP, you could do it all in one script and in an if/then/elif block. Something like:

Printer1=`lpstat -s | grep 1.1.1.1 | awk {'print $3'} | sed s'/.$//'`
Printer2=`lpstat -s | grep 2.2.2.2 | awk {'print $3'} | sed s'/.$//'`

if [[ ${Printer1} ]]; then

    lpadmin -x ${Printer1} ## remove Printer 1

    ## add driver if missing
    if [[ ! -f "/Library/Printers/PPDs/Contents/Resources/en.lproj/Canon iR-ADV C9200s GX400V1.0US" ]]; then

        /usr/local/bin/jamf policy -event iRAC9200_GX400v1

    fi

    ## add the new printer
    /usr/sbin/lpadmin -p New_Printer_1 -E -o printer-is-shared=false -v ipp://1.1.1.1/ipp/print -D "New Printer 1" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/Canon iR-ADV C9200s GX400V1.0US"

elif [[ ${Printer2} ]]; then

    lpadmin -x ${Printer2} ## remove Printer 2

    ## add driver if missing
    if [[ ! -f "/Library/Printers/PPDs/Contents/Resources/en.lproj/Canon iR-ADV C9200s GX400V1.0US" ]]; then

        /usr/local/bin/jamf policy -event iRAC9200_GX400v1

    fi

    ## add the new printer
    /usr/sbin/lpadmin -p New_Printer_2 -E -o printer-is-shared=false -v ipp://2.2.2.2/ipp/print -D "New Printer 2" -P "/Library/Printers/PPDs/Contents/Resources/en.lproj/Canon iR-ADV C9200s GX400V1.0US"

fi

Obviously you want to change out the IP addresses, the names, the drivers, etc. Also, I wasn't clear in my snippet about removing the printer. ${lpa} is a variable that holds the path to lpadmin and ${lps} is a variable that holds the path to lpstat.

You can install PaperCut before or after that block of code, I'd imagine.

As far as editing the config file, you may be able to use cat along with sed to edit the file. I'd have to see the file to give you some ideas.

I'm sure someone else around here has used PaperCut and can comment on editing the config file. I have no experience with PaperCut so I cannot comment decisively on it.

dreinold
New Contributor II

@stevewood This may be a stupid question, as I am not well-versed in JAMF or Bash.

In following your blog article about adding printers, I believe I am adding a single virtual queue, so I've edited your script for the one I currently have on my Mac, which I can test on another IT Test Mac (yay broken screen glass but otherwise fully functional!).

Anyway, the question is about the

#!/bin/sh
/usr/local/bin/jamf policy -trigger xeroxGenericDriver

I currently don't have a policy with that name or function. I do have the driver package up on JAMF, so I can probably call it to pull down and install, but how would I set that up?

It looks like there is a little more setup here than I anticipated, so thanks for your help!

EDIT: Looking at the script and what I can do via the JAMF GUI, I see that some of these can be accomplished, if not as well as the script, then just easier-ish on my end. So I can probably add the single virtual queue via a policy, and install (I think?) the driver (which is a DMG, if that matters) and run some part of these scripts (after figuring out which parts to use and adding them to JAMF) to get the desired effect.

The final part is the Papercut client application (PCClient), which is not packaged in anyway for easy pushing out to the Macs so that's another hurdle, I think

stevewood
Honored Contributor II
Honored Contributor II

@jdionne

In a policy you have the ability to set a Custom trigger. So for example, on the policy you have to install your driver, if you set a Custom trigger of xeroxGenericDriver, for example, you can then call the policy with jamf policy -trigger xeroxGenericDriver or jamf policy -event xeroxGenericDriver.

And yes, you can accomplish a lot of this via the Jamf GUI, but unless you add the printers to Jamf first using Jamf Admin, you will not be able to remove the printers. Of course one option would be to just remove all printers from the system using a command like lpstat -p | cut -d' ' -f2 | xargs -I{} lpadmin -x {} as part of the "Execute Command" box on the Files & Processes tab of a policy:

746613b0c4364cceb13ea48477877d81

dreinold
New Contributor II

So, just to err on the side of caution, can I put the lpstat -p | cut -d' ' -f2 | xargs -I{} lpadmin -x {} command in as a script and have it run as a separate policy before applying the new printer policies?

Or is the way this is run on the Mac mean I'd have to use the Files & Processes Execute command area? Ideally, I'd love to have this automatically remove all the (now non-existant on the network) printers, and then run the part that adds the virtual queue and drivers. Which, by the way has worked once, on a test Mac I have, but we had not setup the rest of the stuff in Papercut so that was kind of a stilted victory.