From fc5901868802d4e465c9b28ad2b24d30198e9c36 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 30 Jul 2021 18:34:47 +0300 Subject: [PATCH] Fix script mode and add safety check --- tools/create_database.sh | 22 +++++++++++++++++----- tools/create_users_database.sh | 0 2 files changed, 17 insertions(+), 5 deletions(-) mode change 100644 => 100755 tools/create_users_database.sh diff --git a/tools/create_database.sh b/tools/create_database.sh index ee90346b6..fe1ff4032 100755 --- a/tools/create_database.sh +++ b/tools/create_database.sh @@ -5,12 +5,24 @@ # # $db_name is passed as an environment variable -source config.sh -source utils.sh +die() { + echo + echo "Erreur: $1" + echo + exit 1 +} -echo 'Creating postgresql database' +source config.sh || die "config.sh not found, exiting" +source utils.sh || die "config.sh not found, exiting" + +if [ "$db_name" == "" ] +then + echo "Error: env var db_name unset" + echo "(ce script ne doit pas ĂȘtre lancĂ© directement !)" + exit 1 +fi # --- -echo 'Creating postgresql database ' $db_name -createdb -E UTF-8 -p $POSTGRES_PORT -O $POSTGRES_USER $db_name +echo 'Creating postgresql database ' "$db_name" +createdb -E UTF-8 -p "$POSTGRES_PORT" -O "$POSTGRES_USER" "$db_name" diff --git a/tools/create_users_database.sh b/tools/create_users_database.sh old mode 100644 new mode 100755