Snippets

Kevin Klement Script to install drivers and configure UMass philosophy Toshiba printer on Linux and Mac

Created by Kevin Klement last modified
#!/bin/bash

cat << EOF

Welcome to the philosophy printer configuration script.

The script will likely ask for your password now. This is the
password you use when installing new software on your computer,
and NOT your UMass password or accounting code.

EOF

cat > printer-root-config.sh << 'RUNWITHSUDO'
#!/bin/bash

##### FUNCTIONS

# function for exiting midway
function rage_quit {

    cat >&2 << EOF

Unfortunately, the script encountered an error.
You can ask Kevin for help.

EOF
    exit 1
}

function setup_single_config  {
    local NETID="$1"
    local CODE="$2"
    local DRIVERB="TOSHIBA_MonoMFP_CUPS_$NETID"
    local FILTERB="est856_Authentication_$NETID"
    local DRIVERPATH="$DRIVERLOC/$DRIVERB"
    local FILTERPATH="$FILTERLOC/$FILTERB"
    local PRINTERNAME="Philosophy-Toshiba-$NETID"
    echo
    echo "Setting up printer $PRINTERNAME"
    echo
    echo "Making copy of driver..."
    cp TOSHIBA_MonoMFP_CUPS.gz "$DRIVERB.gz" || rage_quit
    cp "est856_Authentication" "$FILTERB"
    echo "Unzipping driver..."
    gunzip "$DRIVERB.gz" || rage_quit
    echo "Configuring driver filter to use NetID $NETID..."
    sed 's/USERLOGIN.*/USERLOGIN='$NETID'\\n";/' "$FILTERB" > "$FILTERB.tmp" || rage_quit
    mv "$FILTERB.tmp" "$FILTERB"
    echo "Configuring driver to use code $CODE..."
    sed 's@^\*Password: "(@*Password: "('$CODE'@' "$DRIVERB" > "$DRIVERB.tmp" || rage_quit
    echo "Setting filter location..."
    sed "s@/usr/lib/cups/filter/est856_Authentication@$FILTERPATH@" "$DRIVERB.tmp" > "$DRIVERB" || rage_quit
    echo "Creating destination folders..."
    mkdir -p "$FILTERLOC" || rage_quit
    mkdir -p "$DRIVERLOC" || rage_quit
    echo "Moving driver copy into position...."
    mv "$FILTERB" "$FILTERPATH" || rage_quit
    mv "$DRIVERB" "$DRIVERPATH" || rage_quit
    echo "Making filter executable..."
    chmod a+x "$FILTERPATH"
    echo "Adding to printer list..."
    lpadmin -p "$PRINTERNAME" -E -v lpd://$NETID@128.119.194.18 -o printer_is_shared=false -o media=letter -o password=$CODE -o user=$NETID -o Pedestal=Drawer12L -o Finisher=Saddle2+1 -o OutputBin=Tray1 -P "$DRIVERPATH" > /dev/null 2>&1 || rage_quit
    echo Enabling jobs...
    cupsenable "$PRINTERNAME" || rage_quit
    echo Accepting jobs...
    cupsaccept "$PRINTERNAME" || rage_quit
    echo "Printer $PRINTERNAME set up successfully. (I think!)"
}

####### SCRIPT START; ASK QUESTIONS
cat <<EOF

Now I need to ask some questions.

EOF

DOPERSONAL=""

while [[ ! "$DOPERSONAL" =~ [yY] ]] && [[ ! "$DOPERSONAL" =~ [nN] ]] ; do
	echo "Do you need to set up a printer configuration"
    echo -n "for your personal account (y/n)? "
	read -s -n 1 DOPERSONAL
    echo
done

if [[ "$DOPERSONAL" =~ [yY] ]] ; then
    echo
    echo -n "What is your UMass NetID? "
    read NETID
    NETID="${NETID%@*}"
    echo
    echo -n "What is your personal four-digit accounting code? "
    read PERSONALCODE
    echo
fi

while [[ ! "$DOTEACHING" =~ [yY] ]] && [[ ! "$DOTEACHING" =~ [nN] ]] ; do
	echo "Do you need to set up a printer configuration"
    echo -n "for your teaching account (y/n)? "
	read -s -n 1 DOTEACHING
    echo
done

if [[ "$DOTEACHING" =~ [yY] ]] ; then
    echo
    echo -n "What is your Teaching account name (e.g., ta-f19-100)? "
    read TEACHID
    TEACHID="${TEACHID%@*}"
    echo
    echo "What is the four-digit accounting code for" 
    echo -n "your teaching account? "
    read TEACHCODE
    echo
fi

# check if we're running linux
if [[ "$(uname)" =~ "Linux" ]] ; then
    # awesome linux user
    LINUX="yes"
    DRIVERLOC="/usr/share/cups/model/Toshiba"
    FILTERLOC="/usr/lib/cups/filter"
else
    # horrible, evil-corporation-loving mac user
    LINUX="no"
    FILTERLOC="/usr/libexec/cups/filter"
    DRIVERLOC="/Library/Printers/PPDs/Contents/Resources"
fi

##### Move to temporary folder and get driver

mkdir -p /tmp/toshiba-setup
cd /tmp/toshiba-setup
rm -rf *
echo Downloading driver...
echo 
# OLD: curl -O http://business.toshiba.com/downloads/KB/f1Ulds/16770/TOSHIBA_MonoMFP_CUPS.tar
curl -O https://business.toshiba.com/downloads/KB/f1Ulds/16770/TOSHIBA_MonoMFP_CUPS.tar
echo
echo Unpacking driver components...
echo
tar xf TOSHIBA_MonoMFP_CUPS.tar > /dev/null 2>&1 || rage_quit
[[ -e "usr/share/cups/model/Toshiba/TOSHIBA_MonoMFP_CUPS.gz" ]] || rage_quit
[[ -e "usr/lib/cups/filter/est856_Authentication" ]] || rage_quit
mv "usr/share/cups/model/Toshiba/TOSHIBA_MonoMFP_CUPS.gz" . || rage_quit
mv "usr/lib/cups/filter/est856_Authentication" . || rage_quit

if [[ "$DOPERSONAL" =~ [yY] ]] ; then
    setup_single_config "$NETID" "$PERSONALCODE"
fi

if [[ "$DOTEACHING" =~ [yY] ]] ; then
    setup_single_config "$TEACHID" "$TEACHCODE"
fi

echo
echo "Cleaning up..."
echo

cd /tmp
[[ -d "/tmp/toshiba-setup" ]] && rm -rf /tmp/toshiba-setup

cat << EOF

You should be all set. Select the printer name that includes
the appropriate username at the end, as listed above.

Your computer may create a duplicate printer without anything
else included in its name. That one probably won't work.

Also your printer may ask for your username and password the
first time. Use your UMass NetId or teaching username as
appropriate, and use the accounting code as the 
password.

You may need to restart your computer and restart your individual 
applications before things work completely.

Let Kevin know if this script didn't work for you. He might
be able to fix it. Also, let him know if it did. People need
positive reinforcement, Kevin especially.

Press Ctrl-D or type "exit" to close this terminal window.

EOF
RUNWITHSUDO
sudo bash printer-root-config.sh
rm printer-root-config.sh
exit 0

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.