From: Iain Patterson Date: Thu, 16 Jul 2009 09:55:55 +0000 (+0100) Subject: Script to become another user. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=5bee6828943e63f747c510d201d0dc1b44fcd7e1;p=profile.git Script to become another user. Set per-user initialisation in ~/.become/. --- diff --git a/.become/all b/.become/all new file mode 100644 index 0000000..5138a15 --- /dev/null +++ b/.become/all @@ -0,0 +1,11 @@ +cd +export TERMINFO=$BECOME_HOME/.terminfo +. $BECOME_HOME/.profile.d/ps1.bashrc +__ps1 +vim=$($BECOME_HOME/opt/bin/find_working vim 2>/dev/null) +if [ -n "$vim" ]; then + alias vim="$vim --cmd ':se rtp=$BECOME_HOME/.vim' -u $BECOME_HOME/.vimrc" + alias vi=vim +fi +unset vim +set -o vi diff --git a/opt/bin/become b/opt/bin/become new file mode 100755 index 0000000..abe1b85 --- /dev/null +++ b/opt/bin/become @@ -0,0 +1,13 @@ +#!/bin/bash + +user="$1" +if [ -z "$user" ]; then + echo >&2 "Usage: become " + exit 1 +fi + +BECOME="$HOME/.become" +profile="$BECOME/$user" +[ -f "$profile" ] || profile="$BECOME/all" + +exec sudo -H -u "$user" env BECOME_HOME="$HOME" /bin/bash --rcfile "$profile"