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.
84 lines
2.9 KiB
84 lines
2.9 KiB
#!/bin/bash
|
|
|
|
### DO NOT EDIT THIS FILE
|
|
|
|
source "$(dirname "${BASH_SOURCE[0]}")/../../includes/includes.sh"
|
|
app_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." &> /dev/null && pwd)
|
|
source "$app_dir/etc/config.sh"
|
|
|
|
env="$(getArgument "$1" "Usage: write_shopware_env_file.sh [live|stage|local_live|local_stage]" "live stage local_live local_stage")"
|
|
is_remote=$(if [ "$env" == "live" ] || [ "$env" == "stage" ]; then echo 1; else echo 0; fi)
|
|
|
|
echoMainTitle "Create $env system .env file"
|
|
|
|
currentDate=$(date '+%Y-%m-%d_%H:%M:%S')
|
|
|
|
database_socket="$(getConfig "$env" "database_socket")"
|
|
database_host="$(getConfig "$env" "database_host")"
|
|
database_port="$(getConfig "$env" "database_port")"
|
|
database_name="$(getConfig "$env" "database_name")"
|
|
database_user="$(getConfig "$env" "database_user")"
|
|
database_password="$(getConfig "$env" "database_password")"
|
|
|
|
if [ "$database_socket" != "" ]
|
|
then
|
|
db_connection="mysql://$database_host?unix_socket=$database_socket&dbname=$database_name&user=$database_user&password=$database_password"
|
|
else
|
|
db_connection="mysql://$database_user:$database_password@$database_host:$database_port/$database_name"
|
|
fi
|
|
|
|
app_url=${"$(getConfig "$env" "urls")"[0]}
|
|
|
|
app_secret="$(getSecret "APP_SECRET")"
|
|
echo "$app_secret" > "$app_dir/etc/app_secret"
|
|
instance_id="$(getSecret "INSTANCE_ID")"
|
|
echo "$instance_id" > "$app_dir/etc/instance_id"
|
|
|
|
short="$(echo "$env" | sed -e "s/[_live|_stage]//")"
|
|
host="$(eval "echo \"\${${short}_urls[0]}\"")"
|
|
|
|
cat <<- EOF > "var/tmp/$env.env"
|
|
APP_ENV=dev
|
|
APP_SECRET=$app_secret
|
|
APP_URL=$app_url
|
|
TRUSTED_HOSTS=$host
|
|
MAILER_URL=$local_mailer_url
|
|
INSTANCE_ID=$instance_id
|
|
DATABASE_URL=$db_connection
|
|
COMPOSER_HOME=vendor
|
|
BLUE_GREEN_DEPLOYMENT=1
|
|
SHOPWARE_HTTP_CACHE_ENABLED=0
|
|
SHOPWARE_HTTP_DEFAULT_TTL=0
|
|
EOF
|
|
|
|
if [ "$is_remote" == "1" ]
|
|
then
|
|
ssh_user="$(eval "echo \"\$${env}_ssh_user\"")"
|
|
ssh_domain="$(eval "echo \"\$${env}_ssh_domain\"")"
|
|
httpdocs_path="$(getConfig "$env" "httpdocs_path")"
|
|
httpdocs_git_subpath="$(getConfig "$env" "httpdocs_git_subpath")"
|
|
httpdocs_shopware_subpath="$(getConfig "$env" "httpdocs_shopware_subpath")"
|
|
path="$httpdocs_path$httpdocs_git_subpath$httpdocs_shopware_subpath"
|
|
addSSHKey "$env"
|
|
has_env_file="$(ssh "ssh_user"@"ssh_domain" "[ -f \""$path/.env"\" ] && echo 1 || echo 2")"
|
|
if [ "$has_env_file" == "1" ]
|
|
then
|
|
scp "$ssh_user"@"$ssh_domain":"$path/.env" "$app_dir/backup/$currentDate.$short.env}"
|
|
fi
|
|
scp "var/tmp/$env.env" "$ssh_user"@"$ssh_domain":"$path/.env"
|
|
else
|
|
path="$app_dir/git/$project_name/$local_httpdocs_shopware_subpath"
|
|
has_env_file="$(ssh "[ -f \""$path/.env"\" ] && echo 1 || echo 2")"
|
|
if [ "$has_env_file" == "1" ]
|
|
then
|
|
cp "$path/.env" "$app_dir/backup/$currentDate.$short.env}"
|
|
fi
|
|
cp "var/tmp/$env.env" "$path/.env"
|
|
fi
|
|
|
|
rm "var/tmp/$env.env"
|
|
|
|
echoFinal "... .env file created"
|
|
|
|
echo "Running postscript ..."
|
|
postScript "$app_dir/bin/postscripts/function/write_shopware_env_file.sh"
|