cloudron-setup: add --setup-token

This commit is contained in:
Girish Ramakrishnan
2022-03-31 23:38:54 -07:00
parent 81728f4202
commit 37a4e8d5c5
2 changed files with 15 additions and 10 deletions

View File

@@ -61,6 +61,7 @@ webServerOrigin="https://cloudron.io"
sourceTarballUrl=""
rebootServer="true"
setupToken="" # this is a OTP for securing an installation (https://forum.cloudron.io/topic/6389/add-password-for-initial-configuration)
appstoreSetupToken=""
redo="false"
args=$(getopt -o "" -l "help,skip-baseimage-init,provider:,version:,env:,skip-reboot,generate-setup-token,redo" -n "$0" -- "$@")
@@ -87,6 +88,7 @@ while true; do
--skip-baseimage-init) initBaseImage="false"; shift;;
--skip-reboot) rebootServer="false"; shift;;
--redo) redo="true"; shift;;
--setup-token) appstoreSetupToken="$2"; shift 2;;
--generate-setup-token) setupToken="$(openssl rand -hex 10)"; shift;;
--) break;;
*) echo "Unknown option $1"; exit 1;;
@@ -209,6 +211,19 @@ fi
mysql -uroot -ppassword -e "REPLACE INTO box.settings (name, value) VALUES ('api_server_origin', '${apiServerOrigin}');" 2>/dev/null
mysql -uroot -ppassword -e "REPLACE INTO box.settings (name, value) VALUES ('web_server_origin', '${webServerOrigin}');" 2>/dev/null
if [[ -n "${appstoreSetupToken}" ]]; then
if ! setupResponse=$(curl -X 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"
exit 1
fi
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
appstoreApiToken=$(echo "${setupResponse}" | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["accessToken"])')
mysql -uroot -ppassword -e "REPLACE INTO box.settings (name, value) VALUES ('appstore_api_token', '${appstoreApiToken}');" 2>/dev/null
fi
echo -n "=> Waiting for cloudron to be ready (this takes some time) ..."
while true; do
echo -n "."

View File

@@ -8,7 +8,6 @@ exports = module.exports = {
getAppVersion,
registerWithLoginCredentials,
registerWithSetupToken,
updateCloudron,
purchaseApp,
@@ -342,15 +341,6 @@ async function registerWithLoginCredentials(options) {
await registerCloudron({ domain: settings.dashboardDomain(), accessToken: result.accessToken, version: constants.VERSION });
}
async function registerWithSetupToken(setupToken) {
assert.strictEqual(typeof setupToken, 'string');
const token = await settings.getAppstoreApiToken();
if (token) throw new BoxError(BoxError.CONFLICT, 'Cloudron is already registered');
await registerCloudron({ domain: settings.dashboardDomain(), setupToken: setupToken, version: constants.VERSION });
}
async function createTicket(info, auditSource) {
assert.strictEqual(typeof info, 'object');
assert.strictEqual(typeof info.email, 'string');