Avery Magnotti Avery Magnotti - 5 months ago 9x
Linux Question

Automating package compile process using GitHub API

So, I'd like to create a shell script that automates the process of downloading a package, unzipping it, cd'ing into it, configuring it, and compiling it from source.

I have started with a simple script below:

curl https://api.github.com/repos/$PROJ/$PROJ/tags -o $PROJ.json
cat $PROJ.json | grep -Po '(?<="name": ")[^"]*'

This fetches the JSON file for the Ruby project, and returns the latest(?) tag name (e.g. ruby_2_3_1).

However, I am dumb, and I'd like to expand more on this script. I would like to:

  • ignore any tags that don't include the word "ruby"

  • only fetch the latest tag (in this example, 2_3_1)

  • fetch the URL for tag 2_3_1 and download a tarball of the source code from that tag

  • unzip the tarball (unless it detects that this tarball has been unzipped before)

The rest I can do on my own, as I'm fairly familiar with ./configure, make, make install, etc.

Hopefully this isn't too difficult. I'd prefer not to use jq (just standard regex), but if it happens to be easier with jq, I'll be fine either way.


At https://api.github.com/repos/ruby/ruby/tags I dont'see the word ruby in any tags name.

The tags are sorted by name in reverse order (the same as a sort -nr)

You can download and extract the latest tag ruby tarball by:

LAST_URL=`cat ruby.json | grep -Po '(?<="tarball_url": ")[^"]* | egrep -v [a-z]$ | head -1'
wget $LAST_URL && tar -xvzf `basename $LAST_URL`

Some notes:

  • egrep -v [a-z]$ filters out non ruby packages, not finishing in a number (es. yarv_migration_base)
  • head -1 takes the first tag (in the form vX_X_X) in a reverse order, the most recent