cloudron-setup: validate the setup token

This commit is contained in:
Girish Ramakrishnan
2023-07-16 10:01:09 +05:30
parent 050a82039a
commit 2e20d757b1

View File

@@ -215,11 +215,17 @@ mysql -uroot -ppassword -e "REPLACE INTO box.settings (name, value) VALUES ('web
mysql -uroot -ppassword -e "REPLACE INTO box.settings (name, value) VALUES ('console_server_origin', '${consoleServerOrigin}');" 2>/dev/null
if [[ -n "${appstoreSetupToken}" ]]; then
if ! setupResponse=$(curl -sX POST -H "Content-type: application/json" --data "{\"setupToken\": \"${appstoreSetupToken}\"}" "${apiServerOrigin}/api/v1/cloudron_setup_done"); then
echo "Could not complete setup. See ${LOG_FILE} for details"
if ! httpCode=$(curl -sX POST -H "Content-type: application/json" -o /tmp/response.json -w "%{http_code}" --data "{\"setupToken\": \"${appstoreSetupToken}\"}" "${apiServerOrigin}/api/v1/cloudron_setup_done"); then
echo "Could not reach ${apiServerOrigin} to complete setup. See ${LOG_FILE} for details"
exit 1
fi
if [[ "${httpCode}" != "200" ]]; then
echo "Failed to validate setup token. See ${LOG_FILE} for details"
cat /tmp/response.json >> ${LOG_FILE}
exit 1
fi
setupResponse=$(cat /tmp/response.json)
cloudronId=$(echo "${setupResponse}" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["cloudronId"])')
mysql -uroot -ppassword -e "REPLACE INTO box.settings (name, value) VALUES ('cloudron_id', '${cloudronId}');" 2>/dev/null