#!/usr/bin/env bash provide_version='0.5' dm_version='0.3.15' base=$1 dbuser=$2 dbpass=$3 domain=$4 secret=$5 echo "Checking input values..." echo " path=$base" echo " dbuser=$dbuser" echo " dbpass=$dbpass" echo " domain=$domain" echo " secret=$secret" echo if [ -z $base ] || [ -z $dbuser ] || [ -z $dbpass ] || [ -z $domain ] || [ -z $secret ] then echo "Error: Not enough input parameters. Usage info:" echo echo "provide-provide-$provide_version PATH DBUSER DBPASS DOMAIN SECRET" echo echo " PATH Path to existing dir, like ~ (for example)." echo " DBUSER Name of existing database user." echo " DBPASS Password of existing database user." echo " DOMAIN Name of domain that will be served by Provide." echo " SECRET Long random string, for security protocols." echo exit 1 fi echo "Checking your platform capabilities...." check () if ! (which $@) then echo "Error: Can't find '$@' on your platform. Please either create a symlink to your favorite '$@' program, or install this program. Then run this script again." exit 1 fi check 'cp' check 'editor' check 'env' check 'mkdir' check 'perl' check 'python' check 'rm' check 'sleep' check 'tar' check 'wget' echo "Checking your Python capabilities...." checkPython () { echo "$1" if ! (python -c "import $1" >/dev/null 2>&1) then echo "Error: Can't find Python module '$1'." echo "" echo "Please install this Python module (in Debian, this package is call ed '$2'). Then run this script again." echo "" exit 1 fi } checkPython 'PIL' 'python-imaging' checkPython 'django' 'python-django' checkPython 'simplejson' 'python-simplejson' checkPython 'mx.DateTime' 'python-egenix-mxdatetime' checkPython 'psycopg' 'python-psycopg' echo "Your Python checks out OK." echo # todo: Fix this for earlier versions of bash (conditional binary operator). #if [[$base =~ '^[^\/]']] #then # echo "Sorry, the path argument needs to be an absolute path." # exit 1 #fi if [ ! -e $base ] then echo "Error: Installation path '$1' not found." exit 1 fi if [ ! -d $base ] then echo "Error: Installation path '$1' not a directory." exit 1 fi base=${base//%\//} livebase="$base/provided" live="$livebase/$provide_version" if [ -e $live ] then echo "This version of Provide is already installed under $base." echo echo "Reinstallation will not be attempted. To remove this Provide installation, drop the 'provide-$provide_version' database and remove the '$live' directory. Make sure you really want to do this!!" echo exit 1 fi echo "Your platform checks out OK." echo sleep 4 if [ -e $livebase ] then echo "Installation dir $livebase already exists..." else echo "Making installation dir $livebase..." mkdir $livebase || exit 1 fi echo "Installing Provide to $live..." echo "Making installation dir $live..." mkdir $live || exit 1 echo "Making lib/python dir..." mkdir $live/lib mkdir $live/lib/python echo "Augmenting PYTHONPATH environment variable..." sleep 1 export PYTHONPATH=$live/lib/python:$PYTHONPATH echo "export PYTHONPATH=$PYTHONPATH" echo "Fetching domainmodel distribution..." sleep 1 wget -O domainmodel-$dm_version.tar.gz http://appropriatesoftware.net/provide/docs/domainmodel-$dm_version.tar.gz || exit 1 echo "Installing domainmodel..." sleep 1 tar zxvf domainmodel-$dm_version.tar.gz cd domainmodel-$dm_version python setup.py install --home=$live || exit 1 cd .. rm domainmodel-$dm_version.tar.gz rm -rf domainmodel-$dm_version echo "Fetching Provide distribution..." sleep 1 wget -O provide-$provide_version.tar.gz http://appropriatesoftware.net/provide/docs/provide-$provide_version.tar.gz || exit 1 echo "Installing Provide..." sleep 1 tar zxvf provide-$provide_version.tar.gz cd provide-$provide_version python setup.py install --home=$live || exit 1 cd .. rm provide-$provide_version.tar.gz rm -rf provide-$provide_version cd $live echo "Copying new config file..." sleep 1 cp etc/provide.conf.new etc/provide.conf echo "Setting config file paths..." sleep 1 perl -pi -e "s|/path/to/provide|$live|" etc/provide.conf perl -pi -e "s|^name = provide\S*|name = provide-$provide_version|" etc/provide.conf perl -pi -e "s|^user = provide|user = $dbuser|" etc/provide.conf perl -pi -e "s|^password = pass|password = $dbpass|" etc/provide.conf perl -pi -e "s|^domain_name = provide\.your\.domain|domain_name = $domain|" etc/provide.conf perl -pi -e "s|^secret_key = \S+|secret_key = $secret|" etc/provide.conf echo "Opening new config file (please check the values)..." sleep 3 editor etc/provide.conf echo "Setting environment variables..." sleep 1 export PYTHONPATH=$live/lib/python export PROVIDE_SETTINGS=$live/etc/provide.conf export PATH=$live/bin:$PATH echo "Searching for 'provide' program...." which provide || echo "Error: Can't find the 'provide' program on your system. :-(" echo "Creating model persistence..." sleep 1 provide db create || exit 1 echo "Initialising model..." sleep 1 provide db init || exit 1 echo "" echo "Provide installed OK. Thanks for using Provide." echo "" echo "Please paste these variables in your environment configuration:" sleep 1 echo "" echo "export PROVIDE_SETTINGS=$live/etc/provide.conf" echo "export PYTHONPATH=$live/lib/python" echo "export PATH=$live/bin:\$PATH" echo "" echo "Then you can run the provide commands:" echo "" echo "provide scripts scanbooker 0.17" echo "" echo "provide-scanbooker-init" echo "provide-scanbooker-0.17-init" echo "provide-scanbooker-0.17-accept" echo "provide-scanbooker-0.17-production" echo "" echo "This would initialise a ScanBooker application service provision," echo "aquire relase 0.17, and then test and deploy a production services." sleep 1