LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Linux Answers > Hardware
User Name
Password

Notices


By elliotjreed at 2013-07-10 06:22
[b][u]bPrint Server for the Raspberry Pi (with iOS 6 AirPrint Support)[u][b]

Installing the Required Packages

So you have a Raspberry Pi, you have finished looking at it, and nobody's tried to eat it yet. Now you're wondering what to do with it that may be useful. Well, in my house there's three of us all using different operating systems (Linux, Windows and iOS 6) and one HP LaserJet (the only printer we've not yet managed to break). Cue the Raspberry Pi - it's plugged into the printer and acts as a print server, and also allows us to print from iPhones and iPads. Here's how you do it if you want to do the same.

Generally one should normally just use a 'sudo' command for anything that needs to be run as root, however for this is does make it a lot easier to run 'sudo su'.

So first run a terminal as root:
Code:
sudo su
Download and install the required packages (the '-r' ust means that it will install all the recommended packages too):
Code:
aptitude -r install avahi-daemon avahi-discover libnss-mdns cups cups-pdf python-cups samba samba-common-bin tdb-tools
Then add yourself, your username, to the CUPS (Common Unix Printing System) admin. In this example the username 'pi' is used, like on the Raspberry Pi. Add it by using the following command:
Code:
usermod -aG lpadmin pi
Now back-up your CUPS configuration file (just in case, plus it's always good practice too):
Code:
cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.backup
Enable remote access to the CUPS magagement console:
Code:
cupsctl --share-printers --remote-printers --remote-admin
Now you need to replace the line 'localhost:631' with 'Port 631' in the cupsd.conf file. The easiest way to do this via the terminal is using 'sed (just saves opening up Nano and messing about there):
Code:
sed -i 's/Listen localhost:631/Port 631/g' /etc/cups/cupsd.conf
Setup AirPrint Support - for iPads, iPhones, etc.
To get the print server to work with Apple's AirPint service (to print from your iPhone or iPad), first:
Code:
cd /opt
mkdir airprint
cd airprint
Then download the AirPrint Python file (generates the required services):
Code:
wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
Make the python script you've just downloaded excecutable (otherwise it won't run):
Code:
chmod 755 airprint-generate.py
Next we need to change a couple of bits to make it work with iOS 6:
Code:
echo 'image/urf application/pdf 100 pdftoraster' > /usr/share/cups/mime/airprint.convs
echo 'image/urf urf string(0,UNIRAST<00>)' > /usr/share/cups/mime/airprint.types
Now run the following to add it to the services (so it starts when you startup your computer):
Code:
python airprint-generate.py -d /etc/avahi/services/
Then just restart the CUPS and Avahi daemons:
Code:
service cups start
service avahi-daemon start
Adding a Printer via CUPS
Now open up a web browser, such as Firefox, or Midori on the Raspberry Pi, and go to: https://localhost:631/

Here you can add a printer..........

BASH Script to install a Raspberry Pi Print-Server Automatically

To do the above automatically using a BASH script, do the following (assumed your username is 'pi':

Copy the code below (the /bin/bash code) and paste it into a file name printserver.sh, then:

Code:
sudo chmod 755 /home/pi/printserver.sh && sudo /home/pi/printserver.sh
The BASH script contains the following:

Code:
#!/bin/bash

# Change the following word 'pi' to your own username if it's not 'pi'
YOURUSERNAME="pi"

YELLOW="\033[1;33m"
RED="\033[0;31m"
BLUE="\033[1;34m"
ENDCOLOR="\033[0m"

if [ $USER != root ]; then
  echo -e $RED"Error: you need to be root! Use 'sudo'..."
  echo -e $YELLOW"Exiting..."$ENDCOLOR
  exit 0
fi

echo -e $YELLOW"Updating and upgrading packages:"$ENDCOLOR
aptitude update
aptitude -r full-upgrade -y

echo -e $YELLOW"Installing required packages:"$ENDCOLOR
aptitude -r -y install avahi-daemon avahi-discover libnss-mdns cups cups-pdf python-cups samba samba-common-bin tdb-tools

# Adds the user 'Pi' to the CUPS admin
usermod -aG lpadmin $YOURUSERNAME

# Backup CUPS configuration file
cp /etc/cups/cupsd.conf /etc/cups/cupsd.conf.backup

# Enable remote access to management console
cupsctl --share-printers --remote-printers --remote-admin
sed -i 's/Listen localhost:631/Port 631/g' /etc/cups/cupsd.conf

# To get the print server to work with Apple's AirPint (print from your iPhone or iPad)
cd /opt
mkdir airprint
cd airprint

echo -e $YELLOW"Downloading airprint-generate.py and making it executable:"$ENDCOLOR
wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-gene...

# Makes the Python file excecutable
chmod 755 airprint-generate.py

echo 'image/urf application/pdf 100 pdftoraster' > /usr/share/cups/mime/airprint.convs
echo 'image/urf urf string(0,UNIRAST<00>)' > /usr/share/cups/mime/airprint.types

python airprint-generate.py -d /etc/avahi/services/

echo -e $YELLOW"Starting cups and avahi-daemon:"$ENDCOLOR
service cups start
service avahi-daemon start

echo -e $BLUE"Go to your browser and type in your Raspberry Pi's IP address with the port 631 - eg. https://192.168.0.10:631"$ENDCOLOR


  



All times are GMT -5. The time now is 06:25 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration