Turn your Raspberry Pi into a Print Server foWindows, Linux, Mac and iOS AirPrint - BASH Script to do it automatically too..
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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):
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):
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):
#!/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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.