#!/bin/bash function create_pg_user { # create the database role sudo su - postgres -c "psql -c \"CREATE ROLE $FACTER_RDBMS_USERNAME WITH LOGIN CREATEDB SUPERUSER PASSWORD '$FACTER_RDBMS_PASSWORD';\"" # note that the SUPERUSER option can be removed once we user Rails that merge this fix: https://github.com/rails/rails/pull/8548 if [ $? -ne 0 ]; then echo "INFO: postgresql create role $FACTER_RDBMS_USERNAME failed" fi } # Set this to 0 if you don't have (or don't want to use) sudo permissions if [ "x$HAVESUDO" = "x" ]; then HAVESUDO=1 fi # Setup a development environment for conductor, tim # and aeolus-cli. Configure conductor to use an external # imagefactory/deltacloud by setting env variables and # oauth.json, below. Startup conductor on port 3000 if [ "x$WORKDIR" = "x" ]; then export WORKDIR=~/aeolus-workdir fi # Where the aeolus projects (conductor, aeolus-cli and tim) # get checked out to if [ "x$FACTER_AEOLUS_WORKDIR" = "x" ]; then export FACTER_AEOLUS_WORKDIR=$WORKDIR fi # Port to start up conductor on if [ "x$FACTER_CONDUCTOR_PORT" = "x" ]; then export FACTER_CONDUCTOR_PORT=3000 fi # Used specifically for the conductor/tim's callback_url that gets # provided to imagefactory (in # /conductor/src/config/initializers/tim.rb) if [ "x$FACTER_CONDUCTOR_HOSTNAME" = "x" ]; then export FACTER_CONDUCTOR_HOSTNAME=`hostname` fi # RDBMS to use for the install (postgresql|sqlite) if [ "x$FACTER_RDBMS" = "x" ]; then export FACTER_RDBMS=postgresql fi # If using postgresql, set some sane defaults if not present in environment if [ "$FACTER_RDBMS" = "postgresql" ]; then if [ "x$FACTER_RDBMS_DBNAME" = "x" ]; then # assign a random database name if no database name provided by user export FACTER_RDBMS_DBNAME=conductor_` $FACTER_OAUTH_JSON_FILE fi fi # Optional environment variables (sample values are given below) # # If the following env var is defined, checkout and start up # deltacloud locally rather than use an existing installation. # export SETUP_LOCAL_DELTACLOUD_RELEASE=release-1.0.5 # export SETUP_LOCAL_DELTACLOUD_PORT=3002 # # _BRANCH variables below may be either branches, tags or commit hashes. # Note that master is the default branch cloned from each of the three # projects if a _BRANCH is not specified. # # export FACTER_AEOLUS_CLI_BRANCH=0.5.x # export FACTER_CONDUCTOR_BRANCH=0.10.x # export FACTER_TIM_PULL_REQUEST=v0.2.0 # # Pull requests must be integers # # export FACTER_AEOLUS_CLI_PULL_REQUEST=6 # export FACTER_CONDUCTOR_PULL_REQUEST=47 # export FACTER_TIM_PULL_REQUEST=2 # if `netstat -tln | grep -q -P "\:$FACTER_CONDUCTOR_PORT\\s"`; then echo "A process is already listening on port $FACTER_CONDUCTOR_PORT. Aborting" exit 1 fi if [ -e $FACTER_AEOLUS_WORKDIR/conductor -o -e $FACTER_AEOLUS_WORKDIR/tim -o \ -e $FACTER_AEOLUS_WORKDIR/aeolus-cli ]; then echo -n "Already existing directories, one of $FACTER_AEOLUS_WORKDIR/conductor, " echo "$FACTER_AEOLUS_WORKDIR/tim or $FACTER_AEOLUS_WORKDIR/aeolus-cli. Aborting" exit 1 fi os=unsupported if `grep -Eqs 'Red Hat Enterprise Linux Server release 6|CentOS release 6' /etc/redhat-release`; then os=el6 fi if `grep -qs -P 'Fedora release 16' /etc/fedora-release`; then os=f16 fi if `grep -qs -P 'Fedora release 17' /etc/fedora-release`; then os=f17 fi if [ -f /etc/debian_version ]; then os=debian fi if [ "$os" = "unsupported" ]; then echo This script has not been tested outside of EL6, Fedora 16, echo Fedora 17 or debian. You will need to install development echo libraries manually. echo echo Press Control-C to quit, or ENTER to continue read waiting fi # install dependencies for fedora/rhel/centos if [ "$os" = "f16" -o "$os" = "f17" -o "$os" = "el6" ]; then depends="git patch" # general ruby deps needed to roll your own ruby or build extensions depends="$depends gcc make zlib-devel" # Conductor-specific deps depends="$depends libffi-devel" #ffi depends="$depends libxml2-devel" #nokogiri depends="$depends libxslt-devel" #nokogiri depends="$depends gcc-c++" #eventmachine # Puppet and puppet modules deps depends="$depends openssl-devel lsof" if [ "$FACTER_RDBMS" = "sqlite" ]; then depends="$depends sqlite-devel" #sqlite3 elif [ "$FACTER_RDBMS" = "postgresql" ]; then depends="$depends postgresql-devel postgresql postgresql-server" fi if [ "x$RBENV_VERSION" = "x" ]; then # additional dependencies if using system ruby and not rbenv depends="$depends rubygems ruby-devel" if [ $os != "el6" ]; then depends="$depends rubygem-bundler" fi fi # Add Deltacloud build dependencies if needed if [ "x$SETUP_LOCAL_DELTACLOUD_RELEASE" != "x" ]; then depends="$depends bison flex libxslt openssl-devel" depends="$depends readline-devel" # Deltacloud added new deps after 1.0.5: # https://mail-archives.apache.org/mod_mbox/deltacloud-dev/201212.mbox/browser depends="$depends sqlite-devel" fi # If we have sudo, we're able to install missing dependencies if [ "$HAVESUDO" = "1" ]; then # Check which dependencies need installing install_list="" for dep in $depends; do if ! `rpm -q --quiet --nodigest $dep`; then install_list="$install_list $dep" fi done # Install the needed packages if [ "x$install_list" != "x" ]; then sudo yum install -y $install_list fi # Verify the dependencies did install fail_list="" for dep in $depends; do if ! `rpm -q --quiet --nodigest $dep`; then fail_list="$fail_list $dep" fi done # If anything failed verification, we tell the user and exit if [ "x$fail_list" != "x" ]; then echo "ABORTING: FAILED TO INSTALL $fail_list" exit 1 fi if [ "$FACTER_RDBMS" = "postgresql" ]; then # If postgresql is already initialized, we do not want to overwrite settings in # an existing /var/lib/pgsql/data/pg_hba.conf PG_HBA_CONF_EXISTS=0 if sudo test -e /var/lib/pgsql/data/pg_hba.conf &> /dev/null; then echo "INFO: postgresql database previously initialized" PG_HBA_CONF_EXISTS=1 fi # initialize the postgresql database # if postgresql has already been initialized with the default data dir (/var/lib/pgsql/data) # then this is a no-op if [ "$os" == "el6" ]; then sudo service postgresql initdb else sudo postgresql-setup initdb fi # if there was no pre-existing pg_hba.conf, set all authentication methods to 'trust' and 'md5' if [ $PG_HBA_CONF_EXISTS -eq 0 ]; then sudo sh -c "cat >/var/lib/pgsql/data/pg_hba.conf <: undefined method `enum_lsdev' for Facter::Util::Processor:Module declare -A gem_versions gem_versions["facter"]=1.6.13 for the_gem in $gem_installs; do if [ `gem list -i $the_gem` = "false" ]; then cmd="gem install $the_gem" if [ "x$RBENV_VERSION" = "x" ]; then # TODO perhaps determine a way to install gem local to current # user instead. For now, do a system install of the gem when # using system ruby # http://docs.rubygems.org/read/chapter/3 if [ "$HAVESUDO" = "1" ]; then cmd="sudo $cmd" else echo 'Installing local gems without using rbenv is not currently supported.' echo 'If you want to install gems system-wide using system ruby instead of rbenv, you must be a sudo-enabled user' exit 1 fi fi if [ ! "x${gem_versions[$the_gem]}" = "x" ]; then cmd="$cmd -v ${gem_versions[$the_gem]}" fi $cmd if [ `gem list -i $the_gem` = "false" ]; then echo "ABORTING. FAILED TO INSTALL $the_gem" exit 1 fi fi done # newly installed rbenv/gem binaries require an rbenv rehash to work # properly in our $PATH if [ "x$RBENV_VERSION" != "x" ]; then cd $FACTER_AEOLUS_WORKDIR && rbenv rehash fi # Setup the local deltacloud instance, if the user wants one if [ "x$SETUP_LOCAL_DELTACLOUD_RELEASE" != "x" ]; then cd $FACTER_AEOLUS_WORKDIR if [ -d deltacloud ]; then echo 'INFO deltacloud dir already exists' else git clone https://git-wip-us.apache.org/repos/asf/deltacloud.git fi cd deltacloud git checkout $SETUP_LOCAL_DELTACLOUD_RELEASE cd server bundle install --path ../bundle [ -z $SETUP_LOCAL_DELTACLOUD_PORT ] && SETUP_LOCAL_DELTACLOUD_PORT=3002 if `netstat -tlpn | grep -q -P "\:$SETUP_LOCAL_DELTACLOUD_PORT\\s"`; then echo "WARNING A process is already listening on port $SETUP_LOCAL_DELTACLOUD_PORT" echo " Not starting up deltacloud" else echo "* Starting up deltacloudd on port $SETUP_LOCAL_DELTACLOUD_PORT" # TODO: setup logging by using a custom config file bundle exec "bin/deltacloudd -i \"mock\" -p $SETUP_LOCAL_DELTACLOUD_PORT" >log/deltacloud.log 2>&1 & fi fi # These next few lines are usuall a no-op since WORKDIR # and FACTER_AEOLUS_WORKDIR are usually the same mkdir -p $WORKDIR if [ ! -d $WORKDIR ]; then echo "ABORTING. Could not create directory $WORKDIR" exit 1 fi cd $WORKDIR if [ ! -d dev-tools ]; then git clone https://github.com/martinpovolny/dev-tools.git if [ "x$DEV_TOOLS_BRANCH" != "x" ]; then cd dev-tools git checkout $DEV_TOOLS_BRANCH cd .. fi else echo 'dev-tools DIRECTORY ALREADY EXISTS, LEAVING IN TACT.' fi echo "Given this puppet bug http://projects.puppetlabs.com/issues/9862" echo "you may need to add manually the 'puppet' group to the system in case of errors." # install repos, configure and start up conductor cd $WORKDIR/dev-tools puppet apply -d --modulepath=. test.pp --no-report if [ $? -eq 0 ]; then echo "** instalation successfully finished **" fi # Arbitrary post-script command to execute # (useful for say, seeding provider accounts) if [ ! "x$POST_SCRIPTLET" = "x" ]; then # When $POST_SCRIPTLET is eval'ed, it should just write the script # to execute to stdout. It is "eval'ed" so your outside script can # safely use bootstrap.sh environment variables. eval $POST_SCRIPTLET | /bin/sh -x fi