Arduino Yun and Git

If you’re looking for a quick answer, its that these two just don’t work together. However, the Yun is still a great product that’s well worth using and there are ways to get around some of it’s limitations.

The Yun combines a newer, higher end Arduino microcontroller with a small chip running Linino, a variant of the OpenWRT Linux distro. To that, they’ve added a micro SD card reader, an ethernet port, and a WiFi antenna. This combination lets you easily interface hardware with online API calls. it’d be great to use Git to manage code and other scripts on the Linux distro, but its limited nature makes that difficult.

While Linino is a full Linux system, you’ll find it’s missing a few things if you’re coming from something like Ubuntu or Fedora. While it has programs like SSH and a package manager, they don’t have all the bells and whistles you might be used to. You can use its package manage, opkg, to install Git and other software, but it doesn’t have a huge selection of packages. Many programs, like ssh and wget, aren’t updated to more recent standards.

This all comes to a head if you’re trying to authenticate with GitHub. Git fails to connect via HTTPS because it’s limited to HTTP/1.1 and it can’t connect via SSH because Linino doesn’t have a package for the dev libs of openssh. This is probably solvable by finding all the right tarballs or rolling your own Linino image. However, I wanted to see what was possible with the stock image and the built-in package manager.

While I’ve written some code directly on the Yun using ssh and vi, it’s not a great development environment. So as long as I’m writing code on a different machine, I don’t actually need to commit to git on the Yun. As long as I can pull code down, I’m in good shape. Lucky for us, GitHub lets you download a zip archive of a branch without authenticating. So that will be our route in to get the latest code.

So, we need to remove the old code, download the archive, unzip it, and move the files to the expected location. Linino does throw a few roadblocks in our path, though. The first one is that its wget can’t handle HTTPS. Luckily, its version of curl does, so we can just curl the URL and pipe the output to a file. Now, I know I just said that curl can handle HTTPS, but that’s not entirely true. It can’t validate GitHub’s SSL certificate. So you’ll have to pass a couple of additional arguments, namely “-l -k”. Right now, the URL for an archive is https://codeload.github.com/myusername/myprojectname/zip/branchname. You can plug your own values into that URL, but keep in mind that GitHub might change the URL format at anytime. So if this suddenly stops working for you, checking this is a good place to start. So now you can grab the archive, but now you have to unzip it.

The Yun doesn’t come with unzip installed by default (or curl, for that matter). Luckily, there’s a package that you can easily install. Just run opkg install unzip and you’re good to go.

So, to put this all together, we need two things. The first is a script to install the necessary software and the second is a script to actually download the code. First, the install script:

opkg update
opkg install curl
opkg install unzip

Secondly, the actual update script:

#!/bin/sh
rm -rf myprojectname
curl -l -k https://codeload.github.com/myusername/myprojectname/zip/master > archive.zip
unzip archive.zip -d .
mv myprojectname-master myprojectname
rm -f archive.zip

And there you’ve got it. Now you can use GitHub for source control and keep your Yun up-to-date with the latest versions of your scripts for whatever cool project you’re working on.

Advertisements

2 thoughts on “Arduino Yun and Git

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s