Configuring a Linux PC as a Timecapsule
and AirPrint Server

(c) Brian Reay
25/7/13
For Kent Linux User Group

Introduction


These notes outline how to configure a Linux (Ubuntu in particular) machine as a Timecapsule for one or more MacOS machines and as an AirPrint Server for iOS devices.


Timecapsule

Basic starting point: PC with Linux installed. I used Ubuntu 12.04 LTS but the scheme should work for similar distributions.  I would recommend two hard disks, one with the root and swap partition and the home partion on the second drive. This will allow the backup data to survive if you need to rebuild the main disk. I used a 160G disk for root + swap as that was to hand but 40GB would be more than enough and a 2TB disk for /home.


First the  some network protocols (includes avahi,  also required for the Airprint Server)

Install netatalk

Install avahi

Both are available in the Ubuntu Software Centre but you can use:


sudo apt-get install netatalk

sudo apt-get install avahi-daemon

You need to edit some of the configuration files:

Firstly, with your preferred text editor and root priviliges (eg sudo gedit):

To the end of:  /etc/netatalk/afpd.conf

Add:

- -tcp -noddp -uamlist uam_guest.so,uams_dhx2_passwd.so -nosavepassword

Save and exit.

Next we need to set up the locations for saving the backups.

I used a common user name (timemachine) and "he" has directories in his home area for each machine. Use the normal procedure to create the timemachine account and the directories. Of course, you may prefer seperate accounts, just adjust the lines below.


The file to edit is: /etc/netatalk/AppleVolumes.default

Using your preferred text editor:

1.  Comment out the line:  ~/            "Home Directory"
2. Add lines to describe the backups you wish to provide.

Some examples:

/home/brian/TimeMachine "TM on Ubuntu"  cnidscheme:dbd options:usedots,upriv,tm  allow:brian

This will allow brian to backup to a directory called TimeMachine in his home area. On his Mac it will appear as TM on Ubuntu.


/home/john/MacBook "John's MB_TM"    cnidscheme:dbd options:usedots,upriv,tm  allow:john
/home/john/Mini    "John's Mini_TM"  cnidscheme:dbd options:usedots,upriv,tm  allow:john
/home/lizzie/MacBook "Liz's MB_TM"   cnidscheme:dbd options:usedots,upriv,tm  allow:lizzie

These provide backups for three machines across two users. Each machine's backup has its own directory.

The services will be "seen" in the Time Machine window by labels shown.

In each case, the Linux user name and password will be required when selecting the "disk" from Timemachine.

After checking the above lines, save the file. Take care, a "slip" in the paths (including creating the directories) can cause annoying (OSStatus Error 2)  problems when you get to the Mac stage (been there, done that, got the teeshirt).


If you run a fire wall on your machine, then you will need to allow the traffic through. For "Shorewall" you need to add:

ACCEPT net fw tcp 548    to the rules file and restart Shorewall.
 
For other firewalls, you will need to do the equivalent.

Next, either reboot or restart netatalk with: sudo service netatalk restart

That should be the Linux side complete.

Next, you need a Mac.

Select Timemachine (in Settings) and  add back up disk. You should see a list of the available disks (in the example above John's MB_TM, John's Mini_TM, Liz's MB_TM .  Select the one appropriate to your machine and enter the Linux user name and password. All being well, the disk should connect and the first back up initiate. Be warned, the first backup takes sometime (a couple of hours typically on the three Macs here). Don't worry, subsequent backups happen without you noticing.


Note: If you get an OSStatus Error 2, suspect a path error in your AppleVolume.default file, a missing directory, a 'permissions' problem etc. Fix these and try again. Don't forget to restart services (or reboot) after changing config files.



Airprint Server

You need a PC with Linux, I've assumed Ubuntu, and avahi installed (see above). Also your printers should be installed and verified as working and I've assumed you have CUPS installed. I don't recall seeing a Linux machine without CUPS, other than a R Pi, for some time.  You need not get involved with CUPS, I can let you have a working cupsd.conf file if you prefer.

If you want to edit the cupsd.conf file, the essential changes to the /etc/cups/cupsd.conf file are:
(keep a copy of the old file just in case, cups config files can be a pain.)

Listen 631
Browsing on
BrowseOrder allow,deny
BrowseAllow all
BrowseLocalProtocols CUPS dnssd
BrowseAddress @LOCAL
ServerAlias *

I'm happy to let you have a copy of my working file, just copy it to the right place.

Restart cups or reboot after all the changes.

Avahi needs some "helper" files so it can advertise the printers on the network. You can generate these by hand but someone has kindly generated a tool to do the job for you.


https://github.com/tjfontaine/airprint-generate

The tool generates a script for each printer.  Place the script(s) in /etc/avahi/services .

Either restart avahi with:

/etc/init.d/avahi-daemon restart

or reboot

(I tend to make all the changes and do a reboot- some people don't like this but each to there own...)

If you now look for a printer on an iOS device (iPad/iPhone), which is on the same network, you should "see" your printers- even the ones which are not really Airprinters. If any appear twice, then you've got a naming inconsistancy, ie you've  called the printer different names in different places- avahi will "advertise" both.