diff options
-rw-r--r-- | debian/python-django-ishtar.install | 1 | ||||
-rwxr-xr-x | ishtar-prepare-instance | 163 |
2 files changed, 164 insertions, 0 deletions
diff --git a/debian/python-django-ishtar.install b/debian/python-django-ishtar.install index 2fbda2564..14d90d1e6 100644 --- a/debian/python-django-ishtar.install +++ b/debian/python-django-ishtar.install @@ -1 +1,2 @@ /var/lib/python-django-ishtar +ishtar-prepare-instance usr/sbin diff --git a/ishtar-prepare-instance b/ishtar-prepare-instance new file mode 100755 index 000000000..1d18feb7c --- /dev/null +++ b/ishtar-prepare-instance @@ -0,0 +1,163 @@ +#!/bin/sh +# +# Stripped-down version of the install.sh script, only dealing with +# customizing files shipped through a Debian package which also pulls +# a bunch of dependencies. +set -e +set -u + +# Instance then project names: +INSTANCE=${INSTANCE-iggdrasil} +PROJECT=${PROJECT-Test} +URL=${URL-localhost} +DEST=/var/lib/python-django-ishtar + +echo "*** Preparing ishtar (instance: $INSTANCE, project: $PROJECT) under $DEST ***" + +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 + +# Duplicate example_project into our instance: +cd $DEST +if [ -d "$INSTANCE" ]; then + echo "Sorry, $INSTANCE already exists, not going further" + exit 1 +fi +cp -r example_project $INSTANCE + +# Collect static data: +cd $INSTANCE +./manage.py collectstatic --noinput +cd - + +# Only language available: +LOCALE=fr +for d in archaeological_*; do + cd $d + django-admin compilemessages -l $LOCALE + cd - +done + +# Preparing DB: +PG_VERSION=9.1 +DB_HOST=${DB_HOST-127.0.0.1} +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 PROJECT +su postgres <<'EOF' + echo "Checking template_postgis" + if ! psql -l | grep -qs template_postgis; then + echo " - not present, creating" + createdb template_postgis + psql -q -d template_postgis -f /usr/share/postgresql/$PG_VERSION/contrib/postgis-1.5/postgis.sql + psql -q -d template_postgis -f /usr/share/postgresql/$PG_VERSION/contrib/postgis-1.5/spatial_ref_sys.sql + else + echo " - already present" + fi + + echo "Checking $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 "$PROJECT" + else + echo " - already present" + fi +EOF + + +# Permissions: +mkdir -p -m 775 "$INSTANCE/media" +chown root:www-data "$INSTANCE/media" + +# XXX: Should probably ship those from the package, and make them +# either ishtar or python-django-ishtar, or django/ishtar +# alternatively: +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" + +### LOCAL SETTINGS + +# 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) + +# Declare these in advance, at least the port is needed: +UWSGI_PORT=${UWSGI_PORT-8891} +UWSGI_AVAILABLE_PATH='/etc/uwsgi/apps-available' +UWSGI_ENABLE_PATH='/etc/uwsgi/apps-enabled' + +rm $INSTANCE/settings.py +sed -s "s|#APP_NAME#|$INSTANCE|g;\ + s|#INSTALL_PATH#|$INSTALL_PATH|g;\ + s|#DATE#|$DATE|g;\ + s|#PROJECT_NAME#|$PROJECT|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;" \ + "install/local_settings.py.sample" > \ + "$INSTANCE/local_settings.py" + + +### UWSGI + +sed -s "s|#APP_NAME#|$INSTANCE|g;\ + s|#DB_NAME#|$DB_NAME|g;\ + s|#INSTALL_PREFIX#|$INSTALL_PREFIX|g;\ + s|#URL#|$URL|g;\ + s|#UWSGI_PORT#|$UWSGI_PORT|g;" \ + "install/uwsgi.ini.template" > \ + "$INSTANCE/uwsgi.ini" + +# XXX: Generation of django.wsgi was entirely dropped. + +# XXX: Using -f might be a bit too aggressive +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 + +NGINX_PORT=${NGINX_PORT-80} +NGINX_AVAILABLE_PATH='/etc/nginx/sites-available' +NGINX_ENABLE_PATH='/etc/nginx/sites-enabled' + +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" |