bugfix, refactor funcs

This commit is contained in:
Alec Leamas 2010-11-01 05:20:33 +01:00
parent c07771b390
commit d8376b5a84
2 changed files with 118 additions and 35 deletions

View file

@ -1,48 +1,102 @@
#!/bin/bash
#
# Install diaspora, its dependencies and start.
#
# Usage: bootstrap-fedora-diaspora.sh [external hostname]
#
# Must run as root
export DIASPORADIR=`pwd`
arg_hostname="$1"
echo "####"
echo "Installing build deps ..."
echo "####"
sleep 3
su -c "yum install git bison svn autoconf sqlite-devel gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel ImageMagick git rubygems libxslt libxslt-devel libxml2 libxml2-devel openssl-devel"
. source/funcs.sh
echo "####"
echo "Installing RVM ..."
echo "####"
sleep 3
test $UID = "0" || {
echo "You need to be root to do this, giving up"
exit 2
}
mkdir -p ~/.rvm/src/ && cd ~/.rvm/src && rm -rf ./rvm/ && git clone --depth 1 git://github.com/wayneeseguin/rvm.git && cd rvm && ./install
yum install -y git bison svn autoconf sqlite-devel gcc-c++ patch \
readline-devel zlib-devel libyaml-devel libffi-devel \
ImageMagick git rubygems libxslt-devel libxml2-devel \
openssl-devel mongodb-server wget openssh-clients
echo "####"
echo "Installing RVM into bashrc and sourcing bash ..."
echo "####"
sleep 3
getent group diaspora >/dev/null || groupadd diaspora
getent passwd diaspora >/dev/null || {
useradd -g diaspora -s /bin/bash -m diaspora
echo "Created user diaspora"
}
if [[ `grep -l "rvm/scripts/rvm" $HOME/.bashrc | wc -l` -eq 0 ]]; then
echo 'if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi' >> $HOME/.bashrc
su - diaspora <<EOF
set -x
[ -e "\$HOME/.rvm/scripts/rvm" ] || {
echo '#### Installing rvm ####'
wget http://rvm.beginrescueend.com/releases/rvm-install-head
bash < rvm-install-head && rm rvm-install-head
if [[ -s "\$HOME/.rvm/scripts/rvm" ]]; then
. "\$HOME/.rvm/scripts/rvm"
else
echo "Error: rvm installation failed";
exit 1;
fi
source $HOME/.bashrc
touch \$HOME/.bashrc
grep -q "rvm/scripts/rvm" \$HOME/.bashrc || {
echo '[[ -s "\$HOME/.rvm/scripts/rvm" ]] && \
source "\$HOME/.rvm/scripts/rvm"' \
>> \$HOME/.bashrc
}
}
echo "####"
echo "Installing ruby (will take forever) ..."
echo "####"
sleep 3
source \$HOME/.bashrc
[ -d .ssh ] || {
ssh-keygen -q
echo "StrictHostKeyChecking no" > .ssh/config
chmod 600 .ssh/config
}
ruby=\$(which ruby) || ruby=""
if [[ -z "\$ruby" || ("\${ruby:0:4}" == "/usr") ]]; then
echo '#### Installing ruby (will take forever) ... ####'
rvm install ruby-1.8.7-p302
rvm --default ruby-1.8.7
echo "####"
echo "Installing bundler ..."
echo "####"
sleep 3
echo "#### Installing bundler ... ####"
gem install bundler
fi
echo '### Clone diapora, install bundle. ###'
git clone git@github.com:diaspora/diaspora.git
cd diaspora
bundle install
#Configure diaspora
source pkg/source/funcs.sh
init_appconfig config/app_config.yml "\$arg_hostname"
# Install DB setup
echo "Setting up DB..."
if bundle exec rake db:seed:dev ; then
cat <<- EOM
DB ready. Login -> tom and password -> evankorth.
More details ./diaspora/db/seeds/tom.rb. and ./diaspora/db/seeds/dev.rb.
EOM
else
cat <<- EOM
Database config failed. You might want to remove all db files with
'rm -rf /var/lib/mongodb/*' and/or reset the config file by
'cp config/app_config.yml.example config/app_config.yml' before
making a new try. Also, make sure the mongodb server is running
e. g., by running 'service mongodb status'.
EOM
fi
# Run appserver
echo "Starting server"
script/server
EOF
echo "####"
echo "Installing deps with bundle ..."
echo "####"
sleep 3
pushd $DIASPORADIR && bundle install && popd

View file

@ -59,7 +59,7 @@ function checkout()
git clone --quiet $GIT_REPO;
(
cd diaspora;
git checkout Gemfile
git checkout Gemfile Gemfile.lock
git remote add upstream \
git://github.com/diaspora/diaspora.git
for p in ../../*.patch; do
@ -77,3 +77,32 @@ function checkout()
)
}
function init_appconfig
# Edit pod_url in hostname
# Silently uses argumetn if present, else run dialog.
# Usage: init_appconfig <app_config.yml> [hostname]
{
config=$1
arg_hostanme="$2"
hostname=$( awk '/pod_url:/ { print $2; exit }' <$config )
if [ -n "$arg_hostname" ]; then
sed -i "/pod_url:/s|$hostname|$arg_hostname|g" $config && \
echo "config/app_config.yml updated."
return 0
else
while : ; do
echo "Current hostname is \"$hostname\""
echo -n "Enter new hostname [$hostname] :"
read new_hostname garbage
echo -n "Use \"$new_hostname\" as pod_url (Yes/No) [Yes]? :"
read yesno garbage
[ "${yesno:0:1}" = 'y' -o "${yesno:0:1}" = 'Y' -o -z "$yesno" ] && {
sed -i "/pod_url:/s|$hostname|$new_hostname|g" $config &&
echo "config/app_config.yml updated."
break
}
done
fi
}