jedi4ever / veewee

Easing the building of vagrant boxes
MIT License
4.29k stars 779 forks source link

Feature: specify a different ssh_user for each postinstall_files #200

Open stagrlee opened 12 years ago

stagrlee commented 12 years ago

Would like the ability to specify a different ssh user for each postinstall file.

This would cleanup the build scripts for the funtoo box I'm working on. The postinstall works around this by setting up an SSH very similar to what veewee does. In the funtoo build, veewee ssh's into the box via root and the second postinstall ssh's to localhost to login to the vagrant account, kind of like a matryoshka doll.

I wanted the vagrant box to have RVM all setup in multi-user mode http://beginrescueend.com/rvm/install/

As the RVM documentation points out, this must be installed from a user account in the rvm group. I played around with su and sudo both inside chroot and booted through the built kernel and had no luck. What worked was ssh'ing into the box. What would be ideal for me is to have the first postinstall run as root and the second postinstall run as vagrant.

Might be similar to issue #57, more flexibility with user declarations... Might be able to make this backward compatible by reusing the same login if only one is specified.

ixti commented 10 years ago

I solved this using post-install files like this:

_zshenv

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
source "$HOME/.nvm/nvm.sh"

_zshrc

ZSH=$HOME/.oh-my-zsh
ZSH_THEME="kphoen"

COMPLETION_WAITING_DOTS="true"

plugins=(git rbenv ruby python tmux npm pip vagrant rake)

source $ZSH/oh-my-zsh.sh

setopt nocorrectall

bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word

alias tmux="tmux -2"

vagrant-user.sh

apt-get -y install zsh git tig tmux exuberant-ctags vim-nox
chsh --shell /bin/zsh vagrant

run () {
  echo "*** $1"
  su -l -c "$1" vagrant
}

# Install ixti's tmux & vim configs
run "git clone https://github.com/ixti/dotfiles.git ~/.dotfiles"
run "cd ./.dotfiles && git submodule init && git submodule update"
run "cd ~/.dotfiles/tmux && ./install.sh"
run "cd ~/.dotfiles/vim && ./install.sh"

# Install oh my zsh
run "git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh"

# Install rbenv & plugins
run "git clone https://github.com/sstephenson/rbenv.git ~/.rbenv"
run "git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build"
run "git clone https://github.com/tpope/rbenv-ctags.git ~/.rbenv/plugins/rbenv-ctags"

# Install nvm
run "git clone https://github.com/creationix/nvm.git ~/.nvm"

# Configure ZSH
run "cat _zshrc > .zshrc"
run "cat _zshenv > .zshenv"

# Install Ruby
run "rbenv install 1.9.3-p448"
run "rbenv global 1.9.3-p448"

# Instal Node.js
run "nvm install 0.10"
run "nvm alias default 0.10"

Notice that I use ZSH as my shell, which loads .zshenv always, then .zshprofile upon login (-l optiosn of su does the trick) and .zshrc upon interactive mode (ssh with terminal allocation). Refer to your shell in order to put things for rvm into correct files.