#!/bin/bash CONTEXT="$1"; shift ARGS=($@) if [ "$CONTEXT" = "-c" ]; then ARGS_ALL=($@) CONTEXT="${ARGS_ALL[0]}" ARGS=(${ARGS_ALL[@]:1}) fi RUBYVERSION="${ARGS[0]}" CMD="${ARGS[1]}" ARGS=(${ARGS[@]:2}) if [ "$CONTEXT" = "" ]; then echo " Error: /opt context is not set" >&2 exit 2 fi if [ "$RUBYVERSION" = "" ]; then echo " Error: Ruby version is not set" >&2 exit 2 fi run() { exec sudo context-chruby-run "$CONTEXT" "$RUBYVERSION" gem $@ } forbidden() { echo ' This command is forbidden' >&2 exit 1 } help() { gem help $@ | sed -e 's/ gem/ srv0-gem/g' exit 0 } cmd_proc() { case "$CMD" in install) run install $@ ;; list) run list $@ ;; env) run env $@ ;; build) forbidden $@ ;; server) forbidden $@ ;; help) help $@ ;; "") help $@ ;; *) #exec gem help echo " Unknown or forbidden command $CMD" >&2 exit 1 ;; esac } cmd_proc $ARGS