Difference between revisions of "Add Printers Via Network Script"

From ubermix Wiki
Jump to: navigation, search
Line 40: Line 40:
  
 
  lpadmin -p ReplaceWithPrinterName -v socket://put-IP-address-here:9100 -m put-driver-.ppd-file-here -L "Put the location here" -E
 
  lpadmin -p ReplaceWithPrinterName -v socket://put-IP-address-here:9100 -m put-driver-.ppd-file-here -L "Put the location here" -E
 +
 +
Now once you have a correct line of code for each printer you can edit the script below to install a different printer to each set of computers. Edit the lines that say
 +
if grep CES-A2 /etc/hostname
 +
replacing "CES-A2" with the stem of the name for computers that all share the same printer. Replace the lpadmin line below that if statement wit the lpadmin line for your printer name, IP address, and driver. Change the lpadmin -d line to the same name as the printer you installed (this sets the printer as the default).
 +
Repeat this step for each room of computers. The following lines start with the word elif instead of if. If you need to add more room options just copy more blocks of 4 lines (elif, then, lpadmin -p, lpadmin -d).
 +
 +
The first if statement and the line near the end that start with "sudo echo" just make sure that each computer only runs this update once. If a computer is restored it will run the script and install the correct printer.
  
 
  #!/bin/bash
 
  #!/bin/bash
  if [ ! -e /etc/cups/updated2.txt ]
+
  if [ ! -e /etc/cups/updated.txt ]
 
  then
 
  then
 
  if grep CES-A2 /etc/hostname
 
  if grep CES-A2 /etc/hostname
Line 57: Line 64:
 
  lpadmin -d RoomD8
 
  lpadmin -d RoomD8
 
  fi
 
  fi
  sudo echo > /etc/cups/updated2.txt
+
  sudo echo > /etc/cups/updated.txt
 
  fi
 
  fi

Revision as of 20:08, 5 February 2013

If you have set up your ubermix computers to run the .network-autostart script and look for an update.sh when they boot up, you can do updates and customization. One option is to have the correct printer pushed out to a computer based on its hostname.

Prerequisites:

  • Network-autostart file set up on your image
  • Computers are named with some convention based on location. This can be set after imaging, by choosing Advanced Options (5) and then Set device hostname (5). For example the convention, SCHOOLABBREVIATION-ROOM-COMPUTERNUMBER, would have computers named CES-A2-01 for a computer at Central Elementary School in Room A2.

First determine the correct printer driver

Open a terminal (ctrl-alt-t) and type

lpinfo --make-and-model 'Part of your printer model name here' -m

For example

lpinfo --make-and-model '1022n' -m 

Will find the drivers for the HP Laserjet 1022n You will see a long list of text for multiple drivers, but the top one is the recommended driver

foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd HP LaserJet 1022n Foomatic/foo2zjs-z1 (recommended)
drv:///hpijs.drv/hp-laserjet_1022n-hpijs-pcl3.ppd HP LaserJet 1022n hpijs pcl3, 3.12.6, requires proprietary plugin
drv:///hpijs.drv/hp-laserjet_1022n-hpijs-zjs.ppd HP LaserJet 1022n hpijs zjs, 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022n-pcl3.ppd HP LaserJet 1022n pcl3, hpcups 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022n-zjs.ppd HP LaserJet 1022n zjs, hpcups 3.12.6, requires proprietary plugin
foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022nw.ppd HP LaserJet 1022nw Foomatic/foo2zjs-z1 (recommended)
drv:///hpijs.drv/hp-laserjet_1022nw-hpijs-pcl3.ppd HP LaserJet 1022nw hpijs pcl3, 3.12.6, requires proprietary plugin
drv:///hpijs.drv/hp-laserjet_1022nw-hpijs-zjs.ppd HP LaserJet 1022nw hpijs zjs, 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022nw-pcl3.ppd HP LaserJet 1022nw pcl3, hpcups 3.12.6, requires proprietary plugin
drv:///hpcups.drv/hp-laserjet_1022nw-zjs.ppd HP LaserJet 1022nw zjs, hpcups 3.12.6, requires proprietary plugin

You then copy the first bit of text all the way to .ppd In the laserjet example you would copy the following text and paste it in a text file for later foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd

Second determine your printer ip address

Usually printers are set up with static IP addresses. If so you can ask your IT team for a list of IP addresses for printers. Also most printers will print out their configuration or have a display that will show the configuration. Printer IP addresses will be a series of 4 numbers separated by periods. For example, 10.6.64.103 Once you have the IP address you are ready to push out printers over the network

Edit the script

Here is the basic script that you can change with your site information. The terminal command that will add a printer looks like this:

lpadmin -p RoomA2 -v socket://10.6.64.103:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd -L "Room A2" -E

Replace 4 pieces of information as shown below.

lpadmin -p ReplaceWithPrinterName -v socket://put-IP-address-here:9100 -m put-driver-.ppd-file-here -L "Put the location here" -E

Now once you have a correct line of code for each printer you can edit the script below to install a different printer to each set of computers. Edit the lines that say

if grep CES-A2 /etc/hostname

replacing "CES-A2" with the stem of the name for computers that all share the same printer. Replace the lpadmin line below that if statement wit the lpadmin line for your printer name, IP address, and driver. Change the lpadmin -d line to the same name as the printer you installed (this sets the printer as the default). Repeat this step for each room of computers. The following lines start with the word elif instead of if. If you need to add more room options just copy more blocks of 4 lines (elif, then, lpadmin -p, lpadmin -d).

The first if statement and the line near the end that start with "sudo echo" just make sure that each computer only runs this update once. If a computer is restored it will run the script and install the correct printer.

#!/bin/bash
if [ ! -e /etc/cups/updated.txt ]
	then
	if grep CES-A2 /etc/hostname
	then
		lpadmin -p RoomA2 -v socket://10.6.64.103:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd -L "Room A2" -E
		lpadmin -d RoomA2
	elif grep CMS-D1 /etc/hostname
	then
		lpadmin -p RoomD1 -v socket://10.6.64.106:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_1022n.ppd -L "Room D1" -E
		lpadmin -d RoomD1
	elif grep CMS-D8 /etc/hostname
	then
		lpadmin -p RoomD8 -v socket://10.6.64.102:9100 -m foo2zjs:0/ppd/foo2zjs/HP-LaserJet_Pro_P1606dn.ppd -L "Room D8" -E
		lpadmin -d RoomD8
	fi
	sudo echo > /etc/cups/updated.txt
fi