Skip to content

Instantly share code, notes, and snippets.

@notverypc
Created March 26, 2015 19:13
Show Gist options
  • Save notverypc/5b248a34340ef85b531f to your computer and use it in GitHub Desktop.
Save notverypc/5b248a34340ef85b531f to your computer and use it in GitHub Desktop.
DeployPrinter
#!/bin/sh
# (c) 2010 Walter Meyer SUNY Purchase College
# Script to install and setup printers on a Mac OS X system in a "Munki-Friendly" way.
# Make sure to install the required drivers first!
# Variables. Edit these.
printername="MFD_Colour"
location="MFD Colour"
gui_display_name="MFD Colour"
address="lpd://server.address/MFD%20Colour"
driver_ppd="/Library/Printers/PPDs/Contents/Resources/KONICAMINOLTAC652DS.gz"
# Populate these options if you want to set specific options for the printer. E.g. duplexing installed, etc.
option_1=""
option_2=""
option_3=""
### Printer Install ###
# In case we are making changes to a printer we need to remove an existing queue if it exists.
/usr/bin/lpstat -p $printername
if [ $? -eq 0 ]; then
/usr/sbin/lpadmin -x $printername
fi
# Now we can install the printer.
/usr/sbin/lpadmin \
-p "$printername" \
-L "$location" \
-D "$gui_display_name" \
-v "$address" \
-P "$driver_ppd" \
-o "$option_1" \
-o "$option_2" \
-o "$option_3" \
-o printer-is-shared=false \
-E
# Enable and start the printers on the system (after adding the printer initially it is paused).
/usr/sbin/cupsenable $(lpstat -p | grep -w "printer" | awk '{print$2}')
# Create an uninstall script for the printer.
uninstall_script="/private/etc/cups/printers_deployment/uninstalls/$printername.sh"
mkdir -p /private/etc/cups/printers_deployment/uninstalls
echo "#!/bin/sh" > "$uninstall_script"
echo "/usr/sbin/lpadmin -x $printername" >> "$uninstall_script"
echo "/usr/bin/srm /private/etc/cups/printers_deployment/uninstalls/$printername.sh" >> "$uninstall_script"
# Permission the directories properly.
chown -R root:_lp /private/etc/cups/printers_deployment
chmod -R 700 /private/etc/cups/printers_deployment
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment