Making of a USB giveaway, part two
Tropo’s meetup kits come with USB drives that are loaded with tropo samples, libraries, and applications. This is the second half of a series explaining how we get the software loaded onto those drives.
In the first part, I showed how we’re using git’s distributed source code management and a git feature called submodules to manage the contents of the drives. In this part, I’m going to describe the installer.
We’re an all-Apple company, using MacBooks and OSX as our computing platform of choice. The installer created here is Mac-specific, since it uses some software that’s part of OSX to do some of the magic. You could probably find a way to accomplish all this with Linux or even Windows if you wanted to, but these instructions are for a Mac.
I wanted a system where I could plug a USB drive in, run a single command, and end up with the software loaded, the drive renamed to Tropo, and the drive ejected and ready for the next one. Every extra keystroke, window, or mouse click would make it harder to install and increase the time required.
The installer is in two parts. We have some people who might need to load a drive that don’t use git. Or be on a machine where git isn’t installed. For those instances, we maintain a zip file on our intranet and the first step of the installer is to create the zip.
This zip creation is done in a separate shell script, since I often want to just create a zip.
bundle.shpulls from git to ensure it has the latest copy of the USB pack. Next the script performs a submodule update, initializing any new submodules and recursing in case some of our submodules use submodules themselves.
git submodule --quiet update --init --recursiveThe –quiet flag is on there because the shell scripts print out their own status messages, and I don’t want a bunch of git output cruft pushing that off the screen.
Finally, it creates the zip file, using tar’s
--excludeoption to leave the installer shell scripts and the.gitdirectories out of the zip.
tar --exclude=.git --exclude=bundle.sh --exclude=install.sh -czf ../tropo-usb.tar.gz *The second part of the installer is the install shell script itself.
install.shfirst runsbundle.shto update everything and build the zip file. It uses this zip file to actually build the drives.Next, the installer renames the USB drives to add Tropo branding. Instead of showing “NO NAME” when the drive is plugged in, I want “TROPO” to appear.
![]()
This is done using OSX’s command line Disk Utility. My first attempt was by just renaming the volume in /Volumes/ with the mv command, but this didn’t change the name that showed up in Finder or Windows.
The command is pretty simple, just give the target volume and the new name.
diskutil quiet rename /Volumes/NO NAME TropoThe next step is to copy the contents of the zip file to the drive. I started out by just unzipping straight to the drive, but then later decided that if I wanted to load a handful of drives at once, I could speed things up by only running the the git update and zip file creation process once.
With this in mind, the installer unzips the file that bundle.sh created to a temp directory…
tar -zxf ../tropo-usb.tar.gz -C /tmp/tropo… then calls a function called installme that copies the files over with
cpand then uses diskutil to cleanly eject the drive.
diskutil eject /Volumes/TropoIt then asks the user if they’ve got another drive inserted to load and if so, runs the installme function again.
read -p "Do you have another drive inserted you would like to install to? (y/n):" [ "$REPLY" != "y" ] || installmeWhen the user eventually says “no” to that question, the installer cleans up by deleting the temp directory it created.
If you want to see what bundle.sh and install.sh look like, they’re both in our github account.
Now that you’ve built your drive installer, here’s the steps to install onto a drive. The very first time you do it on a new computer, you’ll need to fetch the pack from git and run
git clone git://github.com/tropo/usb-pack.gitAfter that, all you need to do is..
- Plug a blank USB drive in
./install.sh- Profit!!
If you have a great sample app that you’d like us to include on these drives, send us the git URL for it. Thanks to the magic of submodules, it can be any publicly available git URL. It doesn’t even need to be on github. If we use your app, we’ll send you a tshirt and one of the drives.
Feel free to copy this whole process to create your own USB drives. And if you want one of ours, find someone from Tropo at an event and ask for one. Or put on an event of your own and order one of our meetup kits.
Originally from Voxeo Blogs


Leave a Reply