From e596b6ad2b6a50c223efeaca14e8a16e2237285f Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 1 May 2017 21:05:11 +0200 Subject: Update installation scripts --- example_project/settings.py | 3 - install/README | 15 +- install/install-ishtar.sh | 398 --------------------------------------- install/install.sh | 271 -------------------------- install/ishtar-delete-instance | 85 +++++++++ install/ishtar-install | 397 ++++++++++++++++++++++++++++++++++++++ install/ishtar-prepare-instance | 321 +++++++++++++++++++++++++++++++ install/local_settings.py.sample | 12 +- install/nginx.conf.template | 6 +- install/uninstall.sh | 36 ---- install/uwsgi.ini.template | 2 +- 11 files changed, 819 insertions(+), 727 deletions(-) delete mode 100644 install/install-ishtar.sh delete mode 100755 install/install.sh create mode 100755 install/ishtar-delete-instance create mode 100755 install/ishtar-install create mode 100755 install/ishtar-prepare-instance delete mode 100755 install/uninstall.sh 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-ishtar.sh b/install/install-ishtar.sh deleted file mode 100644 index 16e758c57..000000000 --- a/install/install-ishtar.sh +++ /dev/null @@ -1,398 +0,0 @@ -#!/bin/sh - -set -e - -command_exists() { - command -v "$@" > /dev/null 2>&1 -} - -# Check if this is a forked Linux distro -check_forked() { - # Check for lsb_release command existence, it usually exists in forked distros - if command_exists lsb_release; then - # Check if the `-u` option is supported - set +e - lsb_release -a -u > /dev/null 2>&1 - lsb_release_exit_code=$? - set -e - - # Check if the command has exited successfully, it means we're in a forked distro - if [ "$lsb_release_exit_code" = "0" ]; then - # Print info about current distro - cat <<-EOF - You're using '$lsb_dist' version '$dist_version'. -EOF - - # Get the upstream release info - lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]') - dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]') - - # Print info about upstream distro - cat <<-EOF - Upstream release is '$lsb_dist' version '$dist_version'. -EOF - fi - fi -} - -do_install() { - - cat >&2 <<-'EOF' - -******************************************************************************* -++++++ Ishtar 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 - - # check distribution - lsb_dist='' - dist_version='' - backports_activated='' - if command_exists lsb_release; then - lsb_dist="$(lsb_release -si)" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then - lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" - fi - if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then - lsb_dist='debian' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then - lsb_dist='fedora' - fi - if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then - lsb_dist='oracleserver' - fi - if [ -z "$lsb_dist" ]; then - if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then - lsb_dist='centos' - fi - fi - if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then - lsb_dist="$(. /etc/os-release && echo "$ID")" - fi - - lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" - - case "$lsb_dist" in - - ubuntu) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then - dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" - fi - ;; - - debian) - MAINBACKS=`cat /etc/apt/sources.list | grep jessie-backports |grep -v "^#"` - ALLBACKS='' - if [ "$(ls -A /etc/apt/sources.list.d/)" ]; then - ALLBACKS=`cat /etc/apt/sources.list.d/* | grep jessie-backports |grep -v "^#"` - fi - if [ "$ALLBACKS" != '' ] || [ "$MAINBACKS" != '' ]; then - backports_activated='true'; - fi - dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" - case "$dist_version" in - 8) - dist_version="jessie" - ;; - 7) - dist_version="wheezy" - ;; - esac - ;; - - oracleserver) - # need to switch lsb_dist to match yum repo URL - lsb_dist="oraclelinux" - dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" - ;; - - fedora|centos) - dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" - ;; - - *) - if command_exists lsb_release; then - dist_version="$(lsb_release --codename | cut -f2)" - fi - if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then - dist_version="$(. /etc/os-release && echo "$VERSION_ID")" - fi - ;; - - - esac - - # Check if this is a forked Linux distro - check_forked - - case "$lsb_dist" in - ubuntu|debian) - ;; - *) - cat >&2 <<-'EOF' - - Sorry. Either your platform is not easily detectable or not supported by - this installer. - -EOF - exit 1 - esac - - default_db='' - cat >&2 <<-'EOF' - -------------------------------------------------------------------------------- - A PostgreSQL database is needed to install Ishtar. If you do not plan to use - a database host on another computer you need to install PostgreSQL. - -EOF - while [ "$default_db" == '' ] - do - read -p '* Default PostgreSQL host? [localhost] ' choice - if [ "$choice" == '' ]; then - default_db='127.0.0.1' - elif [ "$choice" == 'localhost' ]; then - default_db='127.0.0.1' - else - default_db=$choice - fi - done - - webserver='' - cat >&2 <<-'EOF' - -------------------------------------------------------------------------------- - A webserver is needed to make Ishtar available to the outside. - Be carreful if another webserver is already configured, you'll have to serve - your pages on a different port. - -EOF - MSG="" - while [ "$webserver" == '' ] - do - read -p '* Which webserver do you want to use? ([nginx]/none) ' choice - case "$choice" in - nginx ) webserver="nginx";; - none ) webserver="none";; - '' ) webserver="nginx";; - esac - done - - version='' - cat >&2 <<-'EOF' - -------------------------------------------------------------------------------- - Two version are usually available for Ishtar: develop/master. Develop is the - bleeding edge version and you can experience problems with this version. - Master is the safest choice. - -EOF - while [ "$version" == '' ] - do - read -p "* Which version would you like to use? ([develop]/master) " choice - case "$choice" in - develop ) version="develop";; - master ) version="master";; - '' ) version="develop";; - esac - done - - etc_path="/etc/ishtar/"$version"/" - if [ -d "$etc_path" ]; then - echo "" - echo "ERROR: it seems that "$etc_path" already exists. If this is a remnant " - echo "of an old installation please delete this path before installing." - exit 1 - fi - - - install_path='' - cat >&2 <<-'EOF' - -------------------------------------------------------------------------------- - By default Ishtar base path is '/srv/'. With this base path Ishtar is - installed in '/srv/ishtar/choosen_version/'. - -EOF - while [ "$install_path" == '' ] - do - read -p "* Which base install path for Ishtar? [/srv/] " choice - if [ -z "$choice" ]; then - install_path='/srv/' - elif [ ! -d "$choice" ]; then - echo 'Not a valid path.' - else - install_path=$choice - fi - done - - full_install_path=$install_path'/ishtar/'$version - if [ -d "$full_install_path" ]; then - echo "" - echo "ERROR: it seems that "$full_install_path" already exists. If this is a " - echo "remnant of an old installation please delete this directory before installing." - exit 1 - fi - - echo "" - echo "*******************************************************************************" - echo "" - - # Run setup for each distro accordingly - case "$lsb_dist" in - ubuntu|debian) - if [ "$dist_version" != "jessie" ] && [ "$dist_version" != "wheezy" ]; then - cat >&2 <<-'EOF' - - Sorry this script cannot manage your version of Debian/Ubuntu. - -EOF - exit 1 - fi - - export DEBIAN_FRONTEND=noninteractive - ( set -x; $sh_c 'sleep 3; apt-get update' ) - if ! command_exists git; then - echo "-------------------------------------------------------------------------------"; - echo "Installing git..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q git' ) - fi - if ! command_exists apg; then - echo "-------------------------------------------------------------------------------"; - echo "Installing apg..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q apg' ) - fi - if ! command_exists pip; then - echo "-------------------------------------------------------------------------------"; - echo "Installing pip..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q python-pip' ) - fi - if [ "$webserver" == 'nginx' ]; then - echo "-------------------------------------------------------------------------------"; - echo "Installing nginx and uwsgi..."; - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q uwsgi uwsgi-plugin-python nginx' ) - fi - - echo "-------------------------------------------------------------------------------"; - - if [ "$dist_version" == "wheezy" ]; then - if [ "$default_db" == 'localhost' ]; 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 - - echo "-------------------------------------------------------------------------------"; - echo "Installing Ishtar dependencies" - echo ""; - ( set -x; $sh_c 'sleep 3; apt-get install -y -q 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-unicodecsv memcached \ - python-tidylib python-django-extra-views python-memcache python-dbf' ) - - echo "Installing BeautifulSoup4" - echo ""; - - ( set -x; $sh_c 'pip install BeautifulSoup4==4.3.2' ) - echo "-------------------------------------------------------------------------------"; - echo "Installing django-simple-history" - echo ""; - ( set -x; $sh_c 'pip install git+https://github.com/treyhunner/django-simple-history.git@0fd9b8e9c6f36b0141367b502420efe92d4e21ce' ) - - echo "-------------------------------------------------------------------------------"; - fi - - if [ "$dist_version" == "jessie" ]; then - if [ "$backports_activated" != 'true' ]; then - cat >&2 <<-'EOF' - - In order to install Ishtar you have to activate Debian backports. To do that: - - echo "deb http://ftp.debian.org/debian jessie-backports main contrib non-free" >> "/etc/apt/sources.list" - - Run again Ishtar installation script after that. -EOF - exit 1 - fi - - if [ "$default_db" == 'localhost' ]; 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 -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' ) - 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' ) - - echo "-------------------------------------------------------------------------------"; - fi - ;; - - esac - echo "-------------------------------------------------------------------------------"; - echo "Installing Ishtar sources" - echo ""; - - mkdir -p $full_install_path - cd $full_install_path - if [ "$dist_version" == "wheezy" ]; then - ( set -x; git clone https://nimn@gitlab.com/iggdrasil/oook_replace.git 2> /dev/null ) - fi - ( set -x; git clone https://gitlab.com/iggdrasil/ishtar.git 2> /dev/null ) - cd ishtar - git fetch 2> /dev/null - 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 "" - echo "*******************************************************************************"; - echo ""; - echo "Installation done. Base configuration stored in "$etc_path"config file." - echo "Next you'll have to create an instance." - echo ""; - -} - -do_install - 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/ishtar-install b/install/ishtar-install new file mode 100755 index 000000000..0d1b6d096 --- /dev/null +++ b/install/ishtar-install @@ -0,0 +1,397 @@ +#!/bin/bash + +set -e + +command_exists() { + command -v "$@" > /dev/null 2>&1 +} + +# Check if this is a forked Linux distro +check_forked() { + # Check for lsb_release command existence, it usually exists in forked distros + if command_exists lsb_release; then + # Check if the `-u` option is supported + set +e + lsb_release -a -u > /dev/null 2>&1 + lsb_release_exit_code=$? + set -e + + # Check if the command has exited successfully, it means we're in a forked distro + if [ "$lsb_release_exit_code" = "0" ]; then + # Print info about current distro + cat <<-EOF + You're using '$lsb_dist' version '$dist_version'. +EOF + + # Get the upstream release info + lsb_dist=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'id' | cut -d ':' -f 2 | tr -d '[[:space:]]') + dist_version=$(lsb_release -a -u 2>&1 | tr '[:upper:]' '[:lower:]' | grep -E 'codename' | cut -d ':' -f 2 | tr -d '[[:space:]]') + + # Print info about upstream distro + cat <<-EOF + Upstream release is '$lsb_dist' version '$dist_version'. +EOF + fi + fi +} + +do_install() { + + cat >&2 <<-'EOF' + +******************************************************************************* +++++++ Ishtar 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 + + # check distribution + lsb_dist='' + dist_version='' + backports_activated='' + if command_exists lsb_release; then + lsb_dist="$(lsb_release -si)" + fi + if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then + lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")" + fi + if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then + lsb_dist='debian' + fi + if [ -z "$lsb_dist" ] && [ -r /etc/fedora-release ]; then + lsb_dist='fedora' + fi + if [ -z "$lsb_dist" ] && [ -r /etc/oracle-release ]; then + lsb_dist='oracleserver' + fi + if [ -z "$lsb_dist" ]; then + if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then + lsb_dist='centos' + fi + fi + if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then + lsb_dist="$(. /etc/os-release && echo "$ID")" + fi + + lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" + + case "$lsb_dist" in + + ubuntu) + if command_exists lsb_release; then + dist_version="$(lsb_release --codename | cut -f2)" + fi + if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then + dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")" + fi + ;; + + debian) + MAINBACKS=`cat /etc/apt/sources.list | grep jessie-backports |grep -v "^#"` + ALLBACKS='' + if [ "$(ls -A /etc/apt/sources.list.d/)" ]; then + ALLBACKS=`cat /etc/apt/sources.list.d/* | grep jessie-backports |grep -v "^#"` + fi + if [ "$ALLBACKS" != '' ] || [ "$MAINBACKS" != '' ]; then + backports_activated='true'; + fi + dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')" + case "$dist_version" in + 8) + dist_version="jessie" + ;; + 7) + dist_version="wheezy" + ;; + esac + ;; + + oracleserver) + # need to switch lsb_dist to match yum repo URL + lsb_dist="oraclelinux" + dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" + ;; + + fedora|centos) + dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//' | sed 's/Server*//')" + ;; + + *) + if command_exists lsb_release; then + dist_version="$(lsb_release --codename | cut -f2)" + fi + if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then + dist_version="$(. /etc/os-release && echo "$VERSION_ID")" + fi + ;; + + + esac + + # Check if this is a forked Linux distro + check_forked + + case "$lsb_dist" in + ubuntu|debian) + ;; + *) + cat >&2 <<-'EOF' + + Sorry. Either your platform is not easily detectable or not supported by + this installer. + +EOF + exit 1 + esac + + default_db='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + A PostgreSQL database is needed to install Ishtar. If you do not plan to use + a database host on another computer you need to install PostgreSQL. + +EOF + while [ "$default_db" == '' ] + do + read -p '* Default PostgreSQL host? [localhost] ' choice + if [ "$choice" == '' ]; then + default_db='127.0.0.1' + elif [ "$choice" == 'localhost' ]; then + default_db='127.0.0.1' + else + default_db=$choice + fi + done + + webserver='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + A webserver is needed to make Ishtar available to the outside. + Be carreful if another webserver is already configured, you'll have to serve + your pages on a different port. + +EOF + MSG="" + while [ "$webserver" == '' ] + do + read -p '* Which webserver do you want to use? ([nginx]/none) ' choice + case "$choice" in + nginx ) webserver="nginx";; + none ) webserver="none";; + '' ) webserver="nginx";; + esac + done + + version='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + Two version are usually available for Ishtar: develop/master. Develop is the + bleeding edge version and you can experience problems with this version. + Master is the safest choice. + +EOF + while [ "$version" == '' ] + do + read -p "* Which version would you like to use? ([develop]/master) " choice + case "$choice" in + develop ) version="develop";; + master ) version="master";; + '' ) version="develop";; + esac + done + + etc_path="/etc/ishtar/" + if [ -d "$etc_path" ]; then + echo "" + echo "ERROR: it seems that "$etc_path" already exists. If this is a remnant " + echo "of an old installation please delete this path before installing." + exit 1 + fi + + + install_path='' + cat >&2 <<-'EOF' + +------------------------------------------------------------------------------- + By default Ishtar base path is '/srv/'. With this base path Ishtar is + installed in '/srv/ishtar/choosen_version/'. + +EOF + while [ "$install_path" == '' ] + do + read -p "* Which base install path for Ishtar? [/srv/] " choice + if [ -z "$choice" ]; then + install_path='/srv' + elif [ ! -d "$choice" ]; then + echo 'Not a valid path.' + else + install_path=$choice + fi + done + + full_install_path=$install_path'/ishtar/'$version + if [ -d "$full_install_path" ]; then + echo "" + echo "ERROR: it seems that "$full_install_path" already exists. If this is a " + echo "remnant of an old installation please delete this directory before installing." + exit 1 + fi + + echo "" + echo "*******************************************************************************" + echo "" + + # Run setup for each distro accordingly + case "$lsb_dist" in + ubuntu|debian) + if [ "$dist_version" != "jessie" ] && [ "$dist_version" != "wheezy" ]; then + cat >&2 <<-'EOF' + + Sorry this script cannot manage your version of Debian/Ubuntu. + +EOF + exit 1 + fi + + export DEBIAN_FRONTEND=noninteractive + ( set -x; $sh_c 'sleep 3; apt-get update' ) + if ! command_exists git; then + echo "-------------------------------------------------------------------------------"; + echo "Installing git..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q git' ) + fi + if ! command_exists apg; then + echo "-------------------------------------------------------------------------------"; + echo "Installing apg..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q apg' ) + fi + if ! command_exists pip; then + echo "-------------------------------------------------------------------------------"; + echo "Installing pip..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q python-pip' ) + fi + if [ "$webserver" == 'nginx' ]; then + echo "-------------------------------------------------------------------------------"; + echo "Installing nginx and uwsgi..."; + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q uwsgi uwsgi-plugin-python nginx' ) + fi + + echo "-------------------------------------------------------------------------------"; + + if [ "$dist_version" == "wheezy" ]; then + if [ "$default_db" == '127.0.0.1' ]; then + POSTGIS=postgresql-9.1-postgis + ( set -x; $sh_c 'sleep 3; apt-get install -y -q postgresql '$POSTGIS ) + fi + + echo "-------------------------------------------------------------------------------"; + echo "Installing Ishtar dependencies" + echo ""; + ( set -x; $sh_c 'sleep 3; apt-get install -y -q 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-unicodecsv memcached \ + python-tidylib python-django-extra-views python-memcache python-dbf' ) + + echo "Installing BeautifulSoup4" + echo ""; + + ( set -x; $sh_c 'pip install BeautifulSoup4==4.3.2' ) + echo "-------------------------------------------------------------------------------"; + echo "Installing django-simple-history" + echo ""; + ( set -x; $sh_c 'pip install git+https://github.com/treyhunner/django-simple-history.git@0fd9b8e9c6f36b0141367b502420efe92d4e21ce' ) + + echo "-------------------------------------------------------------------------------"; + fi + + if [ "$dist_version" == "jessie" ]; then + if [ "$backports_activated" != 'true' ]; then + cat >&2 <<-'EOF' + + In order to install Ishtar you have to activate Debian backports. To do that: + + echo "deb http://ftp.debian.org/debian jessie-backports main contrib non-free" >> "/etc/apt/sources.list" + + Run again Ishtar installation script after that. +EOF + exit 1 + fi + + 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\ + python-django-registration' ) + ( set -x; $sh_c 'sleep 3; apt-get install -y -q \ + 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' ) + + echo "-------------------------------------------------------------------------------"; + fi + ;; + + esac + echo "-------------------------------------------------------------------------------"; + echo "Installing Ishtar sources" + echo ""; + + mkdir -p $full_install_path + cd $full_install_path + if [ "$dist_version" == "wheezy" ]; then + ( set -x; git clone https://nimn@gitlab.com/iggdrasil/oook_replace.git 2> /dev/null ) + fi + ( set -x; git clone https://gitlab.com/iggdrasil/ishtar.git 2> /dev/null ) + cd ishtar + git fetch 2> /dev/null + git checkout $version 2> /dev/null + + mkdir -p $etc_path + 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 ""; + echo "Installation done. Base configuration stored in "$etc_path"config file." + echo "Next you'll have to create an instance." + echo ""; + +} + +do_install + 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 -- cgit v1.2.3