Snippets

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

You are viewing an old version of this snippet. View the current version.
Revised by Kevin Klement 192adec
#!/bin/bash

# function for exiting midway
function rage_quit {

    cat > /dev/stderr << EOF

Unfortunately, the script encountered an error.
You may need to ask for help.

EOF
exit 1

}

# check if we're running linux
if [[ "$(uname)" =~ "Linux" ]] ; then
    LINUX="yes"
    DRIVERLOC="/usr/share/cups/model/Toshiba/TOSHIBA_MonoMFP_CUPS.gz"
else
    LINUX="no"
    DRIVERLOC="/Library/Printers/PPDs/Contents/Resources/TOSHIBA_MonoMFP_X7.gz"
fi

cat << EOF

Welcome to the philosophy printer install script.

First I need some info from you.

EOF
echo -n "What is your UMass NetID? "
read NETID

# ensure cups folder exists
mkdir -p $HOME/.cups > /dev/null 2>&1

# check if username already in cups folder; if not, add it
if [[ ! -e "$HOME/.cups/client.conf" ]] || ! grep -q "User $NETID" $HOME/.cups/client.conf ; then
    echo "User $NETID" >> $HOME/.cups/client.conf
fi

# check if CUPS username already loaded by .bash_profile; if not edit it
if [[ ! -e "$HOME/.bash_profile" ]] || ! grep -q "export CUPS_USER=$NETID" $HOME/.bash_profile ; then
    echo "export CUPS_USER=$NETID" >> $HOME/.bash_profile
fi

cat << EOF

I need your accounting codes. If you have more than
one please separate them with commas, e.g.: 1234,5678

If you want to set one as default, list it first.

EOF

DEFAULTSET="no"

echo -n "Your codes? "
# the IFS variable sets delimiters between array generated by read -a (comma and space)
IFS=", " read -a CODES

# Time to fetch and install the driver package from Toshiba

# checks if driver is already in place; skip this section if it is
if [[ ! -e "$DRIVERLOC" ]] ; then

    if [[ "$LINUX" == "yes" ]] ; then

        cat << EOF

The driver is about to be downloaded and installed. You may 
need to enter your password (for sudo on the local machine).

EOF

        sudo bash << EOF 
cd / && curl -O http://business.toshiba.com/downloads/KB/f1Ulds/16770/TOSHIBA_MonoMFP_CUPS.tar && tar xf TOSHIBA_MonoMFP_CUPS.tar
EOF

    else 

        cat << EOF

An installer for the driver is about to download and open. 
If you need help, consult pages 90-93 of this PDF
(starting from step 6, and ending at step 13;
do not move on to pages 94 or later...)

https://www.toshiba-business.com.au/-/media/Sharepoint/Guides/MFD-Guides/Software-Installation-Guide-eBN2.pdf

When you are done, return to the terminal, and
finish using this script. You need to do so to set things
up to use your accounting codes.

Press any key to start the installation or Ctrl-C 
to quit.

EOF
        read -s -n 1 whateva

        cd /tmp
        echo Downloading driver...
        curl --silent -O "http://business.toshiba.com/downloads/KB/f1Ulds/17022/TOSHIBA_MonoMFP.dmg.gz" || rage_quit
        echo Unzipping driver package...
        gunzip TOSHIBA_MonoMFP.dmg.gz || rage_quit
        echo Mounting driver image...
        hdiutil attach TOSHIBA_MonoMFP.dmg > /dev/null 2>&1 || rage_quit
        echo Opening installer...
        open /Volumes/TOSHIBA\ MonoMFP/TOSHIBA\ MonoMFP.pkg > /dev/null 2>&1 || rage_quit
        cat <<EOF

        Press a key when you are done with the graphical installer.

EOF
        read -s -n 1 whateva
        echo Unmounting driver image...
        hdiutil detach /Volumes/TOSHIBA\ MonoMFP
    fi
fi

for CODE in ${CODES[@]} ; do
    
    cat <<EOF

Setting up printer option: Philosophy-Toshiba-$CODE"

The script may ask you for a password. This is the password
used for installing software on your computer, NOT your 
UMass password.

EOF

    sudo lpadmin -p "Philosophy-Toshiba-$CODE" -E -v lpd://$NETID@128.119.194.18 -o printer_is_shared=false -o auth-info-required=username,password -o media=letter -o password=$CODE -o user=$NETID -o Pedestal=Drawer12L -o Finisher=Saddle2+1 -P $DRIVERLOC > /dev/null 2>&1 || rage_quit
    if [[ $DEFAULTSET == "no" ]] ; then
        echo making default
	sudo lpadmin -d "Philosophy-Toshiba-$CODE" || rage_quit
        DEFAULTSET="yes"
    fi
    echo Enabling jobs...
    sudo cupsenable -U "$NETID" Philosophy-Toshiba-$CODE
    echo Accepting jobs...
    sudo cupsaccept -U "$NETID" Philosophy-Toshiba-$CODE
    echo "Printer option Philosophy-Toshiba-$CODE set up"

done

cat << EOF

You should be all set. Select the printer name that includes
the code as part of the name, as listed above.

Your computer may create a duplicate printer without the code
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 and the account code as the 
password, though I'm not sure this prompt actually does anything, 
hence the need to provide the code during this setup process.

You probably need to reboot and/or restart your individual 
applications before they work completely.

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

EOF
exit 0
HTTPS SSH

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