Permalink
Browse files

updated bootstrap and passing app user to bootstrap - seems to be nec…

…essary in some cases
  • Loading branch information...
1 parent 2a076cc commit 50725d070e96523cdae4aa3a702d7f5cdff96833 @mkocher committed Jun 29, 2011
Showing with 24 additions and 18 deletions.
  1. +2 −1 Capfile
  2. +22 −17 bootstrap.sh
View
@@ -39,9 +39,10 @@ end
desc "bootstrap"
task :bootstrap do
+ app_user = fetch(:user)
set :user, "root"
set :default_shell, "/bin/bash"
upload "bootstrap.sh", "/root/bootstrap.sh"
run "chmod a+x /root/bootstrap.sh"
- run "/root/bootstrap.sh"
+ run "APP_USER=#{app_user} /root/bootstrap.sh"
end
View
@@ -1,18 +1,20 @@
#!/bin/bash -e
-export app_user="mkocher"
+
+env | grep -q "APP_USER=" || echo "Please set APP_USER environment variable"
+echo "app user at the beginning: $APP_USER"
# perl -e 'print crypt("password", "salt"),"\n"'
-getent passwd $app_user >/dev/null 2>&1 || useradd $app_user -p sa3tHJ3/KuYvI
+getent passwd $APP_USER >/dev/null 2>&1 || useradd $APP_USER -p passwordhashgoeshere # sa3tHJ3/KuYvI would set the password to "password"
-# copy root's authorized keys to app_user
-mkdir -p /home/$app_user/.ssh
-touch /home/$app_user/.ssh/authorized_keys
-chmod 700 /home/$app_user/.ssh
-chmod 600 /home/$app_user/.ssh/authorized_keys
-chown -R $app_user /home/$app_user/.ssh
+# copy root's authorized keys to APP_USER
+mkdir -p /home/$APP_USER/.ssh
+touch /home/$APP_USER/.ssh/authorized_keys
+chmod 700 /home/$APP_USER/.ssh
+chmod 600 /home/$APP_USER/.ssh/authorized_keys
+chown -R $APP_USER /home/$APP_USER/.ssh
authorized_keys_string=`cat /root/.ssh/authorized_keys`
-grep -sq "$authorized_keys_string" /home/$app_user/.ssh/authorized_keys || cat /root/.ssh/authorized_keys >> /home/$app_user/.ssh/authorized_keys
+grep -sq "$authorized_keys_string" /home/$APP_USER/.ssh/authorized_keys || cat /root/.ssh/authorized_keys >> /home/$APP_USER/.ssh/authorized_keys
## enable ssh password auth
@@ -26,18 +28,20 @@ rpm -q epel-release-5-4.noarch || rpm -Uvh http://download.fedora.redhat.com/pub
yum -y install git
# rvm prereqs
-yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel iconv-devel java
+yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libffi-devel openssl-devel iconv-devel java
# passwordless sudo
sudo_string='ALL ALL = (ALL) NOPASSWD: ALL'
grep "$sudo_string" /etc/sudoers || echo "$sudo_string" >> /etc/sudoers
-cat <<'BOOTSTRAP_AS_USER' > /home/$app_user/bootstrap_as_user.sh
+cat <<'BOOTSTRAP_AS_USER' > /home/$APP_USER/bootstrap_as_user.sh
set -e
-mkdir -p /home/$app_user/rvm/src
-curl -Lsf http://github.com/wayneeseguin/rvm/tarball/156d0b42feba4922ad04 | tar xvz -C/home/$app_user/rvm/src --strip 1
-cd "/home/$app_user/rvm/src" && ./install
+export APP_USER=$1
+
+mkdir -p /home/$APP_USER/rvm/src
+curl -Lskf http://github.com/wayneeseguin/rvm/tarball/156d0b42feba4922ad04 | tar xvz -C/home/$APP_USER/rvm/src --strip 1
+cd "/home/$APP_USER/rvm/src" && ./install
rvm_include_string='[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"'
grep "$rvm_include_string" ~/.bashrc || echo "$rvm_include_string" >> ~/.bashrc
@@ -49,6 +53,7 @@ rvm_gemset_create_on_use_flag=1
RVMRC_CONTENTS
BOOTSTRAP_AS_USER
-chmod a+x /home/$app_user/bootstrap_as_user.sh
-su - $app_user /home/$app_user/bootstrap_as_user.sh
-rm /home/$app_user/bootstrap_as_user.sh
+echo "app user at the end: $APP_USER"
+chmod a+x /home/$APP_USER/bootstrap_as_user.sh
+su - $APP_USER /home/$APP_USER/bootstrap_as_user.sh $APP_USER
+rm /home/$APP_USER/bootstrap_as_user.sh

0 comments on commit 50725d0

Please sign in to comment.