diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-05-01 21:05:11 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-05-01 21:05:11 +0200 |
commit | 183591d0e09272c0eadb2fc928370ccd965bfd91 (patch) | |
tree | 7609fc700402e10f7fe27a2c7df751d6c8dc8a71 | |
parent | e0cc2800330d92ad577384ea72659427918f589d (diff) | |
download | Ishtar-183591d0e09272c0eadb2fc928370ccd965bfd91.tar.bz2 Ishtar-183591d0e09272c0eadb2fc928370ccd965bfd91.zip |
Update installation scripts
-rw-r--r-- | example_project/settings.py | 3 | ||||
-rw-r--r-- | install/README | 15 | ||||
-rwxr-xr-x | install/install.sh | 271 | ||||
-rwxr-xr-x | install/ishtar-delete-instance | 85 | ||||
-rwxr-xr-x[-rw-r--r--] | install/ishtar-install (renamed from install/install-ishtar.sh) | 31 | ||||
-rwxr-xr-x | install/ishtar-prepare-instance | 321 | ||||
-rw-r--r-- | install/local_settings.py.sample | 12 | ||||
-rw-r--r-- | install/nginx.conf.template | 6 | ||||
-rwxr-xr-x | install/uninstall.sh | 36 | ||||
-rw-r--r-- | install/uwsgi.ini.template | 2 |
10 files changed, 437 insertions, 345 deletions
diff --git a/example_project/settings.py b/example_project/settings.py index ea7aa48fc..2e91cb73f 100644 --- a/example_project/settings.py +++ b/example_project/settings.py @@ -228,9 +228,6 @@ ISHTAR_DOC_TYPES = {u"undefined": u"Undefined"} ISHTAR_DPTS = [] -PRE_APPS = [] -EXTRA_APPS = [] - TEST_RUNNER = 'ishtar_common.tests.ManagedModelTestRunner' try: diff --git a/install/README b/install/README index dc15fa147..d21f7fc2b 100644 --- a/install/README +++ b/install/README @@ -1,9 +1,16 @@ -cd /tmp +cd /usr/local/src apt-get install wget -wget http://lysithea.proxience.net/ishtar-install.tar.gz +wget MAIN_ADDRESS/ishtar-install.tar.gz tar xvzf ishtar-install.tar.gz rm ishtar-install.tar.gz cd install -export APP_NAME=myinstance && export URL=localhost \ - && export PROJECT_NAME="Project name" && bash install.sh + +#### install + +bash ishtar-install +bash ishtar-prepare-instance + +#### delete + +bash ishtar-delete-instance diff --git a/install/install.sh b/install/install.sh deleted file mode 100755 index 7a9a55bd7..000000000 --- a/install/install.sh +++ /dev/null @@ -1,271 +0,0 @@ -#!/bin/bash - -###################################################################### -# Minimum configuration # -###################################################################### - -# only lower alpha-numeric char and '_' and must start with a letter -[ -z "$APP_NAME" ] && ( echo 'APP_NAME empty. Default to: "default".' ; ); -APP_NAME=${APP_NAME-default} - -[ -z $URL ] && ( echo 'URL empty. Default to: "localhost".' ; URL=localhost ; ); -URL=${URL-localhost} - -[ -z "$PROJECT_NAME" ] && ( echo 'PROJECT_NAME empty. Default to: "'$APP_NAME'".' ; ); -PROJECT_NAME=${PROJECT_NAME-$APP_NAME} - -DEFAULT_DATA='fr' # available data: 'fr' - -###################################################################### -# Advanced configuration # -###################################################################### - -# if the database is not local the database will be not automatically -# created -[ -z $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_PASSWORD-''} -DB_PORT='5432' -PG_VERSION=9.1 - -# ishtar git branch -[ -z "$VERSION" ] && ( echo 'VERSION empty. Default to: "stable".' ; ); -VERSION=${VERSION-stable} - -# change it for each instance on a same server -UWSGI_PORT=${UWSGI_PORT-8891} - -# webserver port - default "80" -NGINX_PORT=${NGINX_PORT-80} - -# 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 - -# proxy for pip -PIP_OPTIONS='' -[ -z "$http_proxy" ] || PIP_OPTIONS=' --proxy '$http_proxy; -[ -z "$HTTP_PROXY" ] || PIP_OPTIONS=' --proxy '$HTTP_PROXY; - -# 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/' - -# 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-bs4 python-tidylib \ - python-unicodecsv \ - 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$PIP_OPTIONS BeautifulSoup4==4.3.2 - -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'$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/install/ishtar-delete-instance b/install/ishtar-delete-instance new file mode 100755 index 000000000..f67770d4d --- /dev/null +++ b/install/ishtar-delete-instance @@ -0,0 +1,85 @@ +#!/bin/bash + +set -e + +do_delete_instance() { + NGINX_AVAILABLE_PATH='/etc/nginx/sites-available' + NGINX_ENABLE_PATH='/etc/nginx/sites-enabled' + UWSGI_AVAILABLE_PATH='/etc/uwsgi/apps-available' + UWSGI_ENABLE_PATH='/etc/uwsgi/apps-enabled' + + if [ ! -z '$CONFIG_PATH' ]; then + CONFIG_PATH="/etc/ishtar/" + fi + + if [ ! -f $CONFIG_PATH/config ]; then + echo ""; + echo ""$CONFIG_PATH" is not a valid config file." + echo "Have you properly install Ishtar sources?" + echo "Run ishtar-install before this script."; + echo ""; + exit 1; + fi + + source $CONFIG_PATH/config + + INSTANCES_FILE=$CONFIG_PATH/instances + if [ ! -f $INSTANCES_FILE ]; then + echo ""; + echo "No instance installated. Exiting." + echo ""; + exit 1; + fi + + cat >&2 <<-'EOF' + +******************************************************************************* +++++++ Ishtar instance deletion script ++++++ +******************************************************************************* + + Avalaible instances: + +EOF + + cat $INSTANCES_FILE + + to_delete='' + echo "" + while [ "$to_delete" == '' ] + do + read -p "* Which one would you like to delete? " choice + GRP=`cat $INSTANCES_FILE | grep "^$choice$"` + if [ "$GRP" != '' ]; then + to_delete=$choice + fi + done + echo "" + echo "Are you really sure to delete configuration, database and media attached to the " + echo "instance "$to_delete"?" + echo "" + read -p "* Type DELETE if you are sure: " choice + if [ "$choice" != "DELETE" ]; then + exit 1 + fi + + sed '/'$to_delete'/d' $INSTANCES_FILE > /tmp/new_instances + mv /tmp/new_instances $INSTANCES_FILE + + INSTANCE=$to_delete + rm -rf $ISHTAR_PATH/$INSTANCE + rm -f "$NGINX_AVAILABLE_PATH/ishtar-$INSTANCE.conf" + rm -f "$NGINX_ENABLE_PATH/ishtar-$INSTANCE.conf" + rm -f "$UWSGI_AVAILABLE_PATH/ishtar-$INSTANCE.ini" + rm -f "$UWSGI_ENABLE_PATH/ishtar-$INSTANCE.ini" + + DB_NAME="ishtar-$INSTANCE" + export DB_NAME + su postgres <<'EOF' + dropdb "$DB_NAME" + dropuser "$DB_NAME" +EOF + + echo $to_delete" have been completly removed" +} + +do_delete_instance diff --git a/install/install-ishtar.sh b/install/ishtar-install index 16e758c57..0d1b6d096 100644..100755 --- a/install/install-ishtar.sh +++ b/install/ishtar-install @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -e @@ -221,7 +221,7 @@ EOF esac done - etc_path="/etc/ishtar/"$version"/" + etc_path="/etc/ishtar/" if [ -d "$etc_path" ]; then echo "" echo "ERROR: it seems that "$etc_path" already exists. If this is a remnant " @@ -242,7 +242,7 @@ EOF do read -p "* Which base install path for Ishtar? [/srv/] " choice if [ -z "$choice" ]; then - install_path='/srv/' + install_path='/srv' elif [ ! -d "$choice" ]; then echo 'Not a valid path.' else @@ -304,11 +304,8 @@ EOF echo "-------------------------------------------------------------------------------"; if [ "$dist_version" == "wheezy" ]; then - if [ "$default_db" == 'localhost' ]; then + if [ "$default_db" == '127.0.0.1' ]; then POSTGIS=postgresql-9.1-postgis - if [ "$dist_version" == "jessie" ]; then - POSTGIS=postgresql-9.4-postgis-2.1 - fi ( set -x; $sh_c 'sleep 3; apt-get install -y -q postgresql '$POSTGIS ) fi @@ -346,18 +343,19 @@ EOF exit 1 fi - if [ "$default_db" == 'localhost' ]; then + if [ "$default_db" == '127.0.0.1' ]; then POSTGIS=postgresql-9.4-postgis-2.3 ( set -x; $sh_c 'sleep 3; apt-get install -y -q postgresql '$POSTGIS ) fi echo "Installing Ishtar dependencies" echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -t jessie-backports -y -q python python-django' ) + ( set -x; $sh_c 'sleep 3; apt-get install -t jessie-backports -y -q python python-django\ + python-django-registration' ) ( set -x; $sh_c 'sleep 3; apt-get install -y -q \ - python-pisa python-django-registration python-bs4 python-django-formtools\ - python-tidylib python-lxml python-imaging python-html5lib\ - python-psycopg2 python-gdal gettext python-unicodecsv memcached \ - python-django-extra-views python-memcache python-dbf python-markdown' ) + python-pisa python-bs4 python-django-formtools\ + python-tidylib python-lxml python-imaging python-html5lib\ + python-psycopg2 python-gdal gettext python-unicodecsv memcached \ + python-django-extra-views python-memcache python-dbf python-markdown' ) echo "Installing django-simple-history" echo ""; ( set -x; $sh_c 'pip install git+https://github.com/treyhunner/django-simple-history.git@1.8.2#egg=django-simple-history' ) @@ -382,9 +380,10 @@ EOF git checkout $version 2> /dev/null mkdir -p $etc_path - echo "PATH="$full_install_path > $etc_path"config" - echo "DEFAULT_DB="$default_db >> $etc_path"config" - echo "WEBSERVER="$webserver >> $etc_path"config" + echo "ISHTAR_PATH="$full_install_path'/ishtar/' > $etc_path"config" + echo "ISHTAR_DB="$default_db >> $etc_path"config" + echo "ISHTAR_WEBSERVER="$webserver >> $etc_path"config" + echo "# settings added to all instances" >> $etc_path"extra_settings.py" echo "" echo "*******************************************************************************"; echo ""; diff --git a/install/ishtar-prepare-instance b/install/ishtar-prepare-instance new file mode 100755 index 000000000..f35aa2b02 --- /dev/null +++ b/install/ishtar-prepare-instance @@ -0,0 +1,321 @@ +#!/bin/bash + +set -e + +do_install_instance() { + + NGINX_PORT=${NGINX_PORT-80} + NGINX_AVAILABLE_PATH='/etc/nginx/sites-available' + NGINX_ENABLE_PATH='/etc/nginx/sites-enabled' + UWSGI_AVAILABLE_PATH='/etc/uwsgi/apps-available' + UWSGI_ENABLE_PATH='/etc/uwsgi/apps-enabled' + PG_VERSION=9.4 + POSTGIS_VERSION=2.3.1 + + cat >&2 <<-'EOF' + +******************************************************************************* +++++++ Ishtar instance installation script ++++++ +******************************************************************************* + +EOF + + # check user + user="$(id -un 2>/dev/null || true)" + + sh_c='sh -c' + if [ "$user" != 'root' ]; then + if command_exists sudo; then + sh_c='sudo -E sh -c' + elif command_exists su; then + sh_c='su -c' + else + cat >&2 <<-'EOF' + Error: this installer needs the ability to run commands as root. + We are unable to find either "sudo" or "su" available to make this happen. +EOF + exit 1 + fi + fi + + export LANG=fr_FR.UTF-8 + if [ "$(locale 2>&1 >/dev/null|wc -l)" != 0 ]; then + echo "Unable to set LANG=$LANG properly" + echo "Try: 'dpkg-reconfigure locales' or install the 'locales-all' package" + exit 1 + fi + + if [ ! -z '$CONFIG_PATH' ]; then + CONFIG_PATH="/etc/ishtar/" + fi + + if [ ! -f $CONFIG_PATH/config ]; then + echo ""; + echo ""$CONFIG_PATH" is not a valid config file." + echo "Have you properly install Ishtar sources?" + echo "Run ishtar-install before this script."; + echo ""; + exit 1; + fi + + source $CONFIG_PATH/config + + cd $ISHTAR_PATH + + INSTANCES_FILE=$CONFIG_PATH/instances + + if [ ! -f $INSTANCES_FILE ]; then + touch $INSTANCES_FILE + fi + + if [ -z '$INSTANCE' ]; then + if [ -d "$INSTANCE" ]; then + echo "Sorry, $INSTANCE already exists. Give another name." + exit 1 + fi + + else + INSTANCE='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + You should select a code name for this instance. This code name should have + only lower alphanumeric characters, with no spaces, no accents and should not + begin with an alphabetical character. The only special character allowed is + "_". + +EOF + while [ "$INSTANCE" == '' ] + do + read -p "* Which instance code name? [my_ishtar_instance] " choice + if [ -z "$choice" ]; then + INSTANCE='my_ishtar_instance' + else + INSTANCE=$choice + fi + if [ -d "$INSTANCE" ]; then + echo "Sorry, $INSTANCE already exists. Give another name." + INSTANCE='' + fi + done + fi + + if [ ! -z '$URL' ]; then + URL='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + You should select an url to join your instance. Only a full domain is + accepted. Don't forget to set up your DNS to point this url name to this + server. Only put the url not the protocol part (no http://). + For instance: ishtar.mydomain.org + +EOF + while [ "$URL" == '' ] + do + read -p "* Which url? " choice + URL=$choice + done + fi + + DEST=$ISHTAR_PATH + + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- +EOF + echo "Preparing ishtar instance: $INSTANCE under $DEST" + echo "" + # register instance + echo "$INSTANCE" >> $INSTANCES_FILE + + mkdir -p /var/log/django + chown root:www-data /var/log/django + touch "/var/log/django/ishtar-$INSTANCE.log" + chown root:www-data "/var/log/django/ishtar-$INSTANCE.log" + chmod g+w "/var/log/django/ishtar-$INSTANCE.log" + + + echo " * duplicate example_project into our instance" + # Duplicate example_project into our instance: + cd $ISHTAR_PATH + cp -ra example_project $INSTANCE + + rm $INSTANCE/settings.py + ln -s $DEST/example_project/settings.py $DEST/$INSTANCE/settings.py + + # Permissions: + mkdir -p -m 755 "$INSTANCE/media" + mkdir -p -m 755 "$INSTANCE/media/imported" + mkdir -p -m 755 "$INSTANCE/media/upload" + chown -R www-data:www-data "$INSTANCE/media" + + # Preparing DB: + DB_HOST=${ISHTAR_DB-127.0.0.1} + DB_PORT=${ISHTAR_DB_PORT-5432} + DB_PASSWORD=${DB_PASSWORD-''} + DB_NAME="ishtar-$INSTANCE" + + # Generate a password on the fly if none was specified: + if [ -z "$DB_PASSWORD" ]; then + DB_PASSWORD=$(apg -a 0 -M ncl -n 1 -x 10 -m 10) + fi + + export PG_VERSION DB_HOST DB_PORT DB_PASSWORD DB_NAME POSTGIS_VERSION + su postgres <<'EOF' + echo " * Checking template_postgis" + if ! psql -l | grep -qs template_postgis; then + echo " - not present, creating" + createdb -E UTF8 template_postgis + psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE datname='template_postgis'" + psql -q -d template_postgis -f /usr/share/postgresql/$PG_VERSION/extensions/postgis--$POSTGIS_VERSION.sql + psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;" + psql -d template_postgis -c "GRANT ALL ON geography_columns TO PUBLIC;" + psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;" + else + echo " - already present" + fi + + echo " * Checking database $DB_NAME" + if ! psql -l | grep -qs "$DB_NAME"; then + echo " - not present, creating" + createuser --echo --adduser --createdb --encrypted $DB_NAME + psql --command "ALTER USER \""$DB_NAME"\" with password '"$DB_PASSWORD"';" + createdb -T template_postgis --echo --owner $DB_NAME --encoding UNICODE $DB_NAME + psql -d $DB_NAME -c "CREATE EXTENSION postgis;" + else + echo " - already present" + fi +EOF + + ### LOCAL SETTINGS + + echo " * creating config files" + # Set some variables to avoid changing sed calls too much compared to + # the initial install/install.sh script: + INSTALL_PATH=$DEST + INSTALL_PREFIX=$DEST + APP_DIR="$DEST/$INSTANCE" + DATE=`date +%F` + SECRET_KEY=$(apg -a 0 -M ncl -n 1 -x 10 -m 40) + + PORT_FILE=$CONFIG_PATH/last_uswgi_port + + if [ -f $PORT_FILE ]; then + UWSGI_PORT=`cat $PORT_FILE` + UWSGI_PORT=`expr $UWSGI_PORT + 1` + else + UWSGI_PORT=8889 + fi + echo $UWSGI_PORT > $PORT_FILE + + ### local_settings.py + + sed -s "s|#APP_NAME#|$INSTANCE|g;\ + s|#INSTALL_PATH#|$INSTALL_PATH|g;\ + s|#DB_HOST#|$DB_HOST|g;\ + s|#DB_NAME#|$DB_NAME|g;\ + s|#DB_PORT#|$DB_PORT|g;\ + s|#DB_PASSWORD#|$DB_PASSWORD|g;\ + s|#APP_DIR#|$APP_DIR|g;\ + s|#SECRET_KEY#|$SECRET_KEY|g;" \ + "install/local_settings.py.sample" > \ + "$INSTANCE/local_settings.py" + + if [ -f $CONFIG_PATH"extra_settings.py" ]; then + cat $CONFIG_PATH"extra_settings.py" >> "$INSTANCE/local_settings.py" + fi + + ### UWSGI + + sed -s "s|#APP_NAME#|$INSTANCE|g;\ + s|#INSTALL_PREFIX#|$INSTALL_PREFIX|g;\ + s|#URL#|$URL|g;\ + s|#UWSGI_PORT#|$UWSGI_PORT|g;" \ + "install/uwsgi.ini.template" > \ + "$INSTANCE/uwsgi.ini" + + ln -sf "$DEST/$INSTANCE/uwsgi.ini" \ + "$UWSGI_AVAILABLE_PATH/ishtar-$INSTANCE.ini" + ln -sf "$UWSGI_AVAILABLE_PATH/ishtar-$INSTANCE.ini" \ + "$UWSGI_ENABLE_PATH/ishtar-$INSTANCE.ini" + + ### NGINX + + sed -s "s|#APP_NAME#|$INSTANCE|g;\ + s|#UWSGI_PORT#|$UWSGI_PORT|g;\ + s|#DB_NAME#|$DB_NAME|g;\ + s|#DATE#|$DATE|g;\ + s|#NGINX_PORT#|$NGINX_PORT|g;\ + s|#INSTALL_PREFIX#|$INSTALL_PREFIX|g;\ + s|#URL#|$URL|g;" \ + "install/nginx.conf.template" > \ + "$INSTANCE/nginx.conf" + + ln -sf "$DEST/$INSTANCE/nginx.conf" \ + "$NGINX_AVAILABLE_PATH/ishtar-$INSTANCE.conf" + ln -sf "$NGINX_AVAILABLE_PATH/ishtar-$INSTANCE.conf" \ + "$NGINX_ENABLE_PATH/ishtar-$INSTANCE.conf" + + + echo " * collect static data" + cd $INSTANCE + ./manage.py collectstatic --noinput > /dev/null + cd - + + # only language available + LOCALE=fr + echo " * compile translations" + for d in archaeological_* ishtar_common; do + cd $d + ../$INSTANCE/manage.py compilemessages -l $LOCALE + cd - + done + + ### DB feeding + cd $INSTANCE + echo " * db feeding" + echo " - migrations" + ./manage.py migrate + + echo " - loading fixtures" + FIXTURES="$DEST/fixtures/initial_data-auth-fr.json $DEST/ishtar_common/fixtures/initial_data-fr.json $DEST/ishtar_common/fixtures/initial_importtypes-fr.json $DEST/archaeological_operations/fixtures/initial_data-fr.json $DEST/archaeological_context_records/fixtures/initial_data-fr.json $DEST/archaeological_files/fixtures/initial_data-fr.json $DEST/archaeological_finds/fixtures/initial_data-fr.json $DEST/archaeological_warehouse/fixtures/initial_data-fr.json" + for data in $FIXTURES; do + echo $data; + ./manage.py loaddata $data; + done + + echo " - create superuser" + ./manage.py createsuperuser + + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + Your instance has been configured. +EOF + echo " * instance name: "$INSTANCE + echo " * url: "$URL + + cat >&2 <<-'EOF' + + You should restart uwsgi and nginx: + systemctl restart uwsgi nginx + + And then enjoy ishtar! +EOF +} + +do_install_instance + + + + + + + + + + + + + diff --git a/install/local_settings.py.sample b/install/local_settings.py.sample index 459828c00..f7d8089d8 100644 --- a/install/local_settings.py.sample +++ b/install/local_settings.py.sample @@ -6,10 +6,8 @@ DEBUG_TOOLBAR = False TEMPLATE_DEBUG = DEBUG SQL_DEBUG = False -APP_NAME = u"#PROJECT_NAME#" -PROJECT_SLUG = u"#PROJECT_NAME#" +PROJECT_SLUG = "#APP_NAME#" ROOT_URLCONF = '#APP_NAME#.urls' -STATIC_URL = '/static-#DATE#/' SECRET_KEY = "#SECRET_KEY#" LOGFILE = "/var/log/django/ishtar-#APP_NAME#.log" @@ -33,11 +31,3 @@ DATABASES = { 'PASSWORD': '#DB_PASSWORD#', } } - -# choose the extensions to install -EXTRA_APPS = [ - 'archaeological_files', - 'archaeological_context_records', - 'archaeological_warehouse', - 'archaeological_finds', -] diff --git a/install/nginx.conf.template b/install/nginx.conf.template index dd236d113..3450671b9 100644 --- a/install/nginx.conf.template +++ b/install/nginx.conf.template @@ -1,18 +1,18 @@ server { listen #NGINX_PORT#; server_name #URL#; - root /srv/#DB_NAME#/ishtar/; + root #INSTALL_PATH#; access_log /var/log/django/#APP_NAME#-access.log; error_log /var/log/django/#APP_NAME#-error.log; client_max_body_size 20M; location /static-#DATE#/ { # STATIC_URL - alias /srv/#DB_NAME#/ishtar/#APP_NAME#/static/; # STATIC_ROOT + alias #INSTALL_PATH#/#APP_NAME#/static/; # STATIC_ROOT expires 30d; } location /media/ { # MEDIA_URL - alias /srv/#DB_NAME#/ishtar/#APP_NAME#/media/; # MEDIA_ROOT + alias #INSTALL_PATH#/#APP_NAME#/media/; # MEDIA_ROOT expires 30d; } diff --git a/install/uninstall.sh b/install/uninstall.sh deleted file mode 100755 index 71a5dae17..000000000 --- a/install/uninstall.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# only lower alpha-numeric char and '_' and must start with a letter -[ $APP_NAME ] || ( echo 'APP_NAME empty. Default to: "default".' ; ); -APP_NAME=${APP_NAME-default} -# don't forget the trailing slash -INSTALL_PREFIX=/srv/ - -read -r -p "Are you sure to delete "$APP_NAME" app? [y/N] " response -response=${response,,} # tolower -if [[ $response =~ ^(yes|y)$ ]] -then - echo '* deleting '$APP_NAME; -else - echo "canceled"; - exit; -fi - -# 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/' - -DB_NAME='ishtar'$APP_NAME -INSTALL_PATH=$INSTALL_PREFIX$DB_NAME - -rm -f $UWSGI_AVAILABLE_PATH$APP_NAME'.ini' -rm -f $UWSGI_ENABLE_PATH$APP_NAME'.ini' -rm -f $NGINX_AVAILABLE_PATH$APP_NAME'.conf' -rm -f $NGINX_ENABLE_PATH$APP_NAME'.conf' - -rm -rf $INSTALL_PATH - -echo "All file cleaned." -echo "You can delete database '"$DB_NAME"' to fully clean your installation." diff --git a/install/uwsgi.ini.template b/install/uwsgi.ini.template index 7a20c058c..51a4c5b7f 100644 --- a/install/uwsgi.ini.template +++ b/install/uwsgi.ini.template @@ -2,7 +2,7 @@ # variables projectname = #APP_NAME# projectdomain = #URL# -base = /srv/#DB_NAME#/ishtar/ +base = #INSTALL_PREFIX# # config plugins = python |