#!/bin/bash CONTEXT="$1"; shift RUBYVERSION="$1"; shift if [ "$CONTEXT" = "" ]; then echo " Internal error: /opt context is not set" >&2 exit 4 fi if [ "$RUBYVERSION" = "" ]; then echo " Internal error: Ruby version is not set" >&2 exit 4 fi SYS_MNT_NS="$(sudo readlink /proc/1/ns/mnt)" MY_MNT_NS="$(readlink /proc/self/ns/mnt)" if [ "$SYS_MNT_NS" = "$MY_MNT_NS" ]; then echo " Internal error: Wrong MNT namespace" >&2 exit 4 fi mount --bind /srv/share/nfs/opt/"$CONTEXT" /opt source /usr/local/share/chruby/chruby.sh chruby "$RUBYVERSION" && runuser -u nobody -g "$CONTEXT" $@ RC="$?" umount -l /opt exit $RC