Ein für Shopware 6 vorbereitet Systemmanagment.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.8 KiB

  1. #!/bin/bash
  2. ### DO NOT EDIT THIS FILE
  3. source "$(dirname "${BASH_SOURCE[0]}")/../../includes/includes.sh"
  4. app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." &> /dev/null && pwd)
  5. source "$app_dir/etc/config.sh"
  6. env="$(getArgument "$1" "Usage: create_database.sh [live|stage|local_live|local_stage]" "live stage local_live local_stage")"
  7. echoMainTitle "Create $env system database"
  8. database_name="$(getConfig "$env" "database_name")"
  9. ssh_user="$(getConfig "$env" "ssh_user")"
  10. ssh_domain="$(getConfig "$env" "ssh_domain")"
  11. is_remote=$(if [ "$env" == "live" ] || [ "$env" == "stage" ]; then echo 1; else echo 0; fi)
  12. if [ "$is_remote" == "1" ]
  13. then
  14. addSSHKey "$env";
  15. scp "$app_dir/etc/$env.my.cnf" "$ssh_user"@"$ssh_domain":"~/$env.my.cnf"
  16. has_database=$(ssh "$ssh_user"@"ssh_domain" "mysql --defaults-extra-file=\"~/$env.my.cnf\" --defaults-group-suffix=\"admin\" -se \"SHOW DATABASES\" | grep \"$database_name\"")
  17. fi
  18. if [ "$is_remote" == "0" ]
  19. then
  20. has_database=$(mysql --defaults-extra-file="$app_dir/etc/$env.my.cnf" --defaults-group-suffix="admin" -se "SHOW DATABASES" | grep "$database_name")
  21. fi
  22. if [ "$has_database" == "" ]
  23. then
  24. create="$(readConsole "The Environment $env has no Database, should i creeate it? [y,n]", "Invalid selection" "y n")"
  25. if [ "$create" == "y" ] && [ "$is_remote" == "1" ]
  26. then
  27. ssh "$ssh_user"@"ssh_domain" "mysql --defaults-extra-file=\"~/$env.my.cnf\" --defaults-group-suffix=\"admin\" -se \"CREATE DATABASE \`$database_name\`\""
  28. elif [ "$create" == "y" ]
  29. then
  30. mysql --defaults-extra-file="$app_dir/etc/$env.my.cnf" --defaults-group-suffix="admin" -se "CREATE DATABASE \`$database_name\`"
  31. fi
  32. fi
  33. if [ "$is_remote" == "1" ]
  34. then
  35. ssh "$ssh_user"@"ssh_domain" "rm \"~/$env.my.cnf\""
  36. fi
  37. echoFinal "... database created"
  38. echo "Running postscript ..."
  39. postScript "$app_dir/bin/postscript/functions/create_database.sh"