fork 0k-charms
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.
 
 

99 lines
2.7 KiB

#!/bin/bash
. lib/common
set -e
## If no admin-password set, then don't try to pre-initialize database
admin_password=$(options-get admin-password 2>/dev/null) || exit 0
admin_email=$(options-get admin-email 2>/dev/null ) || true
CONTROL="$SERVICE_DATASTORE/.control"
## Was it already properly propagated to database ?
control=$(H "${admin_password}" "${admin_email}")
if [ -e "$CONTROL" ]; then
if [ "$control" == "$(cat "$CONTROL")" ]; then
exit 0
else
err "Changing admin password in compose file not yet supported"
exit 1
fi
fi
##
## Get domain in option of relation "publish-dir"
##
if ! url=$(relation:get "$SERVICE_NAME":publish-dir url) || [ -z "$url" ]; then
err "Couldn't get ${WHITE}url${NORMAL} information in ${DARKCYAN}publish-dir${NORMAL} relation's data."
exit 1
fi
protocol="${url%%://*}"
domain="${url#$protocol://}"
domain="${domain%%/*}"
##
## We are in post_deploy, so our service is up, we need to get
## the ``network`` and ``container``'s id to communicate with
## him.
##
container_id=$(
for container_id in $(get_running_containers_for_service "$MASTER_BASE_SERVICE_NAME"); do
e "$container_id"
break
done
)
admin_email=${admin_email:-"admin@$domain"}
read-0 network container_ip < <(get_container_network_ip "$container_id")
debug "Running index.php/project/initialize"
echo docker run --network "$network" docker.0k.io/curl -k -s -X POST -H "Host: $domain" -L \
-F sonata_user_registration[username]="admin" \
-F sonata_user_registration[email]="$admin_email" \
-F sonata_user_registration[plainPassword][first]="$admin_password" \
-F sonata_user_registration[plainPassword][second]="$admin_password" \
"$protocol://$container_ip/index.php/project/initialize"
out=$(docker run --network "$network" docker.0k.io/curl -k -s -X POST -H "Host: $domain" -L \
-F sonata_user_registration[username]="admin" \
-F sonata_user_registration[email]="$admin_email" \
-F sonata_user_registration[plainPassword][first]="$admin_password" \
-F sonata_user_registration[plainPassword][second]="$admin_password" \
"$protocol://$container_ip/index.php/project/initialize") || {
err "Failed to run project/initialize script"
echo "$out"
exit 1
}
# #e "$out" > "$SERVICE_DATASTORE/out.html"
# # debug "written $SERVICE_DATASTORE/out.html"
# had_error=
# while read-0 error_msg; do
# had_error=1
# err "Installation failed with these errors:"
# echo "- ${error_msg}" >&2
# done < <(e "$out" | xpath "//div[@class='errors']/ul/li/text()")
# if [ "$had_error" ]; then
# exit 1
# fi
# debug "No error catched on \`\`install.php\`\` result."
# e "$control" > "$CONTROL"
exit 0