2 # This script installs the FollowMe print queue at NTNU on Linux (and possibly Mac) systems.
3 # The targeted and tested distros are: Debian, Ubuntu (and derivates), Fedora, CentOS, OpenSUSE and Mint
4 # Copyright © 2017 einar.haraldseid@ntnu.no
8 echo "Usage: ./$(basename "${0}") [OPTIONS]"
10 echo " -m, --model {ricoh|generic} Printer model to install (default: generic)"
11 echo " -d, --driver {pcl,postscript} Printer driver to use (default: postscript)"
12 echo " -f, --force Force running script as if on Linux systems"
13 echo " -h, --help Display this help text"
16 # Print errors to STDERR
17 function printerror
() {
22 if [ ${UID} -ne 0 ] ; then
23 echo "This script must be run as root, relaunching with sudo:"
28 # Set default options that may be overridden by passed options below
32 # Set other default options
33 PrintServer
="followprint.win.ntnu.no"
35 Workgroup
="WIN-NTNU-NO"
37 while [[ $# -gt 0 ]]; do
42 Model
=$
(echo "${2}" |
tr "[:upper:]" "[:lower:]")
43 if [ "${Model}" != "ricoh" ] && [ "${Model}" != "generic" ]; then
44 printerror
"Unknown model ${Model}, please choose one of ricoh or generic"
47 shift # Jump to next argument
51 shift # Jump to next argument
54 Driver
=$
(echo "${2}" |
tr "[:upper:]" "[:lower:]")
55 if [ "${Driver}" != "postscript" ] && [ "${Driver}" != "pcl" ]; then
56 printerror
"Unknown driver ${Driver}, plase choose one of postscript or pcl"
59 shift # Jump to next option
67 echo "Unknown option: ${Key}"
72 shift # past argument or value
75 # Test for supported OS
76 Uname
=$
(uname |
tr "[:upper:]" "[:lower:]")
77 if [ "${Uname}" != "darwin" ] && [ "${Uname}" != "linux" ] && [ "${Force}" != "YES" ]; then
78 printerror
"I don't think I can run on ${Uname}, but if you insist, please use -f to force Linux detection. This may not work, though."
82 # Set Uname to linux if we are forcing running the script
83 if [ "${Force}" = "YES" ]; then
87 # Set printer share based on model (generic goes to ntnuprint-xerox)
88 if [ "${Model}" = "ricoh" ]; then
89 PrintShare
="ntnuprint-ricoh"
91 PrintShare
="ntnuprint-xerox"
94 # Set printer driver path based on driver (we will override these if we're specific distros
95 if [ "${Driver}" = "postscript" ]; then
96 DriverPath
="drv:///sample.drv/generic.ppd"
98 DriverPath
="drv:///sample.drv/generpcl.ppd"
102 if ! command -v lpadmin
> /dev
/null
2>&1; then
103 printerror
"You must have CUPS installed to add printers. Please install CUPS."
107 # Tests for Linux systems
108 if [ "${Uname}" = "linux" ]; then
109 # Test if smbclient is installed
110 if ! command -v smbclient
>/dev
/null
2>&1; then
111 printerror
"You must have smbclient installed to print to NTNU followprint. Please install smbclient."
115 # Try to determine if the necessary printer drivers are installed, and set alternate driver paths
116 # This should match OpenSUSE, and probably SUSE Enterprise, and other derivates that use yast2 as the primary package
117 if command -v yast2
>/dev
/null
2>&1; then
118 if [ "${Driver}" = "postscript" ]; then
119 if ! rpm
-q OpenPrintingPPDs-postscript
>/dev
/null
2>&1; then
120 printerror
"You don't seem to have the correct printer drivers installed, please run:"
121 printerror
" sudo zypper install OpenPrintingPPDs-postscript"
122 printerror
"first, or use the generic driver instead."
125 if [ "${Model}" = "ricoh" ]; then
126 DriverPath
="OpenPrintingPPDs/postscript/Ricoh-MP_C6003.Postscript-Ricoh.ppd.gz"
128 DriverPath
="OpenPrintingPPDs/postscript/Generic-PostScript_Printer.Postscript.ppd.gz"
132 if ! rpm
-q OpenPrintingPPDs-ghostscript
>/dev
/null
2>&1; then
133 printerror
"You don't seem to have the correct printer drivers installed, please run:"
134 printerror
" sudo zypper install OpenPrintingPPDs-ghostscript"
135 printerror
"first, or use the generic driver instead."
138 if [ "${Model}" = "ricoh" ]; then
139 DriverPath
="OpenPrintingPPDs/ghostscript/Ricoh-MP_C6003.pxlcolor-Ricoh.ppd.gz"
141 DriverPath
="OpenPrintingPPDs/ghostscript/Generic-PCL_6_PCL_XL_Printer.pxlcolor.ppd.gz"
146 # The rest of the tests ignore the model test (all other distros support drv:///)
147 if [ "${Model}" != "generic" ]; then
148 # This should match Fedora and other modern rpm based systems that have dnf as the primary package manager
149 if command -v dnf
>/dev
/null
2>&1; then
150 if ! rpm
-q foomatic-db-ppds
2>&1; then
151 printerror
"You don't seem to have the correct printer drivers installed, please run:"
152 printerror
" sudo dnf install foomatic-db-ppds"
153 printerror
"first, or use the generic driver instead."
156 if [ "${Driver}" = "postscript" ]; then
157 DriverPath
="foomatic-db-ppds/Ricoh/PS/Ricoh-MP_C6003_PS.ppd.gz"
159 DriverPath
="foomatic-db-ppds/Ricoh/PXL/Ricoh-MP_C6003_PXL.ppd.gz"
163 # This should match CentOS, RHEL and other RHEL based distros that have yum as the primary package manager
164 if command -v yum
>/dev
/null
2>&1; then
165 if ! rpm
-q foomatic-db-ppds
>/dev
/null
2>&1; then
166 printerror
"You don't seem to have the correct printer drivers installed, please run:"
167 printerror
" sudo yum install foomatic-db-ppds"
168 printerror
"first, or use the generic driver instead."
171 if [ "${Driver}" = "postscript" ]; then
172 DriverPath
="foomatic-db-ppds/Ricoh/PS/Ricoh-MP_C6003_PS.ppd.gz"
174 DriverPath
="foomatic-db-ppds/Ricoh/PXL/Ricoh-MP_C6003_PXL.ppd.gz"
178 # This should match Debian, Ubuntu and most if not all derivates that use dpkg as the primary package manager
179 if command -v dpkg
>/dev
/null
2>&1; then
180 if ! dpkg
-s openprinting-ppds
> /dev
/null
2>&1; then
181 printerror
"You must have the correct printer drivers installed, please run:"
182 printerror
" sudo apt-get install openprinting-ppds"
183 printerror
"first, or use the generic driver instead."
186 if [ "${Driver}" = "postscript" ]; then
187 DriverPath
="openprinting-ppds:0/ppd/openprinting/Ricoh/PS/Ricoh-MP_C6003_PS.ppd"
189 DriverPath
="openprinting-ppds:0/ppd/openprinting/Ricoh/PXL/Ricoh-MP_C6003_PXL.ppd"
196 echo "This script will add a new printer called ${PrintName}, connecting to the
197 print server ${PrintServer} using your normal user name and
200 NOTE: Your credentials will be stored in plaintext in /etc/cups/printers.conf.
201 This file us usually not readable for normal users, but still:
202 Do not use this script on multi user systems!"
204 # Get username and password
215 # Some further tests for Linux systems
216 # TODO: Add similar tests for macOS
217 if [ "${Uname}" = "linux" ]; then
218 # Test for valid username and password if on Linux
219 # Bonus: find out if the print share is actually available
220 PrintServerIP
=$
(getent ahostsv4
${PrintServer} |
head -n 1 | cut
-d " " -f 1)
221 smbclient
-U "${Workgroup}/${Username}%${Password}" -L "//${PrintServer}" -I "${PrintServerIP}" > /dev
/null
2>&1
222 if [ $?
-ne 0 ]; then
223 printerror
"User name or password incorrect, or no contact with the print server ${PrintServer}."
226 ShareFound
=$
(smbclient
-U "${Workgroup}/${Username}%${Password}" -L "//${PrintServer}" -I "${PrintServerIP}" -g 2>/dev/null | grep ${PrintShare} | cut -d "|
" -f 1)
227 if [ "${ShareFound}" != "Printer
" ]; then
228 printerror "Could not
find printer share called
${PrintShare} on the server
"
229 printerror "This
script must be broken or outdated. Please contact orakel@ntnu.no
for further assistance.
"
234 # Finally we can add the printer
237 if [ "${Uname}" = "linux
" ]; then
238 lpadmin -p ${PrintName} \
239 -D "FollowMe print queue
at NTNU
" \
240 -v "smb
://${Username}:${Password}@${Workgroup}/${PrintServer}/${PrintShare}" \
246 if [ "${Uname}" = "darwin
" ]; then
247 lpadmin -p ${PrintName} \
248 -D "FollowMe print queue
at NTNU
" \
249 -v "smb
://${Workgroup};${Username}:${Password}@${Workgroup}/${PrintServer}/${PrintShare}" \
254 if [ $? -ne 0 ]; then
255 printerror "Could not connect to printer share. See above error
for details.
"
259 # Set correct paper size and enable the duplexer option
260 lpadmin -p ${PrintName} -o PageSize=A4 -o Option1=True
262 if [ $? -ne 0 ]; then
263 printerror "Could not
set default options on the print queue
${PrintName}. See above error
for details.
"
268 lpadmin -d ${PrintName}
270 if [ $? -ne 0 ]; then
271 printerror "Could not
set the print queue
${PrintName} as default printer. See above error
for details.
"
275 echo "Printer successfully installed.
"