Created
June 7, 2013 04:53
-
-
Save zph/5727135 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Make pair user and add them to the pair group on box | |
### sudo adduser --disabled-password pair | |
# Add yourself to pair group on box | |
### sudo usermod -a -G pair zander | |
# Setup pair user with the following /home/pair/.bash_profile | |
### /home/pair/.bash_profile | |
##### https://gist.github.com/5726432 | |
##### tmux -S /tmp/pair attach | |
PAIR="$1" | |
if [[ -d "/home" ]]; then | |
base_dir="home"; #b/c Linux is more important && standard | |
else | |
base_dir="Users"; # b/c we also use OSX | |
fi | |
setup_pair_user(){ | |
sudo adduser --disabled-password pair | |
} | |
add_self_to_pair_group(){ | |
sudo usermod -a -G pair `whoami` | |
} | |
setup_pair_bash_profile(){ | |
sudo -c bash "echo 'tmux -S /tmp/pair attach' > /$base_dir/pair/.bash_profile" | |
} | |
setup_pair_user_full(){ | |
add_self_to_pair_group | |
setup_pair_user | |
setup_pair_bash_profile | |
} | |
tmux_session(){ | |
# Gather github pub key and add it to pair's authkey | |
sudo bash -c "curl https://github.com/$PAIR.keys > /$base_dir/pair/.ssh/authorized_keys" | |
# Set permissions on authorized_keys | |
sudo chown pair:pair /Users/pair/.ssh/authorized_keys | |
# Setup tmux pipe, change group permissions on pipe, and join tmux | |
tmux -S /tmp/pair new -ds pair && \ | |
chgrp pair /tmp/pair && \ | |
tmux -S /tmp/pair attach -t pair | |
# After Tmux session ends, empty the pair's authorized_keys | |
sudo bash -c "echo '' > /$base_dir/pair/.ssh/authorized_keys" | |
# Kick pair from server | |
sudo pkill -9 -u pair bash | |
# Remove tmux pair socket | |
rm -f /tmp/pair | |
} | |
################################# | |
# Main | |
################################# | |
case $1 in | |
"setup") | |
setup_pair_user_full | |
;; | |
*) | |
tmux_session | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment