Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e8c8c62c1b
Fetching contributors…

Cannot retrieve contributors at this time

executable file 377 lines (316 sloc) 10.305 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
#!/bin/bash
# Copyright (c) 2009-2011 VMware, Inc.
# Try to detect platform. VCAP installs well on Ubuntu and MacOS X Systems.

OS=`uname -s`
if [[ $OS == 'Linux' ]]; then
    PLATFORM='Linux'
elif [[ $OS == 'Darwin' ]]; then
    PLATFORM='MacOSX'
else
    echo "Unknown System, cancelling setup"
    exit 1
fi

echo ""
echo '-----------------------------------------------------------'
echo "($PLATFORM) Setup for VMware's Cloud Application Platform!"
echo '-----------------------------------------------------------'
echo ""


echo "Just hit <enter> to skip any item"
echo ""

if [ "$(id -u)" != "0" ]; then
    echo '** Setup must be run as root **'
    exit 1
fi

read -p "Setup all components? default: individual components? [y/N]"
if [[ $REPLY =~ ^[yY]$ ]]; then
    ALL=true
fi

# Defaults, done for everyone

echo "Installing default packages"
if [[ $PLATFORM == 'Linux' ]]; then
    apt-get install -qqy wget curl libcurl3 libcurl3-dev bison build-essential zlib1g-dev libssl-dev libreadline5-dev libxml2 libxml2-dev libxslt1.1 libxslt1-dev git-core sqlite3 libsqlite3-ruby libsqlite3-dev unzip zip
fi

if [[ $PLATFORM == 'Linux' ]]; then
    # Probably should make this something different instead of apt_get
    echo "Installing Ruby"
    apt-get install -qqy ruby-full rake
fi

# This is site/setup specific, can be commented out if not needed.
# export http_proxy='http://192.168.208.20:3128'

RUBYGEMS_VERSION=1.6.2
echo "Checking rubygems version"
if [ "$(gem -v)" != $RUBYGEMS_VERSION ]; then
    echo "Installing rubygems $RUBYGEMS_VERSION"
    pushd .
    cd /tmp
    wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBYGEMS_VERSION.tgz
    tar -zxf rubygems-$RUBYGEMS_VERSION.tgz
    cd rubygems-$RUBYGEMS_VERSION
    ruby setup.rb
    if [ -f /usr/local/bin/gem ]; then
rm /usr/local/bin/gem
    fi
    cd ..
    rm rubygems-$RUBYGEMS_VERSION.tgz
    rm -fr rubygems-$RUBYGEMS_VERSION
    popd
fi
ln -sf /usr/bin/gem1.8 /usr/bin/gem

echo "Creating default directories at /var/vcap"

if [ ! -d '/var/vcap' ]; then
    mkdir /var/vcap
    mkdir /var/vcap/sys
    mkdir /var/vcap/sys/log
    mkdir /var/vcap/shared
    mkdir /var/vcap/services
    chmod -R 777 /var/vcap
fi

if [[ ! "$(bundle -v)" =~ "1.0.10" ]]; then
    echo "Installing bundler 1.0.10"
    gem install bundler -v 1.0.10 --no-rdoc --no-ri
fi

#######################################################################

# Router
if [[ $ALL != true ]]; then
    echo ""
    read -p "Should I do a Router setup? [y/N] "
    if [[ $REPLY =~ ^[yY]$ ]]; then
        ROUTER=true
fi
fi

if [[ $ROUTER == true || $ALL == true ]]; then

    echo "Installing Nginx."
    if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy nginx
    elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
    fi
    echo ""
fi

# CloudController
if [[ $ALL != true ]]; then
    read -p "Should I do a CloudController setup? [y/N] "
    if [[ $REPLY =~ ^[yY]$ ]]; then
        CC=true
fi
fi

if [[ $CC == true || $ALL == true ]]; then
    if [[ $PLATFORM == 'Linux' ]]; then
read -p "Should I do a production setup as well (Postgres/MySQL)? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
echo "Installing PostgreSQL server and support"
apt-get install -qqy postgresql
echo "Installing pg gems"
gem install pg --no-rdoc --no-ri
echo ""
echo "Installing MySQL server and support"
apt-get install -qqy mysql-server ruby-dev libmysql-ruby libmysqlclient-dev
echo "Installing mysql gems"
gem install mysql --no-rdoc --no-ri
echo ""
fi
    elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
    fi


    # note: vcap start runs db:migrate on each cloud boot
    # no need to run anything during setup
fi

# DEA
if [[ $ALL != true ]]; then
    read -p "Should I do a DEA setup (Java, Ruby, Node, etc)? [y/N] "
    if [[ $REPLY =~ ^[yY]$ ]]; then
        DEA=true
fi
fi

if [[ $DEA == true || $ALL == true ]]; then
    echo "Setting up for support for DEA"

    # lsof support for secure dea monitoring, psmisc is for JeOS, which has killall5, not killall
    if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy lsof psmisc
    elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
    fi

    # For Ruby
    if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy librmagick-ruby
    elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
    fi

    # Java
    if [[ $PLATFORM == 'Linux' ]]; then
JAVA=`dpkg --get-selections | grep sun-java6`
echo $JAVA
    elif [[ $PLATFORM == 'MacOSX' ]]; then
JAVA=`java -version | grep 'build 1.6.0_22'`
    fi

    if [[ $JAVA == '' ]]; then
        echo "Installing Sun Java 1.6"
if [[ $PLATFORM == 'Linux' ]]; then
            apt-get install -qqy python-software-properties
            add-apt-repository "deb http://archive.canonical.com/ lucid partner"
            apt-get -qqy update
            apt-get install -qqy curl sun-java6-bin sun-java6-jre sun-java6-jdk
elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
fi
    fi

    # Node
    pushd .
    cd /tmp

    NODE_VERSION=0.4.5

    if [[ ! `node -v` == 'v'$NODE_VERSION ]]; then
wget http://nodejs.org/dist/node-v$NODE_VERSION.tar.gz
tar -zxf node-v$NODE_VERSION.tar.gz
cd node-v$NODE_VERSION
./configure
make
make install
cd ..
rm node-v$NODE_VERSION.tar.gz
rm -fr node-v$NODE_VERSION
popd
fi

    ERLANG_VERSION=R14B02

    if [ ! -d "/opt/vcap/runtimes/erlang$ERLANG_VERSION" ]; then
   if [[ $PLATFORM == 'Linux' ]]; then
   apt-get -qqy install build-essential libncurses5-dev openssl libssl-dev
   elif [[ $PLATFORM == 'MacOSX' ]]; then
   echo -e "\033[31mFIXME: Install MacOSX dependencies \033[0m"
   fi

wget http://erlang.org/download/otp_src_$ERLANG_VERSION.tar.gz
tar zxvf otp_src_$ERLANG_VERSION.tar.gz
cd otp_src_$ERLANG_VERSION

if [[ $PLATFORM == 'Linux' ]]; then
   apt-get -qqy install build-essential libncurses5-dev openssl libssl-dev
   elif [[ $PLATFORM == 'MacOSX' ]]; then
   echo -e "\033[31mFIXME: Install MacOSX dependencies \033[0m"
   fi
  
./configure --prefix /opt/vcap/runtimes/erlang-$ERLANG_VERSION
make
make install
   fi

    echo "App Platform Support"
    echo "===================="

    echo -e "\nRuby should now be installed -->"
    ruby -v

    echo -e "\nJava should now be installed -->"
    java -version

    echo -e "\nNode should now be installed -->"
    node -v
    echo ""

    echo -e "\nErlang should now be installed -->"
    erl -version
    echo ""

    echo "Setting up Ruby System Gems and Support"
    if [[ $PLATFORM == 'Linux' ]]; then
apt-get install -qqy ruby-dev libmysql-ruby libmysqlclient-dev libpq-dev postgresql-client
    elif [[ $PLATFORM == 'MacOSX' ]]; then
echo -e "\033[31mFIXME: Implement for MacOSX \033[0m"
    fi

    echo "Installing some default system gems"
    echo "gem: --no-rdoc --no-ri" > ~/.gemrc
    gem install rack rake thin sinatra eventmachine

    if [ ! -d '/var/vcap.local' ]; then
echo "Creating directory /var/vcap.local"
mkdir "/var/vcap.local"
chmod 777 "/var/vcap.local"
    fi

    if [[ $ALL != true ]]; then
read -p "Should I do a production setup and secure this system? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
          # Setup var directory
echo "Securing directories and permissions"
chmod 755 "/var"
chmod -R 700 "/var/vcap/sys"
chmod -R 700 "/var/vcap/shared"
chmod -R 700 "/var/vcap.local"
chmod -R 711 "/var/vcap.local"
chmod -R 711 "/var/vcap.local/apps"
chmod -R 700 "/tmp"
chmod -R 700 "/var/tmp"
fi
echo ""
    fi
fi

###################

echo ""
echo "Additional Optional Services"

# if you answered no to the production setup
# question than you should answer yes here for sure
X=`which mysqld`
if [ $? != 0 ]; then
    read -p "Should I add MySQL Server? [y/N] "
    if [[ $REPLY =~ ^[yY]$ ]]; then
        echo "Installing MySQL server and support"
apt-get install -qqy mysql-server ruby-dev libmysql-ruby libmysqlclient-dev
echo "Installing mysql gems"
gem install mysql --no-rdoc --no-ri
echo ""
    fi
fi

REDIS_VERSION=2.2.4

redis_current=`redis-server -v | grep $REDIS_VERSION`

if [[ -z "$redis_current" ]]; then
    read -p "Should I add Redis Server? [y/N] "
    if [[ $REPLY =~ ^[yY]$ ]]; then
echo "Installing Redis (version $REDIS_VERSION)"
pushd .
cd /tmp
wget --no-check-certificate -O redis_master.tgz http://redis.googlecode.com/files/redis-$REDIS_VERSION.tar.gz
tar -zxf redis_master.tgz
cd redis-$REDIS_VERSION/src
make
cp redis-server /usr/bin
cp redis-cli /usr/bin
cd ../..
rm redis_master.tgz
rm -fr redis-$REDIS_VERSION
popd
fi
else
    echo "Redis Server (version 2.2.2) is current"
fi

RABBITMQ_VERSION=2.4.0
RABBITMQ_VERSION_FULL=2.4.0-1_all

read -p "Should I add RabbitMQ Server? [y/N] "
if [[ $REPLY =~ ^[yY]$ ]]; then
    echo "Installing RabbitMQ Server (version $RABBITMQ_VERSION)"
    pushd .
    cd /tmp
    wget http://www.rabbitmq.com/releases/rabbitmq-server/v$RABBITMQ_VERSION/rabbitmq-server_$RABBITMQ_VERSION_FULL.deb
    dpkg -i rabbitmq-server_$RABBITMQ_VERSION_FULL.deb
    rm rabbitmq-server_$RABBITMQ_VERSION_FULL.deb
    popd
fi

MONGODB_VERSION=1.8.1

mongodb_current=`mongod --version | grep $MONGODB_VERSION`

if [[ -z "$mongodb_current" ]]; then
    read -p "Should I add the MongoDB Server? [y/N] "
    if [[ $REPLY =~ ^[yY]$ ]]; then
echo "Installing MongoDB Server (version $MONGODB_VERSION)"
if [[ `uname -a` =~ "x86_64" ]] ; then
mongodb="mongodb-linux-x86_64-$MONGODB_VERSION"
echo "Installing 64-bit version"
else
mongodb="mongodb-linux-i686-$MONGODB_VERSION"
echo "Installing 32-bit version"
fi

pushd .
cd /tmp
wget http://fastdl.mongodb.org/linux/$mongodb.tgz
tar -zxvf $mongodb.tgz
cp $mongodb/bin/* /usr/bin
rm $mongodb.tgz
rm -fr $mongodb
popd
fi
else
    echo "MongoDB Server (version $MONGODB_VERSION) is current"
fi

echo -e "\n\nYou should be good to go!!\n\n"
ruby -v

echo -n "Gem version: "
gem -v

echo -e "\nGem List"
gem list --local

echo -e "\n\nBYE!\n\n"
Something went wrong with that request. Please try again.