From 25b4e71ee5a37196385630f02de3de2bba509269 Mon Sep 17 00:00:00 2001
From: "N. Geisler" <ngeisler@fachschaft.informatik.tu-darmstadt.de>
Date: Wed, 9 Oct 2019 22:39:57 +0200
Subject: [PATCH] add utility scripts

add Utils directory
add Utils README
add setup script
add check script
add update script
document usages in top-level README
---
 README.md       | 18 ++++++++++++++++++
 Utils/README.md |  9 +++++++++
 Utils/check.sh  | 21 +++++++++++++++++++++
 Utils/setup.sh  | 25 +++++++++++++++++++++++++
 Utils/update.sh | 27 +++++++++++++++++++++++++++
 5 files changed, 100 insertions(+)
 create mode 100644 Utils/README.md
 create mode 100644 Utils/check.sh
 create mode 100644 Utils/setup.sh
 create mode 100644 Utils/update.sh

diff --git a/README.md b/README.md
index b7e9f228..4aeaa4e6 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,14 @@ Python requirements are listed in ``requirements.txt``. They can be installed wi
 * change into that directory ``cd AKPlanning``
 * clone this repository ``git clone URL .``
 
+
+**Automatic Setup**
+
+1. execute the setup bash script ``Utils/setup.sh``
+
+
+**Manual Setup**
+
 1. setup a virtual environment using the proper python version ``virtualenv env -p python3.7``
 1. activate virtualenv ``source env/bin/activate``
 1. install python requirements ``pip install -r requirements.txt``
@@ -41,7 +49,17 @@ Python requirements are listed in ``requirements.txt``. They can be installed wi
 1. create a priviledged user, credentials are entered interactively on CLI ``python manage.py createsuperuser``
 1. deactivate virtualenv ``deactivate``
 
+
+**Development Server**
+
 To start the application for development use ``python manage.py runserver 0:8000`` from the root directory.
 *Do not use this for deployment!*
 
 In your browser, access ``http://127.0.0.1:8000/wannaDB/`` and continue from there.
+
+
+### Updates
+
+To update the setup to the current version on the main branch of the repository use the update script ``Utils/update.sh`` or ``Utils/update.sh --prod`` in production.
+
+Afterwards, you may check your setup by executing ``Utils/check.sh`` or ``Utils/check.sh --prod`` in production.
diff --git a/Utils/README.md b/Utils/README.md
new file mode 100644
index 00000000..b601f952
--- /dev/null
+++ b/Utils/README.md
@@ -0,0 +1,9 @@
+# AKPlanning Utility Scripts
+
+This directory contains helper scripts for setup and updating/checking of AKPlanning.
+
+All scripts should be executed from the project folder (repository root).
+
+* **setup** installation script for development setup
+* **update** update script for development or production (--prod) setup
+* **check** setup checking script for development and production (--prod) setup
diff --git a/Utils/check.sh b/Utils/check.sh
new file mode 100644
index 00000000..1f10486b
--- /dev/null
+++ b/Utils/check.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+# Check the AKPlanning setup for potential problems
+# execute as Utils/check.sh
+
+# activate virtualenv when necessary
+if [ -z ${VIRTUAL_ENV+x} ]; then
+    source env/bin/activate
+fi
+
+# enable really all warnings, some of them are silenced by default
+if [[ "$@" == *"--all"* ]]; then
+    export PYTHONWARNINGS=all
+fi
+
+# in case of checking production setup
+if [[ "$@" == *"--prod"* ]]; then
+    export DJANGO_SETTINGS_MODULE=AKPlanning.settings_production
+    ./manage.py check --deploy
+fi
+
+./manage.py check
diff --git a/Utils/setup.sh b/Utils/setup.sh
new file mode 100644
index 00000000..7e9d7a2a
--- /dev/null
+++ b/Utils/setup.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+# Setup AKPlanning
+# execute as Utils/check.sh
+
+# abort on error, print executed commands
+set -ex
+
+# remove old virtualenv
+rm -rf env/
+
+# Setup Python Environment
+# Requires: Virtualenv, appropriate Python installation
+virtualenv env -p python3.7
+source env/bin/activate
+pip install --upgrade setuptools pip wheel
+pip install -r requirements.txt
+
+# Setup database
+python manage.py migrate
+
+# Create superuser
+# Credentials are entered interactively on CLI
+python manage.py createsuperuser
+
+deactivate
diff --git a/Utils/update.sh b/Utils/update.sh
new file mode 100644
index 00000000..24076742
--- /dev/null
+++ b/Utils/update.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+# Update AKPlanning
+# execute as Utils/check.sh
+
+# abort on error, print executed commands
+set -ex
+
+# activate virtualenv if necessary
+if [ -z ${VIRTUAL_ENV+x} ]; then
+    source env/bin/activate
+fi
+
+# set environment variable when we want to update in production
+if [ "$1" = "--prod" ]; then
+    export DJANGO_SETTINGS_MODULE=AKPlanning.settings_production
+fi
+
+git pull
+pip install --upgrade setuptools pip wheel
+pip install --upgrade -r requirements.txt
+
+if [ "$1" = "--prod" ]; then
+    ./manage.py collectstatic --noinput
+fi
+
+./manage.py migrate
+touch AKPlanning/wsgi.py
-- 
GitLab