Script to become another user.
authorIain Patterson <me@iain.cx>
Thu, 16 Jul 2009 09:55:55 +0000 (10:55 +0100)
committerIain Patterson <me@iain.cx>
Tue, 4 Aug 2009 16:30:53 +0000 (17:30 +0100)
Set per-user initialisation in ~/.become/<user>.

.become/all [new file with mode: 0644]
opt/bin/become [new file with mode: 0755]

diff --git a/.become/all b/.become/all
new file mode 100644 (file)
index 0000000..5138a15
--- /dev/null
@@ -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 (executable)
index 0000000..abe1b85
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+user="$1"
+if [ -z "$user" ]; then
+  echo >&2 "Usage: become <user>"
+  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"