#!/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-$INSTANCE} URL=${URL-localhost} DEST=/var/lib/python-django-ishtar INSTANCES_FILE=$DEST/INSTANCES 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 # 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" # Duplicate example_project into our instance: cd $DEST if [ -d "$INSTANCE" ]; then echo "Sorry, $INSTANCE already exists, not going further" exit 1 fi cp -ra example_project $INSTANCE rm $INSTANCE/settings.py ln -s $DEST/example_project/settings.py $DEST/$INSTANCE/settings.py # Preparing DB: PG_VERSION=9.1 DB_HOST=${DB_HOST-127.0.0.1} DB_PORT=${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 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" ### 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' 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" # Collect static data: cd $INSTANCE ./manage.py collectstatic --noinput cd - # Only language available: LOCALE=fr for d in archaeological_* ishtar_common; do cd $d ../$INSTANCE/manage.py compilemessages -l $LOCALE cd - done ### DB feeding cd $INSTANCE ./manage.py syncdb --noinput ./manage.py migrate ./manage.py flush --noinput 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 ./manage.py createsuperuser ./manage.py migrate --fake cd - echo "*** DB all done ***" ### 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" echo "*** uwsgi and nginx configured, restart them and you're done ***" printf "\n /etc/init.d/uwsgi restart\n /etc/init.d/nginx restart\n\n Enjoy ishtar!\n" # Register instance: echo "$INSTANCE" >> $INSTANCES_FILE