#!/bin/bash gem_path="" ruby_path="" module_to_import="" function usage { retval="$1" case "$retval" in 0) ;; *) exec 1>&2 ;; esac echo "Usage: $0" echo " --gem-path /where/gem/lives/gem" echo " --ruby-path /where/ruby/lives/ruby" echo " --module-to-import module_name" echo " --gem-package gem-package-name" echo echo This program installs a ruby package , but only if module_name echo is not yet require\'able. echo echo This cuts down on unnecessary sudoing. exit "$retval" } while [ "$#" -ge 2 ] do case "$1" in --gem-path) gem_path="$2" shift ;; --ruby-path) ruby_path="$2" shift ;; --module-to-import) module_to_import="$2" shift ;; --gem-package) gem_package="$2" shift ;; -h|--help) usage 0 ;; *) echo "$0: Unrecognized option: $1" 1>&2 usage 1 ;; esac shift done case "$gem_path" in "") echo --gem-path is a required option 1>&2 usage 1 ;; esac case "$ruby_path" in "") echo --ruby-path is a required option 1>&2 usage 1 ;; esac case "$module_to_import" in "") echo --module-to-import is a required option 1>&2 usage 1 ;; esac case "$gem_package" in "") echo --gem-package is a required option 1>&2 usage 1 ;; esac if "$ruby_path" -e 'require "'"$module_to_import"'"' > /dev/null 2>&1 then : else sudo "$gem_path" install "$gem_package" fi