From dafa4337882586fc9a4397ce9255b9611ec6c8b7 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 10 Jan 2019 16:19:48 +1100 Subject: [PATCH] Add script to install required bundler version The newest version of bundler is not compatible with our current version of Ruby. This script helps to install the bundler version defined in Gemfile.lock. --- script/install-bundler | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 script/install-bundler diff --git a/script/install-bundler b/script/install-bundler new file mode 100755 index 0000000000..a5c994c311 --- /dev/null +++ b/script/install-bundler @@ -0,0 +1,42 @@ +#!/bin/sh + +# This shell script looks for the last used Bundler version in Gemfile.lock and +# installs exactly that version, removing all other versions. + +# Command line arguments are passed on to `gem install`. So you can call this +# script with with arguments: +# +# ./script/install-bundler --no-ri --no-rdoc + +# This script is used by ofn-install and can by handy in your development +# environment. + +# Fail if a single command fails. +set -e + +# `grep -m 1`: find the first occurrence of "BUNDLED WITH" +# `-A`: print the next line after "BUNDLED WITH" as well +# `-x -F`: find exactly that string without interpreting regex +# `tail -n 1`: take the last line, the version line +# `tr -d`: delete all spaces, the indent before the version +version="$(grep -m 1 -A 1 -x -F "BUNDLED WITH" Gemfile.lock | tail -n 1 | tr -d '[:space:]')" + +# if the length of $version is zero +if [ -z "$version" ]; then + echo >&2 "No bundler version in Gemfile.lock." + exit 1 +fi + +# Get the currently used bundler version. +# We ignore all errors with `2>/dev/null || true` in case there is no bundler +# or only an orphaned shim installed. +current="$(bundler --version 2>/dev/null || true)" + +if [ "$current" = "Bundler version $version" ]; then + echo >&2 "Already up-to-date: $current" + exit 0 +fi + +# Passing on all arguments of this script with "$@". +gem install bundler -v "$version" "$@" +gem uninstall bundler -v "!= $version" 2>/dev/null || true