89 lines
3.5 KiB
Bash
89 lines
3.5 KiB
Bash
#!/bin/bash
|
|
################################################################################
|
|
|
|
################################################################################
|
|
#
|
|
################################### variables ##################################
|
|
PrinterLocation="hier Name"
|
|
PrinterDriver="/Library/Printers/PPDs/Contents/Resources/RICOH MP C4504ex"
|
|
PrintProtocol=smb
|
|
#loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");' | tr '[:upper:]' '[:lower:]')
|
|
loggedInUser=$(stat -f '%u %Su' /dev/console | cut -d ' ' -f 2)
|
|
uid=$(id -u "${loggedInUser}")
|
|
kerbticketuser=$(launchctl asuser ${uid} klist -l | awk -F'[ ]' 'END{print $2}')
|
|
userloginkeychain="/Users/${loggedInUser}/Library/Keychains/login.keychain-db"
|
|
cupsplist=/Library/Preferences/org.cups.printers.plist
|
|
################################### functions ##################################
|
|
#function to delete old printers and keychain objects
|
|
#get all installed printers, check for each object if installed printer is a ING printer, if so delete printer and delete keychainobject if existing
|
|
deleteoldprintqueues() {
|
|
i=0
|
|
lpstat -p | awk '{print $2}' | while read printer
|
|
do
|
|
if [[ ${printer} == Central_Print_Queue* ]]; then
|
|
printerdescription=$(/usr/libexec/PlistBuddy -c "Print $i:printer-info" ${cupsplist})
|
|
if [[ -f $userloginkeychain ]]; then
|
|
keychainobject=$(security find-internet-password -l "${printerdescription}" keychain "${userloginkeychain}" | grep "${printerdescription}" | awk -F'[=]' '{gsub(/"/, "", $2); print $2}')
|
|
if [[ ${keychainobject} ]] && [[ ${printerdescription} == ${keychainobject} ]]; then
|
|
echo "delete '${keychainobject}' object from login keychain"
|
|
security delete-internet-password -l "${printerdescription}" keychain "${userloginkeychain}"
|
|
fi
|
|
else
|
|
echo "login keychain not found"
|
|
fi
|
|
echo "deleting printer:" ${printer}
|
|
lpadmin -x ${printer}
|
|
fi
|
|
i=$(($i + 1))
|
|
done
|
|
}
|
|
|
|
#set variables for printqueue1
|
|
printqueue1() {
|
|
PrinterName="Central_Print_Queue_1"
|
|
PrinterDescription="Central Print Queue 1"
|
|
PrintServer=su8000006361.ad.ing.net
|
|
PrintQueue=CentralPrintQueue1
|
|
}
|
|
|
|
#set variables for printqueue8
|
|
printqueue8() {
|
|
PrinterName="Central_Print_Queue_8"
|
|
PrinterDescription="Central Print Queue 8"
|
|
PrintServer=su8000006368.ad.ing.net
|
|
PrintQueue=CentralPrintQueue8
|
|
}
|
|
|
|
#function to add printer
|
|
#printer will be installed with Kerberos Authentication and with set default options to use installed trays and finisher
|
|
addprinter() {
|
|
/usr/sbin/lpadmin \
|
|
-p ${PrinterName} \
|
|
-D "${PrinterDescription}" \
|
|
-L "${PrinterLocation}" \
|
|
-E -v ${PrintProtocol}://${PrintServer}/${PrintQueue} \
|
|
-P "${PrinterDriver}" \
|
|
-o printer-is-shared=false \
|
|
-o PageSize=A4 \
|
|
-o Duplex=DuplexNoTumble \
|
|
-o OptionTray=2Cassette \
|
|
-o Finisher=FinAMURHY \
|
|
-o ColorModel=Gray \
|
|
-o auth-info-required=negotiate
|
|
echo ${PrinterName} "installed with Kerberos Authentication"
|
|
}
|
|
################################### execution ##################################
|
|
## check if user has a Kerberos Ticket and install/correct printers accordingly
|
|
if [[ -n ${kerbticketuser} ]]; then
|
|
echo ${loggedInUser} "has a ticket with ID:" ${kerbticketuser}
|
|
deleteoldprintqueues
|
|
printqueue1
|
|
addprinter
|
|
printqueue8
|
|
addprinter
|
|
else
|
|
echo ${loggedInUser} "has no Kerberos Ticket - aborting"
|
|
exit 1
|
|
fi
|
|
################################### end ########################################
|
|
exit 0 |