summaryrefslogtreecommitdiff
path: root/taler-bank-manage.in
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-04-08 16:52:20 +0200
committerFlorian Dold <florian.dold@gmail.com>2016-04-08 17:00:43 +0200
commit90072481161b3361da0af9a13b51a468764c1987 (patch)
treecbaf72af02b9b1d23a042217d3b1aa677b1c09c4 /taler-bank-manage.in
parent8bf550786257a83d76f6a2864484a47fb4d1b9e9 (diff)
downloadbank-90072481161b3361da0af9a13b51a468764c1987.tar.gz
bank-90072481161b3361da0af9a13b51a468764c1987.tar.bz2
bank-90072481161b3361da0af9a13b51a468764c1987.zip
restructure modules
Diffstat (limited to 'taler-bank-manage.in')
-rw-r--r--taler-bank-manage.in138
1 files changed, 138 insertions, 0 deletions
diff --git a/taler-bank-manage.in b/taler-bank-manage.in
new file mode 100644
index 0000000..463ae26
--- /dev/null
+++ b/taler-bank-manage.in
@@ -0,0 +1,138 @@
+#!/bin/bash
+# This file is part of TALER
+# (C) 2014, 2015, 2016 INRIA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Affero General Public License as published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
+#
+# @author Marcello Stanisci
+
+ARGS=$(getopt -o "" -l "all,help,bareserver:,createdb,flushdata,definetables,dumpdata,preaccounts,sampledata" -n "taler-bank-manage" -- "$@")
+SRC=@prefix@/share/talerbank/src
+VENV=@prefix@/share/talerbank/venv
+
+# unknown option given?
+if [ $? -ne 0 ];
+ then
+ exit 1
+fi
+
+function usage(){
+echo -e "Usage: taler-bank-manage [options]\n\t\
+ --all\tDefine tables, create preaccounts, provide sample data\n\t\
+ --definetables\tDefine DB tables needed by the bank\n\t\
+ --flushdata\tDelete any data/table from DB\n\t\
+ --dumpdata\tDump DB in JSON format\n\t\
+ --preaccounts\tInitialize bank's predefined accounts\n\t\
+ --sampledata\tFill DB with sample data\n\t\
+ --createdb \tCreate the '@dbnamefinal@' database.\n\t\
+ Make sure the user running this option has permission to create databases.\n\t\
+ --bareserver PORT\tRun the bank at given PORT with no nginx interaction;\n\t\
+ (SSI will not work that way)\n\t\
+ --help\tPrint this message\n"
+exit $1
+}
+
+function db_exists(){
+psql @dbnamefinal@ < /dev/null
+if test 0 -ne $?
+then
+ echo "Please create db (--createdb) before running this option"
+ exit 1
+fi
+}
+
+eval set -- "$ARGS"
+
+
+export DJANGO_SETTINGS_MODULE=talerbank.settings
+
+# source $VENV/bin/activate
+# cd $SRC
+
+EMPTYARGS=0
+
+while true;
+ do
+ case $1 in
+ --all)
+ db_exists
+ django-admin makemigrations
+ django-admin migrate
+ django-admin pre_accounts
+ django-admin sample_donations
+ shift
+ ;;
+ --definetables)
+ echo "Creating tables..."
+ EMPTYARGS=1
+ db_exists
+ django-admin migrate
+ django-admin basic_accounts
+ shift
+ ;;
+ --bareserver)
+ db_exists
+ EMPTYARGS=1
+ # FIXME test if $2 is a number
+ exec django-admin runserver --noreload $2
+ shift 2
+ ;;
+ --flushdata)
+ EMPTYARGS=1
+ db_exists
+ django-admin flush
+ shift
+ ;;
+ --dumpdata)
+ EMPTYARGS=1
+ db_exists
+ django-admin dumpdata --indent 3
+ shift
+ ;;
+ --preaccounts)
+ EMPTYARGS=1
+ db_exists
+ echo "Creating pre accounts..."
+ django-admin pre_accounts
+ shift
+ ;;
+ --sampledata)
+ EMPTYARGS=1
+ db_exists
+ echo "Generating sample data..."
+ django-admin sample_donations
+ shift
+ ;;
+ --createdb)
+ EMPTYARGS=1
+ psql @dbnamefinal@ < /dev/null
+ if test 0 -ne $?
+ then
+ createdb @dbnamefinal@
+ else
+ echo "'@dbnamefinal@' DB already exists."
+ fi
+ shift
+ ;;
+ --help)
+ EMPTYARGS=1
+ usage 0
+ break
+ ;;
+ --)
+ if test 0 -eq $EMPTYARGS
+ then usage 0
+ fi
+ break
+ ;;
+ esac
+ done