Streamlined Rails Gem Updates on Gem in a Box

Problem: Per recent Ruby on Rails security patches, you need to update your Rails applications. However, because you host Rails and its related gems on a private Gem in a Box gem server, it’s a bit cumbersome to manually download the necessary gems from Rubygems.org, and then upload them to your Gem in a Box gem server.

Solution: bash and curl.

1. List the necessary gems in a gems.txt file:

rails
actionmailer
activemodel
actionview
actionpack
activerecord
activeresource
activesupport
railties

2. Create a bash script in a get_gems.sh file to retrieve the gems from Rubygems.org. Note that I’ve created a VERSION variable specifying the desired gems’ version.

#!/bin/bash

VERSION=4.1.8

for ARG in `cat $1`; do
  curl -L "http://rubygems.org/downloads/$ARG-$VERSION.gem" > "$ARG-$VERSION.gem"
done

3. Create a bash script in a post_gems.sh file to post the downloaded gems to your Gem in a Box. Note that I’ve created a VERSION variable specifying the desired gems’ version here too.

#!/bin/bash

VERSION=4.1.8

for ARG in `cat $1`; do
  curl -v -X POST -F file=@$ARG-$VERSION.gem http://YOUR_GEM_IN_A_BOX_USERNAME:YOUR_PASSWORD@YOUR_GEM_IN_A_BOX.com/upload
done

Usage

Download gems:

./get_gems.sh gems.txt

Upload gems:

./post_gems.sh gems.txt