Project: Automated offsite backups for an NSLU2 – part 8

I’ve discovered that in order to get automated offsite backups from my NSLU2 to Amazon S3, I have to get it to run Ruby so that it can run s3sync. Installing Ruby required the slug’s firmware to be upgraded to a new version of Linux, called Unslung, so I did that – and I also installed s3sync on a Ubuntu machine as a dry run. Both of these worked out OK, so the next step was to get the Ruby language itself running under the Unslung firmware – and importantly, to make sure that Ruby had the OpenSSL package installed; the latter had proven non-obvious under regular Linux, so I was expecting problems on Unslung, which is, after all, a cut-down version of the operating system.

The first thing was to work out how to install new packages on an Unslung system in the first place. The last section of the installation README gives a link to this page, which is a good starting point. Going from the instructions there, I made sure that the gateway and DNS server were correctly set up on the slug’s web admin pages, then ran ipkg update from a telnet window logged into the unslung slug. This seemed to work just fine – appropriate messages about downloading, inflating and updating things went by. The next recommended steps were to run ipkg install unslung-feeds, and then ipkg update again. I’m sure there is a very good reason for this, but I’ve no idea what it is – for now, I just followed the instructions, bleating occasionally. Nothing obviously bad happened, and it looked like it managed to install some further lists of software.

The next step was to run ipkg list to see what I could now install. And wow, there were a lot of packages. Most importantly for this project, there was the ruby one, so…

Hmmm. So, how to find out where it’s been installed? Well, ipkg --help is apparently an unrecognised option, but when I tried it, it forced a printout of the options for ipkg anyway. This made it clear that I should run ipkg files ruby to find out where everything was, and from there I found out that it had installed the binary in /opt/bin/ – which is not unreasonable.

# /opt/bin/ruby --version
ruby 1.8.5 (2006-08-25) [armv5b-linux]

Looking good! Come to thing of it, that’s a more recent version of Ruby than the default for Ubuntu Linux :-)

Now, as I said earlier in this post, one worry I had was the difficulty of installing the Ruby OpenSSL libraries, which are a requirement for s3sync. I had noticed something relevant-looking as the list of files for the package went past earlier, so decided to double-check:

This was pretty promising – not a sure thing, but it looked good. So how to be sure – or, at least reasonably sure – that nothing was missing? Well, going back to the error message I got when s3sync failed on my Ubuntu machine (which, at the time, lacked an OpenSSL library for Ruby) I noted that I’d had the error

./S3.rb:25:in `require': no such file to load -- openssl (LoadError)

So, it sounded to me like the “require” command in Ruby loads libraries – perhaps somewhat like import in Python or Java, or using in C#. A quick grep through the s3sync source seemed to confirm this – the first few non-comment lines of S3.rb ran:

require 'base64'
require 'cgi'

…and then, shortly after, there was:

require 'openssl'

So, I could reasonably comfortably posit that if a Ruby script containing just that last line would run happily on the slug, s3sync should be able to run. On that basis, I created such a file and ran it:

Now, from this I suspected that the Ruby system had its own SSL stuff installed, and it was just the operating system’s shared library that was missing. In retrospect, this was not obvious – after all, the file that was missing was in /opt/lib/ruby. But, without noticing that, I decided to try installing any non-Ruby OpenSSL package that was out there:

Which looked perfect. Perhaps someone can tell me how that all worked… or perhaps I’ll work it out myself later. But for now, onward! The next step was clearly to copy over s3sync, and to try it out on a simple directory. And that’s one for tomorrow.