Snippets
Kevin Klement Script to install drivers and configure UMass philosophy Toshiba printer on Linux and Mac
Created by
Kevin Klement
last modified
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | #!/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)
You can clone a snippet to your computer for local editing. Learn more.