[FIX] Problem with export that is already used by Bash

This commit is contained in:
Olivier DOSSMANN 2016-02-15 16:06:14 +01:00
parent 30126e9daf
commit 3042f5c813

View File

@ -83,13 +83,13 @@ not_implemented() {
show_help() {
echo "$PROGRAM COMMAND [arg ...]"
echo -e " Where ${green}COMMAND${reset} is one of:"
echo -e " - backup Create a compressed postgreSQL database dump
in current directory"
echo -e " - create Create postgreSQL database volume and
postgreSQL Docker container"
echo -e " - dev [arg ...] Mount Git repository directory AS VOLUME
for Gissmo Docker container and launch it in
'development' mode"
echo -e " - export Create a compressed postgreSQL database dump
in current directory"
echo -e " - init Create project directory as python virtual
environment, fetch git repository and install
Python dependancies"
@ -111,12 +111,12 @@ show_help() {
check_command() {
# Allowed commands return 0 to continue. Otherwise show help and exit
if test $1 == "create"; then
if test $1 == "backup"; then
return 0
elif test $1 == "create"; then
return 0
elif test $1 == "dev"; then
return 0
elif test $1 == "export"; then
return 0
elif test $1 == "init"; then
return 0
elif test $1 == "psql"; then
@ -196,7 +196,7 @@ another name please set GISSMO_DOCKER_NAME in configuration file."
fi
}
test_export() {
test_backup() {
# Check postgreSQL Docker container exists and is launched.
test_postgresql_launched
if [ $? -eq 1 ]; then
@ -204,12 +204,12 @@ test_export() {
fi
}
export_command() {
backup() {
# Check all variables are availables
test_create
# Then check some specific things for dump method
test_export
$docker_cmd run -it --rm --volume $PWD/:/tmp/ --link ${POSTGRES_DOCKER_NAME}:db postgres:${POSTGRES_VERSION} bash -c 'exec pg_dump -F c -h "$DB_PORT_5432_TCP_ADDR" -p "$DB_PORT_5432_TCP_PORT" -U postgres postgres > /tmp/gissmo-`date +"%Y.%m.%d.%H%M"`-'${GISSMO_VERSION}'.dump' || error_and_quit "Failed to export Gissmo database."
test_backup
$docker_cmd run -it --rm --volume $PWD/:/tmp/ --link ${POSTGRES_DOCKER_NAME}:db postgres:${POSTGRES_VERSION} bash -c 'exec pg_dump -F c -h "$DB_PORT_5432_TCP_ADDR" -p "$DB_PORT_5432_TCP_PORT" -U postgres postgres > /tmp/gissmo-`date +"%Y.%m.%d.%H%M"`-'${GISSMO_VERSION}'.dump' || error_and_quit "Failed to backup Gissmo database."
}
init() {
@ -221,7 +221,7 @@ init() {
virtualenv -p python3 $PROJECT_DIR || error_and_quit "Create ${PROJECT_DIR} python virtual environment failed."
info "Python virtual environment initialized."
fi
cd $PROJECT_DIR
cd "$PROJECT_DIR"
# On Fedora 23: gcc postgresql-devel python3-devel python-virtualenv git-core python3-pip redhat-rpm-config gmp-devel
sudo apt-get install -qq libpq-dev python3-dev python-virtualenv git-core python3-pip || error_and_quit "Dependancies installation failed."
info "Dependancies via apt-get checked/installed."
@ -236,8 +236,8 @@ init() {
cp "${GISSMO_DIR}/scripts/git_hooks/pre-commit" "${GISSMO_DIR}/.git/hooks/pre-commit" || error_and_quit "Failed to install pre-commit hook."
info "Git repository pre-commit hook installed."
fi
. bin/activate || error_and_quit "Failed entering python virtual environment"
cd $GISSMO_DIR
source bin/activate || error_and_quit "Failed entering python virtual environment"
cd "$GISSMO_DIR"
pip install -q -r requirements.txt || error_and_quit "Python dependancies
installation failed."
info "Python dependancies checked."
@ -294,11 +294,11 @@ test_initial_start() {
fi
# Build Gissmo Docker images if missing
if [[ "$($docker_cmd images -q gissmo:${GISSMO_VERSION} 2> /dev/null)" == "" ]]; then
cd $GISSMO_DIR
cd "$GISSMO_DIR"
info "Building Docker images…"
$docker_cmd build -t gissmo:${GISSMO_VERSION} -f ${DOCKERFILE} . || error_and_quit "Failed to build Gissmo Docker container."
info "…done."
cd $CURRENT_DIR
cd "$CURRENT_DIR"
fi
if test -z "$GISSMO_DOCKER_PORT"; then
error_and_quit "No Gissmo Docker container port given
@ -362,13 +362,7 @@ fi
if ! test -z $COMMAND; then
check_command "$COMMAND"
# To avoid 'export' bash command reassignement which made some failure in
#+ Python virtualenv
if "$COMMAND" == "export"; then
export_command
else
$COMMAND
fi
$COMMAND
else
show_help
fi