diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-27 10:11:27 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-01-27 10:11:27 +0100 |
commit | de3147527cae11e78677ed876f828cff8187d185 (patch) | |
tree | c07c2d1198c8dba89d96b3f8a8552735d62e4718 | |
parent | c97cabe1358ba0186461f90f13c9e831d20cdb7c (diff) | |
download | Chimère-master-install.tar.bz2 Chimère-master-install.zip |
Workon on installmaster-install
-rwxr-xr-x | bin/chimere-create-instance | 267 | ||||
-rwxr-xr-x | bin/chimere-install (renamed from bin/install-chimere.sh) | 4 |
2 files changed, 269 insertions, 2 deletions
diff --git a/bin/chimere-create-instance b/bin/chimere-create-instance new file mode 100755 index 0000000..f20b36e --- /dev/null +++ b/bin/chimere-create-instance @@ -0,0 +1,267 @@ +#!/bin/bash + +# +# You can call this file interactively or pass environment variables. +# Available environment variable: +# * CONF_FILE - for an alternate configuration file - default: /etc/chimere/config +# * INSTANCE_NAME - name of the instance - mandatory for a non interactive call +# * URL - url - mandatory for a non interactive call +# + +conf_file=${CONF_FILE-"/etc/chimere/config"} + +if [ ! -e "$conf_file" ]; then + echo $conf_file" is not a valid configuration file. You should run chimere-install script before this one." + echo "If your configuration file is not at the standard place. Overload the default place with the environment variable: \"CONF_FILE\" " + echo "" + exit 1 +fi + +instance_name=${INSTANCE_NAME-""} + +if [ "$instance_name" == '' ]; then + cat >&2 <<-'EOF' + + ------------------------------------------------------------------------------- + You should provide an instance name for new instance Chimère. This name + should be in lower case, no special characters, no spaces. Underscores and + number are possible but not as first character. + + EOF + while [ "$instance_name" == '' ] + do + read -p "* What is your instance name? " choice + if [ "$choice" != '' ]; then + instance_name=$choice + fi + done +fi + +url=${URL-""} + +if [ "$url" == '' ]; then + cat >&2 <<-'EOF' + + ------------------------------------------------------------------------------- + Chimère uses a virtual host configuration. A specific hostname should be + provided, it will be the root of URLs for your website. + For instance, you should set "my_chimere.my_domain.net" to have a + Chimère responding to "http://my_chimere.my_domain.net/". + + Of course DNS configuration should be done to match this hostname with + this server. + + EOF + while [ "$url" == '' ] + do + read -p "* What hostname should be used? " choice + if [ "$choice" != '' ]; then + url=$choice + fi + done +fi + +source $conf_file + +DB_PORT=${DB_PORT-5432} + +UWSGI_PORT=${LAST_UWSGI_PORT-8891} + +# if a virtualenv is used put the full path of the python to use +PYTHON=python + + +# default for debian +UWSGI_AVAILABLE_PATH='/etc/uwsgi/apps-available/' +UWSGI_ENABLE_PATH='/etc/uwsgi/apps-enabled/' +NGINX_AVAILABLE_PATH='/etc/nginx/sites-available/' +NGINX_ENABLE_PATH='/etc/nginx/sites-enabled/' + + +echo "* installing dependencies" + +DB_PASSWORD=`apg -a 0 -M ncl -n 6 -x 10 -m 10 |head -n 1` + +DB_NAME='ishtar'$APP_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 + echo " * create template_postgis" + 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 + echo " * create "$DB_NAME + 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 ' * ishtar' +git clone https://gitlab.com/iggdrasil/ishtar.git 2> /dev/null +# echo ' * oook!' +# git clone git://git.proxience.com/git/oook_replace.git 2> /dev/null +# ln -s $INSTALL_PATH'/oook_replace/oook_replace' $INSTALL_PATH'/ishtar/' + +cd ishtar +git fetch 2> /dev/null +git checkout $VERSION 2> /dev/null + +cd django-simple-history +python setup.py install +cd .. + +cp -ra example_project $APP_NAME 2> /dev/null > /dev/null + +rm $APP_NAME/settings.py +ln -s $INSTALL_PATH"/ishtar/example_project/settings.py" $INSTALL_PATH"/ishtar/"$APP_NAME"/" + +APP_DIR=$INSTALL_PATH'/ishtar/'$APP_NAME + +echo '* load parameters' +sed -s "s|#APP_NAME#|$APP_NAME|g;\ + s|#INSTALL_PATH#|$INSTALL_PATH|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 -p "$APP_DIR/media/imported" +mkdir -p "$APP_DIR/media/upload" +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-'$APP_NAME'.log' +chown root:www-data '/var/log/django/ishtar-'$APP_NAME'.log' +chmod g+w '/var/log/django/ishtar-'$APP_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|#APP_NAME#|$APP_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#APP_NAME#/$APP_NAME/g;" $CDIR'/django.wsgi.template' > \ + $INSTALL_PATH'/conf/'$APP_NAME'.wsgi' + +ln -s $INSTALL_PATH'/conf/uwsgi.ini' \ + $UWSGI_AVAILABLE_PATH$APP_NAME'.ini' +ln -s $UWSGI_AVAILABLE_PATH$APP_NAME'.ini' \ + $UWSGI_ENABLE_PATH$APP_NAME'.ini' + +service uwsgi restart + +echo '* nginx configuration' + + +sed -s "s|#APP_NAME#|$APP_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' \ + $NGINX_AVAILABLE_PATH$APP_NAME'.conf' +ln -s $NGINX_AVAILABLE_PATH$APP_NAME'.conf' \ + $NGINX_ENABLE_PATH$APP_NAME'.conf' + +service nginx restart + diff --git a/bin/install-chimere.sh b/bin/chimere-install index 3b0b1c6..e5c36f9 100755 --- a/bin/install-chimere.sh +++ b/bin/chimere-install @@ -252,7 +252,7 @@ EOF ------------------------------------------------------------------------------- By default Chimère base path is '/srv/'. With this base path Chimère is - installed in '/srv/chimere/choosen_version/'. + installed in '/srv/chimere/'. EOF while [ "$install_path" == '' ] @@ -308,7 +308,7 @@ EOF export DEBIAN_FRONTEND=noninteractive ( set -x; $sh_c 'sleep 3; apt-get update' ) - if [ "$default_db" == 'localhost' ]; then + if [ "$default_db" == '127.0.0.1' ]; then echo "-------------------------------------------------------------------------------"; echo "Installing postgresql..."; echo ""; |