0

It compiling the files and ignoring all the error.Now i want here is that it has to exit and stop compiling if error exist

Note: I am working with docker container.This code is executing after .yml file.The yml exits the compiler if there's an error but in this file it is ignoring all the errors

Here is my shell-scripts-dev.sh file

#!/bin/bash
#do not enter current dir
#cd $(dirname $0)
BASEDIR=$(dirname "$0")
printf "\n"
printf "###############################################################################\n"
printf "# Running dev script from directory  #\n"
printf "###############################################################################\n"
pwd

printf "\n"
printf "###############################################################################\n"
printf "# Create initial/ needed files  #\n"
printf "###############################################################################\n"
# backend init files
if [ ! -f backend/config/main-local.php ]; then
    printf "File backend/config/main-local.php does not exist, creating it, please edit configuration on server!\n"
    cp backend/config/main-local.example backend/config/main-local.php
fi

if [ ! -f backend/config/params.php ]; then
    printf "File backend/config/params.php does not exist, creating it, please edit configuration on server!\n"
    cp backend/config/params.example backend/config/params.php
fi
if [ ! -f backend/web/index.php ]; then
    printf "File backend/web/index.php does not exist, creating it, please edit configuration on server!\n"
    cp backend/web/index.example backend/web/index.php
fi
if [ ! -f backend/web/index-test.php ]; then
    printf "File backend/web/index-test.php does not exist, creating it, please edit configuration on server!\n"
    cp backend/web/index.example backend/web/index-test.php
fi
# common init files
if [ ! -f common/config/main.php ]; then
    printf "File common/config/main.php does not exist, creating it, please edit configuration on server!\n"
    cp common/config/main.example common/config/main.php
fi

if [ ! -f common/config/main-local.php ]; then
    printf "File common/config/main-local.php does not exist, creating it, please edit configuration on server!\n"
    cp common/config/main-local.example common/config/main-local.php
fi

if [ ! -f common/config/params.php ]; then
    printf "File common/config/params.php does not exist, creating it, please edit configuration on server!\n"
    cp common/config/params.example common/config/params.php
fi


# rest init files
if [ ! -f rest/config/params.php ]; then
    printf "File rest/config/params.php does not exist, creating it, please edit configuration on server!\n"
    cp rest/config/params.example rest/config/params.php
fi
if [ ! -f rest/web/index.php ]; then
    printf "File rest/web/index.php does not exist, creating it, please edit configuration on server!\n"
    cp rest/web/index.example rest/web/index.php
fi
if [ ! -f rest/web/index-test.php ]; then
    printf "File rest/web/index-test.php does not exist, creating it, please edit configuration on server!\n"
    cp rest/web/index.example rest/web/index-test.php
fi
printf "\n"
printf "###############################################################################\n"
printf "# Clearing cache #\n"
printf "###############################################################################\n"
# backend runtime files
rm -rf backend/web/assets/*
rm -rf backend/runtime/debug/*
rm -rf backend/runtime/logs/*
rm -rf backend/runtime/mail/*
rm -rf backend/runtime/URI/*
rm -rf cache/*
# rest runtime files
rm -rf rest/runtime/cache/*
rm -rf backend/runtime/debug/*
rm -rf backend/runtime/logs/*
rm -rf backend/runtime/mail/*


###############################################################################
# Rebuild assets# - don't we need this???
###############################################################################
#chmod +x ../app/Console/cake
#cd ../app && Vendor/bin/cake asset_compress build --force

printf "\n"
printf "###############################################################################\n"
printf "# Composer update #\n"
printf "###############################################################################\n"
php composer.phar install

printf "\n"
printf "###############################################################################\n"
printf "# Running yii migrations #\n"
printf "###############################################################################\n"
yes | php yii migrate

printf "\n"
printf "###############################################################################\n"
printf "#Run PhpSniffer and output any errors #\n"
printf "###############################################################################\n"
php ./vendor/bin/phpcs --encoding=utf-8 --extensions=php backend --colors
php ./vendor/bin/phpcs --encoding=utf-8 --extensions=php common --colors
php

 ./vendor/bin/phpcs --encoding=utf-8 --extensions=php rest --colors
nullPointer
  • 4,419
  • 1
  • 15
  • 27
rajwa766
  • 604
  • 13
  • 31

1 Answers1

1

In case I understood correctly, you need your bash script to exit in case it encounters errors ? if so, you can use set -e command : What does set -e mean in a bash script?

nullPointer
  • 4,419
  • 1
  • 15
  • 27