101 lines
3.3 KiB
Bash
Executable File
101 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Configure mysql for further usage
|
|
credentialsFile="/opt/bin/mysql-credentials.cnf"
|
|
|
|
setup="false"
|
|
composer_install="false"
|
|
Green='\033[0;32m'
|
|
Color_Off='\033[0m'
|
|
|
|
function print_usage {
|
|
echo "use flag -s to setup db structure as well"
|
|
}
|
|
|
|
while getopts 'sc' flag; do
|
|
case "${flag}" in
|
|
s) setup="true" ;;
|
|
c) composer_install="true" ;;
|
|
*) print_usage
|
|
exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
# Check if we are in the project's root directory by checking for this script's directory
|
|
if [ ! -d "./development/bin" ]; then
|
|
echo "This script must be run from the root of the project"
|
|
exit 1
|
|
fi
|
|
|
|
# Bring up the Docker containers
|
|
echo -e "${Green}Bringing up Docker containers${Color_Off}"
|
|
echo
|
|
|
|
docker-compose -f docker-compose.yaml up -d || exit 1
|
|
|
|
# Adding the execute permission for database scripts
|
|
docker exec -t elixirvault_mysql bash -c 'chmod +x /opt/bin/*.sh'
|
|
|
|
# Create folders & install composer packages if folder is missing
|
|
#if [[ ! -d "./vendor" || $composer_install -eq "true" ]]; then
|
|
# # Installing composer dependencies
|
|
# echo -e "${Green}Installing composer dependencies${Color_Off} ..."
|
|
# echo
|
|
#
|
|
# rm -rf ./vendor
|
|
# mkdir -p ./vendor
|
|
#
|
|
# sleep 3;
|
|
# docker exec secretvault_php bash -c "php /usr/local/bin/composer install --working-dir /var/www/html"
|
|
#else
|
|
# docker exec secretvault_php bash -c "cd /var/www/html; composer dumpautoload" > /dev/null 2>&1;
|
|
#fi
|
|
|
|
# Disable sendmail_path from php.webdevops.ini cfg file which overrider php.ini
|
|
#docker exec -t secretvault_php bash -c 'sed -i "s/^sendmail_path/;sendmail_path/" /opt/docker/etc/php/php.webdevops.ini'
|
|
|
|
# Check if db container is loaded, if not wait for it to load
|
|
printf 'Waiting for database connection ...' > /dev/tty
|
|
|
|
timeout=0
|
|
while ! docker exec -it elixirvault_mysql mysql --defaults-extra-file=$credentialsFile -e "SELECT 1" >/dev/null 2>&1; do
|
|
# Exit if exceed 60s
|
|
if [[ "$timeout" -gt 60 ]]; then
|
|
exit 1
|
|
fi
|
|
printf "." > /dev/tty
|
|
|
|
let timeout++
|
|
sleep 1
|
|
done
|
|
echo -e " ${Green}done${Color_Off}"
|
|
|
|
# Load DB & setup users and privileges
|
|
if [[ $setup == "true" ]]; then
|
|
|
|
# Load base working companies
|
|
echo
|
|
echo -e "${Green}Load database core structure${Color_Off}"
|
|
docker exec -t elixirvault_mysql bash -c "./opt/bin/load_structure.sh -db=elixir_vault_lv -progress-title='Constructing elixir_vault_lv'"
|
|
# Load base working companies
|
|
echo
|
|
echo -e "${Green}Load database core data${Color_Off}"
|
|
docker exec -t elixirvault_mysql bash -c "./opt/bin/load_data.sh -db=elixir_vault_lv -progress-title='Loading data elixir_vault_lv'"
|
|
|
|
|
|
# Create ct user & grant all permissions - some views depend on this user
|
|
docker exec -it elixirvault_mysql mysql --defaults-extra-file=$credentialsFile -e \
|
|
"DROP USER IF EXISTS 'dAccGlobal'@'%';"
|
|
docker exec -it elixirvault_mysql mysql --defaults-extra-file=$credentialsFile -e \
|
|
"CREATE USER 'dAccGlobal'@'%' IDENTIFIED BY 'dAccGlobal12!@'; GRANT ALL PRIVILEGES ON *.* TO dAccGlobal@'%';"
|
|
|
|
docker exec -it elixirvault_mysql mysql --defaults-extra-file=$credentialsFile -e \
|
|
"DROP USER IF EXISTS 'dElixirGlobalCr'@'%';"
|
|
docker exec -it elixirvault_mysql mysql --defaults-extra-file=$credentialsFile -e \
|
|
"CREATE USER 'dElixirGlobalCr'@'%' IDENTIFIED BY 'dElixirGlobalCr12\!@'; GRANT ALL PRIVILEGES ON *.* TO dElixirGlobalCr@'%';"
|
|
|
|
echo -e "Database structure & data setup load ... ${Green}done${Color_Off}"
|
|
fi
|
|
|
|
exit 0
|