#!/bin/sh

# This script will install the foo2zjs printer driver for Ubuntu Linux
# This seems to be the only way to effectively use printers that use the Zenographics ZjStream wire protocol.
# This script must be run as root with 755 permission
#
# Authored by Bob Nelson  admin@stchman.com
#
# This script was made possible by the folks over at http://foo2zjs.rkkda.com/

# Usage ubuntu_foo2zjs_install.sh <printer_model>
# $1 is the printer model gotten from the command line while executing this script

script_name="ubuntu_foo2zjs_install.sh"

# Script must run as root 
if [ $USER != "root" ]; then
	echo "You need to run this script as root."
	echo "Use 'sudo ./$script_name' then enter your password when prompted."
	exit 1
fi

# check to see if $1 is NULL
if [ $1 = "" ]; then
	echo "Please include printer model as your argument"
	echo "Usage: sudo ./$script_name <printer_model>"
	exit 1
fi

# check to see if a valid printer model has been input at the command line
# if a proper printer is selected then assign printer variable a value
if [ $1 = "2600n" ]; then
	printer=$1
elif [ $1 = "1600" ]; then
	printer=$1	
elif [ $1 = "2530" ]; then
	printer=$1
elif [ $1 = "2490" ]; then
	printer=$1
elif [ $1 = "2480" ]; then
	printer=$1
elif [ $1 = "6115" ]; then
	printer=$1
elif [ $1 = "2430" ]; then
	printer=$1
elif [ $1 = "2300" ]; then
	printer=$1
elif [ $1 = "2200" ]; then
	printer=$1
elif [ $1 = "cpwl" ]; then
	printer=$1
elif [ $1 = "300" ]; then
	printer=$1
elif [ $1 = "600" ]; then
	printer=$1
elif [ $1 = "2160" ]; then
	printer=$1
elif [ $1 = "3160" ]; then
	printer=$1
elif [ $1 = "3200" ]; then
	printer=$1
elif [ $1 = "3300" ]; then
	printer=$1		
elif [ $1 = "3400" ]; then
	printer=$1	
elif [ $1 = "5100" ]; then
	printer=$1	
elif [ $1 = "5200" ]; then
	printer=$1	
elif [ $1 = "5500" ]; then
	printer=$1	
elif [ $1 = "5600" ]; then
	printer=$1	
elif [ $1 = "5800" ]; then
	printer=$1	
elif [ $1 = "6110" ]; then
	printer=$1
elif [ $1 = "500" ]; then
	printer=$1	
elif [ $1 = "1020" ]; then
	printer=$1
elif [ $1 = "1018" ]; then
	printer=$1
elif [ $1 = "1005" ]; then
	printer=$1
elif [ $1 = "1000" ]; then
	printer=$1
elif [ $1 = "P1005" ]; then
	printer=$1
elif [ $1 = "P1006" ]; then
	printer=$1
elif [ $1 = "P1505" ]; then
	printer=$1
else	
	echo "Invalid printer model number"
	exit 1
fi

# since we will be using make to make the driver we need to be sure that build-essential is installed for gcc
# if build-essential is installed this command will be bypassed
sudo apt-get -y install build-essential

# change to the users home folder
cd ~

# get the driver from http://www.stchman.com/
wget http://www.stchman.com/tools/foo2zjs/foo2zjs.tar.gz

# unpack the archive
tar zxf foo2zjs.tar.gz

# change to the newly created folder the archive creates.
cd foo2zjs

# Make sure that any previous foo2zjs drivers are uninstalled
sudo make uninstall

# compile the driver
make

#  get the firmware or .ICM file(s)
# ./getweb 2600n  	# Get HP Color LaserJet 2600n .ICM files
# ./getweb 1600	        # Get HP Color LaserJet 1600 .ICM files

# ./getweb 2530	        # Get Konica Minolta magicolor 2530 DL .ICM files
# ./getweb 2490	        # Get Konica Minolta magicolor 2490 MF .ICM files
# ./getweb 2480	        # Get Konica Minolta magicolor 2480 MF .ICM files
# ./getweb 6115	        # Get Xerox Phaser 6115MFP .ICM files

# ./getweb 2430	        # Get Konica Minolta magicolor 2430 DL .ICM files
# ./getweb 2300	        # Get Minolta/QMS magicolor 2300 DL .ICM files
# ./getweb 2200	        # Get Minolta/QMS magicolor 2200 DL .ICM files
# ./getweb cpwl	        # Get Minolta Color PageWorks/Pro L .ICM files

# ./getweb 300          # Get Samsung CLP-300 .ICM files
# ./getweb 600          # Get Samsung CLP-600 .ICM files
# ./getweb 2160         # Get Samsung CLX-2160 .ICM files
# ./getweb 3160         # Get Samsung CLX-3160 .ICM files

# ./getweb 3200	        # Get Oki C3200n .ICM files
# ./getweb 3300	        # Get Oki C3300n .ICM files
# ./getweb 3400	        # Get Oki C3400n .ICM files
# ./getweb 5100	        # Get Oki C5100n .ICM files
# ./getweb 5200	        # Get Oki C5200n .ICM files
# ./getweb 5500	        # Get Oki C5500n .ICM files
# ./getweb 5600	        # Get Oki C5600n .ICM files
# ./getweb 5800	        # Get Oki C5800n .ICM files

# ./getweb 6110         # Get Xerox Phaser 6110 and 6110MFP .ICM files

# ./getweb 500          # Get Lexmark C500 .ICM files

# ./getweb 1020	        # Get HP LaserJet 1020 firmware file
# ./getweb 1018	        # Get HP LaserJet 1018 firmware file
# ./getweb 1005	        # Get HP LaserJet 1005 firmware file
# ./getweb 1000	        # Get HP LaserJet 1000 firmware file

# ./getweb P1005	    # Get HP LaserJet P1005 firmware file
# ./getweb P1006	    # Get HP LaserJet P1006 firmware file
# ./getweb P1505	    # Get HP LaserJet P1505 firmware file

# get proper files for the printer gotten at command line
./getweb $printer

# Install driver, foomatic XML files, and extra files:
sudo make install

# (Optional) Configure hotplug (USB; HP LJ 1000/1005/1018/1020):
sudo make install-hotplug

# (Optional) If you use CUPS, restart the spooler:
sudo make cups

# Start gnome-cups-manager to select the printer
sudo gnome-cups-manager

sudo make cups

# remove the archive and the folder it created as it is no longer needed
# remove archive
rm -f ~/foo2zjs.tar.gz

# remove the folder the archive created
rm -r -f ~/foo2zjs

# Your printer should be installed!!!

