summaryrefslogtreecommitdiff
path: root/install/install.sh
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-04-17 19:30:20 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2015-04-17 19:33:43 +0200
commite3a061f50b538e88884a0e89b99d40f6a0e193c3 (patch)
tree9111c25f355c8b5f4d4d612a52505af3c5cf04fd /install/install.sh
parent00f6c7380ed4ec9c578cca5dd93cae0b92c57b10 (diff)
downloadIshtar-e3a061f50b538e88884a0e89b99d40f6a0e193c3.tar.bz2
Ishtar-e3a061f50b538e88884a0e89b99d40f6a0e193c3.zip
Install scripts
Diffstat (limited to 'install/install.sh')
-rw-r--r--install/install.sh254
1 files changed, 254 insertions, 0 deletions
diff --git a/install/install.sh b/install/install.sh
new file mode 100644
index 000000000..dc2bb9b2a
--- /dev/null
+++ b/install/install.sh
@@ -0,0 +1,254 @@
+#!/bin/bash
+
+######################################################################
+# Minimum configuration #
+######################################################################
+
+# only lower alpha-numeric char and '_' and must start with a letter
+[ $SHORT_NAME ] || ( echo 'SHORT_NAME empty. Default to: "default".' ; );
+SHORT_NAME=${SHORT_NAME-default}
+
+[ $URL ] || ( echo 'URL empty. Default to: "localhost".' ; URL=localhost ; );
+URL=${URL-localhost}
+
+[ $PROJECT_NAME ] || ( echo 'PROJECT_NAME empty. Default to: "Test".' ; );
+PROJECT_NAME=${PROJECT_NAME-Test}
+
+DEFAULT_DATA='fr' # available data: 'fr'
+
+######################################################################
+# Advanced configuration #
+######################################################################
+
+# if the database is not local the database will be not automatically
+# created
+[ $DB_HOST ] || ( echo 'DB_HOST empty. Default to: "127.0.0.1".' ; );
+DB_HOST=${DB_HOST-127.0.0.1}
+
+# if not set automatically generated
+DB_PASSWORD=''
+DB_PORT='5432'
+PG_VERSION=9.1
+
+# ishtar git branch
+[ $VERSION ] || ( echo 'VERSION empty. Default to: "new-stable".' ; );
+VERSION=new-stable
+
+# change it for each instance on a same server
+UWSGI_PORT=8891
+
+# webserver port - default "[::]:80"
+NGINX_PORT="[::]:80"
+if [ $URL = 'localhost' ]; then
+ # don't clash with default server on localhost
+ NGINX_PORT="[::]:8080"
+fi
+
+# don't forget the trailing slash
+INSTALL_PREFIX=/srv/
+
+# if a virtualenv is used put the full path of the python to use
+PYTHON=python
+
+# Don't edit below this line
+######################################################################
+
+echo "* installing dependencies"
+
+if [ $DB_HOST = "127.0.0.1" ]; then
+ apt-get -q -y install postgresql postgresql-$PG_VERSION-postgis postgresql 2> /dev/null > /dev/null
+fi
+
+apt-get -q -y install git apg python-pip 2> /dev/null > /dev/null
+
+apt-get -q -y install python python-django \
+ libjs-jquery libjs-jquery-ui python-pisa python-django-registration \
+ python-utidylib python-lxml python-imaging python-django-south \
+ python-psycopg2 python-gdal gettext \
+ python-django-extra-views python-memcache python-dbf 2> /dev/null > /dev/null
+
+apt-get -q -y install uwsgi uwsgi-plugin-python nginx memcached 2> /dev/null > /dev/null
+
+pip install git+https://github.com/treyhunner/django-simple-history.git@0fd9b8e9c6f36b0141367b502420efe92d4e21ce 2> /dev/null > /dev/null
+
+if [ -z "$DB_PASSWORD" ]
+then
+
+DB_PASSWORD=`apg -a 0 -M ncl -n 6 -x 10 -m 10 |head -n 1`
+
+fi
+
+DB_NAME='ishtar'$SHORT_NAME
+INSTALL_PATH=$INSTALL_PREFIX$DB_NAME
+DATE=`date +%F`
+CDIR=`pwd`
+SECRET_KEY=`apg -a 0 -M ncl -n 6 -x 10 -m 40 |head -n 1`
+
+if [ $DB_HOST = '127.0.0.1' ]
+then
+
+echo "* create database and user"
+DB_PASSWORD=$DB_PASSWORD DB_NAME=$DB_NAME PROJECT_NAME=$PROJECT_NAME PG_VERSION=$PG_VERSION su postgres <<'EOF'
+cd
+if [ `psql -l | grep template_postgis | wc -l` -ne 1 ]; then
+ createdb template_postgis
+ psql -d template_postgis -f /usr/share/postgresql/$PG_VERSION/contrib/postgis-1.5/postgis.sql 2> /dev/null > /dev/null
+ psql -d template_postgis -f /usr/share/postgresql/$PG_VERSION/contrib/postgis-1.5/spatial_ref_sys.sql 2> /dev/null > /dev/null
+
+fi
+if [ `psql -l | grep $DB_NAME | wc -l` -ne 1 ]; then
+ createuser --echo --adduser --createdb --encrypted $DB_NAME 2> /dev/null > /dev/null
+ psql --command "ALTER USER "$DB_NAME" with password '"$DB_PASSWORD"';" 2> /dev/null > /dev/null
+ createdb -T template_postgis --echo --owner $DB_NAME --encoding UNICODE $DB_NAME "$PROJECT_NAME" 2> /dev/null > /dev/null
+
+fi
+EOF
+
+fi
+
+
+echo '* get sources'
+
+mkdir $INSTALL_PATH
+mkdir $INSTALL_PATH'/conf'
+cd $INSTALL_PATH
+
+echo ' * oook!'
+git clone git://git.proxience.net/git/oook_replace.git 2> /dev/null
+echo ' * ishtar'
+git clone git://git.proxience.net/git/ishtar.git 2> /dev/null
+cd ishtar
+git fetch 2> /dev/null
+git checkout $VERSION 2> /dev/null
+
+cp -ra example_project $SHORT_NAME 2> /dev/null > /dev/null
+
+rm $SHORT_NAME/settings.py
+ln -s $INSTALL_PATH"/example_project/settings.py" $INSTALL_PATH"/"$SHORT_NAME"/"
+
+APP_DIR=$INSTALL_PATH'/ishtar/'$SHORT_NAME
+
+echo '* load parameters'
+
+sed -s "s/#SHORT_NAME#/$SHORT_NAME/g;\
+ s/#DATE#/$DATE/g;\
+ s/#PROJECT_NAME#/$PROJECT_NAME/g;\
+ s/#DB_HOST#/$DB_HOST/g;\
+ s/#DB_NAME#/$DB_NAME/g;\
+ s/#DB_PORT#/$DB_PORT/g;\
+ s/#APP_DIR#/$APP_DIR/g;\
+ s/#SECRET_KEY#/$SECRET_KEY/g;\
+ s/#DB_PASSWORD#/$DB_PASSWORD/g;\
+ s/#UWSGI_PORT#/$UWSGI_PORT/g;" $CDIR'/local_settings.py.sample' > \
+ $INSTALL_PATH'/conf/local_settings.py'
+
+ln -s $INSTALL_PATH'/conf/local_settings.py' $APP_DIR'/local_settings.py'
+
+# rights
+mkdir $APP_DIR'/media'
+chown -R root:www-data $APP_DIR'/media'
+chmod -R g+w $APP_DIR'/media'
+
+# logs
+mkdir -p /var/log/django/
+chown root:www-data '/var/log/django'
+touch '/var/log/django/ishtar-'$SHORT_NAME'.log'
+chown root:www-data '/var/log/django/ishtar-'$SHORT_NAME'.log'
+chmod g+w '/var/log/django/ishtar-'$SHORT_NAME'.log'
+
+cd $APP_DIR
+./manage.py collectstatic --noinput 2> /dev/null > /dev/null
+
+# load locale data
+
+cd $INSTALL_PATH'/ishtar/archaeological_context_records'
+django-admin compilemessages -l fr 2> /dev/null
+cd $INSTALL_PATH'/ishtar/archaeological_files'
+django-admin compilemessages -l fr 2> /dev/null
+cd $INSTALL_PATH'/ishtar/archaeological_finds'
+django-admin compilemessages -l fr 2> /dev/null
+cd $INSTALL_PATH'/ishtar/archaeological_operations'
+django-admin compilemessages -l fr 2> /dev/null
+cd $INSTALL_PATH'/ishtar/archaeological_warehouse'
+django-admin compilemessages -l fr 2> /dev/null
+cd $INSTALL_PATH'/ishtar/ishtar_common'
+django-admin compilemessages -l fr 2> /dev/null
+
+echo "* sync database"
+
+cd $APP_DIR
+python ./manage.py syncdb --noinput 2> /dev/null > /dev/null
+python ./manage.py migrate ishtar_common 2> /dev/null > /dev/null
+python ./manage.py migrate archaeological_files 0013 2> /dev/null > /dev/null
+python ./manage.py migrate archaeological_operations 2> /dev/null > /dev/null
+python ./manage.py migrate archaeological_files 2> /dev/null > /dev/null
+python ./manage.py migrate 2> /dev/null > /dev/null
+
+echo "* load default data"
+# data migrations have created some default data - return to a clean state
+python ./manage.py flush --noinput 2> /dev/null
+
+python ./manage.py loaddata \
+ '../fixtures/initial_data-auth-'$DEFAULT_DATA'.json' 2> /dev/null
+python ./manage.py loaddata \
+ '../ishtar_common/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null
+python ./manage.py loaddata \
+ '../ishtar_common/fixtures/initial_towns-'$DEFAULT_DATA'.json' 2> /dev/null
+python ./manage.py loaddata \
+ '../archaeological_operations/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null
+python ./manage.py loaddata \
+ '../archaeological_files/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null
+python ./manage.py loaddata \
+ '../archaeological_context_records/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null
+python ./manage.py loaddata \
+ '../archaeological_finds/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null
+python ./manage.py loaddata \
+ '../archaeological_warehouse/fixtures/initial_data-'$DEFAULT_DATA'.json' 2> /dev/null
+
+echo "* create superuser"
+python ./manage.py createsuperuser
+
+# "de-flush" migrations
+$PYTHON ./manage.py migrate --fake 2> /dev/null > /dev/null
+
+# add a default site
+echo '[{"pk":null, "model": "sites.site", "fields": {"domain": "'$URL'", "name": "'$PROJECT_NAME'"}}]' > \
+ /tmp/site.json
+python ./manage.py loaddata /tmp/site.json
+rm /tmp/site.json
+
+echo '* uwsgi configuration'
+
+sed -s "s/#SHORT_NAME#/$SHORT_NAME/g;\
+ s/#DB_NAME#/$DB_NAME/g;\
+ s/#URL#/$URL/g;\
+ s/#UWSGI_PORT#/$UWSGI_PORT/g;" $CDIR'/uwsgi.ini.template' > \
+ $INSTALL_PATH'/conf/uwsgi.ini'
+
+sed -s "s/#SHORT_NAME#/$SHORT_NAME/g;" $CDIR'/django.wsgi.template' > \
+ $INSTALL_PATH'/conf/'$SHORT_NAME'.wsgi'
+
+ln -s $INSTALL_PATH'/conf/uwsgi.ini' \
+ '/etc/uwsgi/apps-available/'$SHORT_NAME'-uwsgi.ini'
+ln -s '/etc/uwsgi/apps-available/'$SHORT_NAME'-uwsgi.ini' \
+ '/etc/uwsgi/apps-enabled/'$SHORT_NAME'-uwsgi.ini'
+
+service uwsgi restart
+
+echo '* nginx configuration'
+
+
+sed -s "s/#SHORT_NAME#/$SHORT_NAME/g;\
+ s/#UWSGI_PORT#/$UWSGI_PORT/g;\
+ s/#DB_NAME#/$DB_NAME/g;\
+ s/#DATE#/$DATE/g;\
+ s/#NGINX_PORT#/$NGINX_PORT/g;\
+ s/#URL#/$URL/g;" $CDIR'/nginx.conf.template' > \
+ $INSTALL_PATH'/conf/nginx.conf'
+ln -s $INSTALL_PATH'/conf/nginx.conf' \
+ '/etc/nginx/sites-available/'$SHORT_NAME'.conf'
+ln -s '/etc/nginx/sites-available/'$SHORT_NAME'.conf' \
+ '/etc/nginx/sites-enabled/'$SHORT_NAME'.conf'
+
+service nginx restart
+