X-Git-Url: https://git.slaskete.net/einar-bin/blobdiff_plain/d0516fbae9de87ae04446ad16fd342c7f0cec28d..f864072b93bf89fc47ef6e4fa265cd3f34a2d94c:/addfollowmeprint.sh?ds=sidebyside diff --git a/addfollowmeprint.sh b/addfollowmeprint.sh index 035767d..f50b1d0 100755 --- a/addfollowmeprint.sh +++ b/addfollowmeprint.sh @@ -1,14 +1,16 @@ #!/bin/bash -# This script installs the FollowMe print queue at NTNU on Linux (and possibly Mac) systems. +# This script installs the FollowMe print queue at NTNU on Linux and possibly Mac systems. # The targeted and tested distros are: Debian, Ubuntu (and derivates), Fedora, CentOS, OpenSUSE and Mint # Copyright © 2017-2019 einar.haraldseid@ntnu.no +# LibreOffice has some problems on Linux, see https://bugs.documentfoundation.org/show_bug.cgi?id=126604 + # Documentation function usage { echo "Usage: ./$(basename "${0}") [OPTIONS]" echo "Options:" echo " -m, --model {ricoh|generic} Printer model to install (default: generic)" - echo " -d, --driver {pcl,postscript} Printer driver to use (default: postscript)" + echo " -d, --driver {pcl|postscript} Printer driver to use (default: postscript)" echo " -f, --force Force running script as if on Linux systems" echo " -p, --plaintext Store credentials as plaintext in /etc/cups/printers.conf (Linux only)" echo " -h, --help Display this help text" @@ -139,7 +141,7 @@ if [ "${Uname}" = "linux" ]; then if ! sudo rpm -q OpenPrintingPPDs-postscript >/dev/null 2>&1; then printerror "You don't seem to have the correct printer drivers installed, please run:" printerror " sudo zypper install OpenPrintingPPDs-postscript" - printerror "first, or use the generic driver instead." + printerror "first, or use the generic model instead." exit 1 else DriverPath="OpenPrintingPPDs/postscript/Ricoh-MP_C6003.Postscript-Ricoh.ppd.gz" @@ -151,7 +153,7 @@ if [ "${Uname}" = "linux" ]; then if ! sudo rpm -q OpenPrintingPPDs-ghostscript >/dev/null 2>&1; then printerror "You don't seem to have the correct printer drivers installed, please run:" printerror " sudo zypper install OpenPrintingPPDs-ghostscript" - printerror "first, or use the generic driver instead." + printerror "first, or use the generic model instead." exit 1 else if [ "${Model}" = "ricoh" ]; then @@ -166,10 +168,10 @@ if [ "${Uname}" = "linux" ]; then if [ "${Model}" = "ricoh" ]; then # This should match Fedora and other modern rpm based systems that have dnf as the primary package manager if command -v dnf >/dev/null 2>&1; then - if ! sudo rpm -q foomatic-db-ppds 2>&1; then + if ! sudo rpm -q foomatic-db-ppds > /dev/null 2>&1; then printerror "You don't seem to have the correct printer drivers installed, please run:" printerror " sudo dnf install foomatic-db-ppds" - printerror "first, or use the generic driver instead." + printerror "first, or use the generic model instead." exit 1 else if [ "${Driver}" = "postscript" ]; then @@ -178,13 +180,18 @@ if [ "${Uname}" = "linux" ]; then DriverPath="foomatic-db-ppds/Ricoh/PXL/Ricoh-MP_C6003_PXL.ppd.gz" fi fi - fi # This should match CentOS, RHEL and other RHEL based distros that have yum as the primary package manager - if command -v yum >/dev/null 2>&1; then - if ! sudo rpm -q foomatic-db-ppds >/dev/null 2>&1; then + elif command -v yum >/dev/null 2>&1; then + if ! sudo rpm -q foomatic-filters > /dev/null 2>&1; then + printerror "You don't seem to have the foomatic-filters package installed, please run:" + printerror " sudo yum install foomatic-filters" + printerror "first, or use the generic model instead." + exit 1 + fi + if ! sudo rpm -q foomatic-db-ppds > /dev/null 2>&1; then printerror "You don't seem to have the correct printer drivers installed, please run:" printerror " sudo yum install foomatic-db-ppds" - printerror "first, or use the generic driver instead." + printerror "first, or use the generic model instead." exit 1 else if [ "${Driver}" = "postscript" ]; then @@ -199,7 +206,7 @@ if [ "${Uname}" = "linux" ]; then if ! sudo dpkg -s openprinting-ppds > /dev/null 2>&1; then printerror "You must have the correct printer drivers installed, please run:" printerror " sudo apt-get install openprinting-ppds" - printerror "first, or use the generic driver instead." + printerror "first, or use the generic model instead." exit 1 else if [ "${Driver}" = "postscript" ]; then @@ -217,9 +224,9 @@ echo "This script will add a new printer called ${QueueName}, connecting to the print server ${PrintServer} using your user name and password from NTNU." # Get username and password -printf "User name: " +printf "NTNU User name: " read -r Username -printf "Password: " +printf "NTNU Password: " Settings=$(stty -g) stty -echo read -r Password @@ -252,7 +259,7 @@ if [ "${Uname}" = "darwin" ]; then fi ShareFound=$(smbutil view "//${Workgroup};${Username}:${Password}@${PrintServer}" 2>/dev/null | grep ${PrintFile} | cut -d " " -f 1) if [ "${ShareFound}" != "${PrintFile}" ]; then - printerror "Could not find printer share called ${PrintFile} on the server" + printerror "Could not find printer share called ${PrintFile} on the server" printerror "This script must be broken or outdated. Please contact orakel@ntnu.no for further assistance." exit 1 fi @@ -270,6 +277,7 @@ if [ "${Uname}" = "linux" ]; then else PrinterShare="smb://${Workgroup}/${PrintServer}/${PrintFile}" AuthInfo="username,password" + echo -e "\nNOTE: Due to the way credentials are stored and accessed on Linux, some print operations will still halt for credentials, notably the \"Print test page\" function and printing from LibreOffice. In those cases, supply your normal NTNU username and password. If this becomes too tedious, you can try using the --plaintext option.\n" fi if ! sudo lpadmin -p ${QueueName} \ -D "FollowMe print queue at NTNU" \ @@ -305,18 +313,24 @@ if [ "${Uname}" = "darwin" ]; then exit 1 fi - sudo cupsenable "${QueueName}" - sudo cupsaccept "${QueueName}" - # Add credentials to the keychain if they are missing # Shamelessly stolen^W^WBorrowed from https://github.com/Orakeltjenesten/scripts/blob/33abfb353524f449f0bbdee27adb2f1f0a9756a2/print/ntnuprint-mac.sh - # TODO: Since we should have a known-good username and password at this stage it's unwise to re-use the existing credentials, can we simply drop the test? - if ! security find-internet-password -s ${PrintServer} >/dev/null 2>&1; then - security -v add-internet-password -a "${Workgroup}\\${Username}" -s ${PrintServer} \ - -w "${Password}" -D "Network Password" -r "smb " -l "${QueueName}" \ - -T /System/Library/CoreServices/NetAuthAgent.app -T 'group://NetAuth' \ - -T /System/Library/CoreServices/NetAuthAgent.app/Contents/MacOS/NetAuthSysAgent >/dev/null 2>&1 + security -v add-internet-password -U -a "${Workgroup}\\${Username}" -s "${PrintServer}" \ + -w "${Password}" -D "Network Password" -r "smb " -l "${QueueName}" \ + -T /System/Library/CoreServices/NetAuthAgent.app -T 'group://NetAuth' \ + -T /System/Library/CoreServices/NetAuthAgent.app/Contents/MacOS/NetAuthSysAgent >/dev/null 2>&1 + + # Make sure the password has the correct ACL ref https://mostlikelee.com/blog-1/2017/9/16/scripting-the-macos-keychain-partition-ids + OS_Min_Vers=$(sw_vers | grep ProductVersion | awk '{print $2}' | cut -d "." -f2) + if [ "${OS_Min_Vers}" -ge 12 ]; then + echo -e "\nNOTE: You need to provide your local Mac password again here in order to give the printing system access to your credentials.\n" + security set-internet-password-partition-list -S "apple-tool:,apple:" -s "${PrintServer}" > /dev/null fi + + sudo cupsenable "${QueueName}" + sudo cupsaccept "${QueueName}" + sudo launchctl stop org.cups.cupsd + sudo launchctl start org.cups.cupsd fi # Set correct paper size and enable the duplexer option @@ -331,4 +345,4 @@ if ! sudo lpadmin -d ${QueueName}; then exit 1 fi -echo "Printer successfully installed. You may need to restart cups for the changes to take effect." +echo "Printer successfully installed."