From 4b31658af643d1884c0d464959243174d27b6f1f Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Sun, 3 Apr 2016 05:17:12 +0200 Subject: Allow running install.sh from the top-level directory. Setting CDIR to the directory containing install.sh makes it possible to run it as install/install.sh from the top-level directory. Calling readlink -f on it makes sure one gets the canonical location, so that cd-ing to various places doesn't interfere with finding appropriate files (relatively to CDIR) afterwards. --- install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'install') diff --git a/install/install.sh b/install/install.sh index 92d0684c6..e90dc902a 100755 --- a/install/install.sh +++ b/install/install.sh @@ -89,7 +89,7 @@ fi DB_NAME='ishtar'$APP_NAME INSTALL_PATH=$INSTALL_PREFIX$DB_NAME DATE=`date +%F` -CDIR=`pwd` +CDIR=`readlink -f $(dirname $0)` SECRET_KEY=`apg -a 0 -M ncl -n 6 -x 10 -m 40 |head -n 1` if [ $DB_HOST = '127.0.0.1' ] -- cgit v1.2.3 From d459f5eb9232bd3da3e779ac32bf5065b9680212 Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Sun, 3 Apr 2016 05:17:17 +0200 Subject: Fix syntax error in sed command. --- install/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'install') diff --git a/install/install.sh b/install/install.sh index e90dc902a..7358ee747 100755 --- a/install/install.sh +++ b/install/install.sh @@ -241,7 +241,7 @@ sed -s "s|#APP_NAME#|$APP_NAME|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' > \ +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' \ -- cgit v1.2.3 From ac8c5e9f1d02bbc235f4c1a2664f1ab8d3c3798f Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Sun, 3 Apr 2016 05:17:19 +0200 Subject: Make INSTALL_PREFIX configurable. Since a comment insisted on this topic, make sure to add a trailing slash if that variable wasn't set properly. This means adjusting the templates in addition to the main script. A slash is kept as a separator in those to keep them readable, which explains the slightly awkward (uwsgi and nginx) sed calls. --- install/install.sh | 11 ++++++++++- install/nginx.conf.template | 6 +++--- install/uwsgi.ini.template | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'install') diff --git a/install/install.sh b/install/install.sh index 7358ee747..049a8a34a 100755 --- a/install/install.sh +++ b/install/install.sh @@ -41,7 +41,10 @@ UWSGI_PORT=${UWSGI_PORT-8891} NGINX_PORT=${NGINX_PORT-80} # don't forget the trailing slash -INSTALL_PREFIX=/srv/ +INSTALL_PREFIX=${INSTALL_PREFIX-/srv/} +if ! echo "$INSTALL_PREFIX" | grep -qs '/$'; then + INSTALL_PREFIX="$INSTALL_PREFIX/" +fi # if a virtualenv is used put the full path of the python to use PYTHON=python @@ -235,8 +238,11 @@ $PYTHON ./manage.py migrate --fake 2> /dev/null > /dev/null echo '* uwsgi configuration' +# NOTE: Replacing #INSTALL_PREFIX#/ is done on purpose, since we +# ensured that variable has a trailing slash. sed -s "s|#APP_NAME#|$APP_NAME|g;\ s|#DB_NAME#|$DB_NAME|g;\ + s|#INSTALL_PREFIX#/|$INSTALL_PREFIX|g;\ s|#URL#|$URL|g;\ s|#UWSGI_PORT#|$UWSGI_PORT|g;" $CDIR'/uwsgi.ini.template' > \ $INSTALL_PATH'/conf/uwsgi.ini' @@ -254,11 +260,14 @@ service uwsgi restart echo '* nginx configuration' +# NOTE: Replacing #INSTALL_PREFIX#/ is done on purpose, since we +# ensured that variable has a trailing slash. 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|#INSTALL_PREFIX#/|$INSTALL_PREFIX|g;\ s|#URL#|$URL|g;" $CDIR'/nginx.conf.template' > \ $INSTALL_PATH'/conf/nginx.conf' ln -s $INSTALL_PATH'/conf/nginx.conf' \ diff --git a/install/nginx.conf.template b/install/nginx.conf.template index c41018786..8df09e859 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_PREFIX#/#DB_NAME#/ishtar/; 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_PREFIX#/#DB_NAME#/ishtar/#APP_NAME#/static/; # STATIC_ROOT expires 30d; } location /media/ { # MEDIA_URL - alias /srv/#DB_NAME#/ishtar/#APP_NAME#/media/; # MEDIA_ROOT + alias #INSTALL_PREFIX#/#DB_NAME#/ishtar/#APP_NAME#/media/; # MEDIA_ROOT expires 30d; } diff --git a/install/uwsgi.ini.template b/install/uwsgi.ini.template index 7a20c058c..dd8f00480 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#/#DB_NAME#/ishtar/ # config plugins = python -- cgit v1.2.3 From f99df602f341b1aca1af44b44080d054303545cd Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Sun, 3 Apr 2016 05:17:23 +0200 Subject: Use 'mkdir -p' to create intermediate directory where needed. --- install/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'install') diff --git a/install/install.sh b/install/install.sh index 049a8a34a..c5cf57068 100755 --- a/install/install.sh +++ b/install/install.sh @@ -122,7 +122,7 @@ fi echo '* get sources' -mkdir $INSTALL_PATH +mkdir -p $INSTALL_PATH mkdir $INSTALL_PATH'/conf' cd $INSTALL_PATH @@ -164,7 +164,7 @@ sed -s "s|#APP_NAME#|$APP_NAME|g;\ ln -s $INSTALL_PATH'/conf/local_settings.py' $APP_DIR'/local_settings.py' # rights -mkdir $APP_DIR'/media' +mkdir -p $APP_DIR'/media' chown -R root:www-data $APP_DIR'/media' chmod -R g+w $APP_DIR'/media' -- cgit v1.2.3 From e8a39800e8d11ac63c3ed53e95c0a3003ce578a0 Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Sun, 3 Apr 2016 05:17:26 +0200 Subject: Add support for APT_GET and PIP environment variables. This makes it possible for admins or packagers to bypass automatic dependency installation using apt-get and pip. Example: APT_GET='echo -- apt-get' PIP='echo -- pip' install/install.sh --- install/install.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'install') diff --git a/install/install.sh b/install/install.sh index c5cf57068..42d337c0d 100755 --- a/install/install.sh +++ b/install/install.sh @@ -65,22 +65,25 @@ NGINX_ENABLE_PATH='/etc/nginx/sites-enabled/' echo "* installing dependencies" +APT_GET=${APT_GET-apt-get} +PIP=${PIP-pip} + if [ $DB_HOST = "127.0.0.1" ]; then - apt-get -q -y install postgresql postgresql-$PG_VERSION-postgis postgresql 2> /dev/null > /dev/null + $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 git apg python-pip 2> /dev/null > /dev/null -apt-get -q -y install python python-django \ +$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 +$APT_GET -q -y install uwsgi uwsgi-plugin-python nginx memcached 2> /dev/null > /dev/null -pip install$PIP_OPTIONS BeautifulSoup4==4.3.2 +$PIP install$PIP_OPTIONS BeautifulSoup4==4.3.2 if [ -z "$DB_PASSWORD" ] then -- cgit v1.2.3 From bf742d118a8c67114a170fd142e670c09f34920f Mon Sep 17 00:00:00 2001 From: Cyril Brulebois Date: Sun, 3 Apr 2016 06:22:41 +0200 Subject: FIXME: Improve reporting and error detection. set -e makes the shell error out whenever an unguarded command reports a failure, instead of blindly executing everything in turn. set -x ensures one knows which commands are being run/attempted. XXX: At least in v0.9, two commands are failing, hence the two occurrences of "|| true". --- install/install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'install') diff --git a/install/install.sh b/install/install.sh index 42d337c0d..a1829940d 100755 --- a/install/install.sh +++ b/install/install.sh @@ -1,5 +1,8 @@ #!/bin/bash +set -e +set -x + ###################################################################### # Minimum configuration # ###################################################################### @@ -201,8 +204,8 @@ 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 0013 2> /dev/null > /dev/null || true +python ./manage.py migrate archaeological_operations 2> /dev/null > /dev/null || true python ./manage.py migrate archaeological_files 2> /dev/null > /dev/null python ./manage.py migrate 2> /dev/null > /dev/null -- cgit v1.2.3