#!/bin/bash # NEEDED_LIBS=(lib32z1 lib32ncurses5 lib32stdc++6) PRINTER_MANUFACTURER="Brother" PRINTER_SERIES="P-touch" PRINTER_MODEL="PT-P900W" PRINTER_NAME="${PRINTER_MANUFACTURER}-${PRINTER_MODEL}" PRINTER_USB_ID="04f9:2085" PRINTER_PPD_FILE="/usr/share/ppd/Brother/brother_ptp900_printer_en.ppd" PRINTER_LOCATION="BCSPC128 in R2/30" PRINTER_DRIVER_LPR="ptp900lpr-1.0.0-0.i386.deb" PRINTER_DRIVER_CUPS="ptp900cupswrapper-1.0.0-0.i386.deb" DEFAULT_PRINTER_AFTER_DRIVER_INSTALL="PT-P900" # Check, if we are on a X86_64 machine... if [ "`uname -m`" = "x86_64" ]; then echo "64bit architecture detected ..." # Check if nessesary 32bit libs are already installed ... for LIB in ${NEEDED_LIBS[*]} do echo "" echo -n "Check for Lib: $LIB ..." dpkg -s $LIB &> /dev/null if [ $? -eq 0 ]; then echo "Lib: $LIB is already installed!" else echo "Lib: $LIB is not installed -> Installing Lib: $LIB" sudo apt-get -y install $LIB fi done else echo "we are running on a 32bit architecture ..." fi # Check to see if the drivers are installed if [ ! -e $PRINTER_PPD_FILE ] ; then echo "" echo -n "Insalling printer driver ..." sudo mkdir -p /var/spool/lpd/ [ -e $PRINTER_DRIVER_LPR ] && sudo dpkg --install $PRINTER_DRIVER_LPR || echo "Driver $PRINTER_DRIVER_LPR not present" [ -e $PRINTER_DRIVER_CUPS ] && sudo dpkg --install $PRINTER_DRIVER_CUPS || echo "Driver $PRINTER_DRIVER_CUPS not present" echo " done!" else echo "Printer driver already installed!" fi # Remove default printer PT-P900 if it still exsists lpstat -p | grep -i "$DEFAULT_PRINTER_AFTER_DRIVER_INSTALL is idle" &> /dev/null if [ $? -eq 0 ]; then echo "Default printer \"$DEFAULT_PRINTER_AFTER_DRIVER_INSTALL\" from driver package found!" echo -n "Removing default printer to avoid conflicts with new model..." lpadmin -x $DEFAULT_PRINTER_AFTER_DRIVER_INSTALL echo " done." fi # Check to see if the printer is already installed if [ -n "`lpstat -p 2>&1 | grep -E \"${PRINTER_NAME}\"`" ]; then echo "Printer already configured - nothing to do." else # Make sure the printer is available before trying to configure it if [ "`lsusb | grep -i ${PRINTER_MANUFACTURER} | cut -d" " -f6`" = "$PRINTER_USB_ID" ]; then echo "Printer \"${PRINTER_MANUFACTURER} ${PRINTER_SERIES} ${PRINTER_MODEL}\" connected and switched ON." echo -n "Generating printer configuration ..." # get printer URI PRINTER_URI="`lpinfo -v | grep -i direct | cut -d" " -f2`" #echo "Printer URI: $PRINTER_URI" # configure printer for CUPS printing system lpadmin \ -p "${PRINTER_NAME}" \ -v ${PRINTER_URI} \ -P "$PRINTER_PPD_FILE" \ -L "${PRINTER_LOCATION}" \ -o "BRCutLabel=0" \ -o "BRChain=ON" \ -E # Set it as the default printer # lpadmin -d 'Brother-HL-4570CDW' echo " done." else echo "" echo "" echo "Printer \"${PRINTER_MANUFACTURER} ${PRINTER_SERIES} ${PRINTER_MODEL}\" not connected or switched OFF." fi fi