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.

83 lines
2.9 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: write_shopware_env_file.sh [live|stage|local_live|local_stage]" "live stage local_live local_stage")"
  7. is_remote=$(if [ "$env" == "live" ] || [ "$env" == "stage" ]; then echo 1; else echo 0; fi)
  8. echoMainTitle "Create $env system .env file"
  9. currentDate=$(date '+%Y-%m-%d_%H:%M:%S')
  10. database_socket="$(getConfig "$env" "database_socket")"
  11. database_host="$(getConfig "$env" "database_host")"
  12. database_port="$(getConfig "$env" "database_port")"
  13. database_name="$(getConfig "$env" "database_name")"
  14. database_user="$(getConfig "$env" "database_user")"
  15. database_password="$(getConfig "$env" "database_password")"
  16. if [ "$database_socket" != "" ]
  17. then
  18. db_connection="mysql://$database_host?unix_socket=$database_socket&dbname=$database_name&user=$database_user&password=$database_password"
  19. else
  20. db_connection="mysql://$database_user:$database_password@$database_host:$database_port/$database_name"
  21. fi
  22. app_url=${"$(getConfig "$env" "urls")"[0]}
  23. app_secret="$(getSecret "APP_SECRET")"
  24. echo "$app_secret" > "$app_dir/etc/app_secret"
  25. instance_id="$(getSecret "INSTANCE_ID")"
  26. echo "$instance_id" > "$app_dir/etc/instance_id"
  27. short="$(echo "$env" | sed -e "s/[_live|_stage]//")"
  28. host="$(eval "echo \"\${${short}_urls[0]}\"")"
  29. cat <<- EOF > "var/tmp/$env.env"
  30. APP_ENV=dev
  31. APP_SECRET=$app_secret
  32. APP_URL=$app_url
  33. TRUSTED_HOSTS=$host
  34. MAILER_URL=$local_mailer_url
  35. INSTANCE_ID=$instance_id
  36. DATABASE_URL=$db_connection
  37. COMPOSER_HOME=vendor
  38. BLUE_GREEN_DEPLOYMENT=1
  39. SHOPWARE_HTTP_CACHE_ENABLED=0
  40. SHOPWARE_HTTP_DEFAULT_TTL=0
  41. EOF
  42. if [ "$is_remote" == "1" ]
  43. then
  44. ssh_user="$(eval "echo \"\$${env}_ssh_user\"")"
  45. ssh_domain="$(eval "echo \"\$${env}_ssh_domain\"")"
  46. httpdocs_path="$(getConfig "$env" "httpdocs_path")"
  47. httpdocs_git_subpath="$(getConfig "$env" "httpdocs_git_subpath")"
  48. httpdocs_shopware_subpath="$(getConfig "$env" "httpdocs_shopware_subpath")"
  49. path="$httpdocs_path$httpdocs_git_subpath$httpdocs_shopware_subpath"
  50. addSSHKey "$env"
  51. has_env_file="$(ssh "ssh_user"@"ssh_domain" "[ -f \""$path/.env"\" ] && echo 1 || echo 2")"
  52. if [ "$has_env_file" == "1" ]
  53. then
  54. scp "$ssh_user"@"$ssh_domain":"$path/.env" "$app_dir/backup/$currentDate.$short.env}"
  55. fi
  56. scp "var/tmp/$env.env" "$ssh_user"@"$ssh_domain":"$path/.env"
  57. else
  58. path="$app_dir/git/$project_name/$local_httpdocs_shopware_subpath"
  59. has_env_file="$(ssh "[ -f \""$path/.env"\" ] && echo 1 || echo 2")"
  60. if [ "$has_env_file" == "1" ]
  61. then
  62. cp "$path/.env" "$app_dir/backup/$currentDate.$short.env}"
  63. fi
  64. cp "var/tmp/$env.env" "$path/.env"
  65. fi
  66. rm "var/tmp/$env.env"
  67. echoFinal "... .env file created"
  68. echo "Running postscript ..."
  69. postScript "$app_dir/bin/postscripts/function/write_shopware_env_file.sh"