#!/bin/bash EXECUTABLE_FILE=restsrv.jar PROPERTIES_FILE=application-prod.properties HELP="Usage: restsrv_linux [KEY] Script without key is run program in DEFAULT mode. DEFAULT mode uses postgresql with next parameters: url: jdbc:postgresql://localhost/test username: test password: test Also available next switches: --prod - running program in PRODUCTION mode. For running in this mode needed additional file application-prod.properties with PostgreSQL dataset information. --demo - running program in DEMO mode. In this mode uses H2 database (in-memory) instead postgresql. --help - display this is message Examples: restsrv_linux - run program in DEFAULT mode restsrv_linux --demo - run program in DEMO mode. restsrv_linux --prod - run program in PRODUCTION mode. " PROPERTIES_FILE_NOT_FOUND=" WARNING! You try run program in PRODUCTION mode. For this mode need PostgreSQL but file $PROPERTIES_FILE with dataset information is not found. Please fill next information and run program again! " if [ -f "$EXECUTABLE_FILE" ]; then if [ -z "$1" ]; then echo "Running program in DEFAULT mode" java -jar "$EXECUTABLE_FILE" else case "$1" in --help) echo "$HELP" ;; --demo) echo "Running program in DEMO mode with H2 DB (in-memory)" java -jar "$EXECUTABLE_FILE" --spring.profiles.active=demo ;; --prod) if [ -f "$PROPERTIES_FILE" ]; then echo "Running program in PRODUCTION mode with PostgreSQL DB" java -jar "$EXECUTABLE_FILE" --spring.profiles.active=prod else echo "$PROPERTIES_FILE_NOT_FOUND" printf 'PostgreSQL database host name or IP address (default localhost): ' read -r RESTSRV_PGSQL_DB_HOST if [ -z "$RESTSRV_PGSQL_DB_HOST" ]; then RESTSRV_PGSQL_DB_HOST="jdbc:postgresql://localhost" else RESTSRV_PGSQL_DB_HOST="jdbc:postgresql://$RESTSRV_PGSQL_DB_HOST" fi printf 'PostgreSQL database port (default 5432): ' read -r RESTSRV_PGSQL_DB_PORT if [ -z "$RESTSRV_PGSQL_DB_PORT" ]; then RESTSRV_PGSQL_DB_PORT=5432 fi printf 'PostgreSQL database name (default test): ' read -r RESTSRV_PGSQL_DB_NAME if [ -z "$RESTSRV_PGSQL_DB_NAME" ]; then RESTSRV_PGSQL_DB_NAME="test" fi printf 'PostgreSQL database user name: ' read -r RESTSRV_PGSQL_DB_USER printf 'PostgreSQL database password: ' read -r -s RESTSRV_PGSQL_DB_PASSWORD echo touch "$PROPERTIES_FILE" { echo "RESTSRV_PGSQL_DB_HOST=$RESTSRV_PGSQL_DB_HOST" echo "RESTSRV_PGSQL_DB_PORT=$RESTSRV_PGSQL_DB_PORT" echo "RESTSRV_PGSQL_DB_NAME=$RESTSRV_PGSQL_DB_NAME" echo "RESTSRV_PGSQL_DB_USER=$RESTSRV_PGSQL_DB_USER" echo "RESTSRV_PGSQL_DB_PASSWORD=$RESTSRV_PGSQL_DB_PASSWORD" } > "$PROPERTIES_FILE" fi ;; *) echo "restsrv_linux: unknown option $1" echo "Try 'restsrv_linux --help' for more information." ;; esac fi else echo "Executable file restsrv.jar is not found!" fi