#!/bin/zsh # LaDolce Office Printer — Mac setup # Adds the office Epson as a printer that works from anywhere with internet. # Uses your LaDolce (Central Auth) username and password; your account needs # the PRINT app assigned in LaDolce One. # # Run: zsh setup-mac.sh SERVER="print.ladolcecorp.com" QUEUE="LaDolce_Office" PPD="/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/Resources/Generic.ppd" enc() { /usr/bin/perl -MURI::Escape -e 'print uri_escape($ARGV[0])' -- "$1"; } curl_quote() { local s=${1//\\/\\\\}; print -r -- "${s//\"/\\\"}"; } echo "LaDolce Office Printer setup" echo read "LUSER?LaDolce username: " read -s "LPASS?LaDolce password (typing is hidden): "; echo if [[ -z "$LUSER" || -z "$LPASS" ]]; then echo "Username and password are required."; exit 1 fi # Check the login (credentials go through stdin, not the command line) RESULT=$(print -r -- "user = \"$(curl_quote "$LUSER:$LPASS")\"" | /usr/bin/curl -s -m 20 -X POST -K - "https://$SERVER/check.php") if [[ "$RESULT" != *'"success":true'* ]]; then MSG=$(print -r -- "$RESULT" | /usr/bin/sed -nE 's/.*"message":"([^"]*)".*/\1/p') echo "\nCould not add the printer: ${MSG:-cannot reach $SERVER}" exit 1 fi lpadmin -p "$QUEUE" -E \ -v "ipps://$(enc "$LUSER"):$(enc "$LPASS")@$SERVER:443/printers/$QUEUE" \ -P "$PPD" \ -D "LaDolce Office Printer" \ -L "Office — Epson L3210" \ -o auth-info-required=none \ -o printer-is-shared=false || { echo "\nAdding the printer failed."; exit 1; } echo "\nDone. \"LaDolce Office Printer\" is now in your printer list." read "TEST?Print a one-line test page now? [y/N] " if [[ "$TEST" == [yY]* ]]; then echo "LaDolce Office Printer test from $(scutil --get ComputerName 2>/dev/null) - $(date)" | lp -d "$QUEUE" -t "Printer test" >/dev/null && echo "Test page sent." fi echo "If you change your LaDolce password, run this script again."