forked from 0k/0k-charms
Browse Source
new: [cyclos] loading a default database for preconfiguration
new: [cyclos] loading a default database for preconfiguration
Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>upd-docker
Valentin Lab
4 years ago
4 changed files with 124 additions and 1 deletions
@ -0,0 +1,62 @@ |
|||
#!/bin/bash |
|||
|
|||
## |
|||
## Get domain in option of relation "web-proxy" |
|||
## |
|||
|
|||
## XXXvlab: there is a tiny lapse of time where database is not yet |
|||
## installed, and admin password is the default value. |
|||
|
|||
|
|||
. lib/common |
|||
|
|||
set -ex |
|||
|
|||
|
|||
admin_password=$(options-get admin-password 2>/dev/null ) || exit 1 |
|||
|
|||
CONTROL_PASSWORD_FILE="$SERVICE_DATASTORE/.control-pass" |
|||
## Was it already properly propagated to database ? |
|||
control_password=$(H "${admin_password}") |
|||
if ! [ -e "$CONTROL_PASSWORD_FILE" ] || [ "$control_password" != "$(cat "$CONTROL_PASSWORD_FILE")" ]; then |
|||
|
|||
hash="$(htpasswd -nbBC 10 USER "$admin_password" | cut -f 2- -d :)" || { |
|||
err "Couldn't generate hash for admin password." |
|||
exit 1 |
|||
} |
|||
|
|||
if ! sql < <(e " |
|||
UPDATE passwords SET value = '$hash' |
|||
WHERE user_id = 1 |
|||
AND status = 'ACTIVE' |
|||
AND password_type_id in ( |
|||
SELECT id FROM password_types |
|||
WHERE input_method = 'TEXT_BOX' |
|||
AND password_mode = 'MANUAL'); |
|||
"); then |
|||
debug "Failed to set password for admin users." |
|||
exit 1 |
|||
fi |
|||
e "$control_password" > "$CONTROL_PASSWORD_FILE" |
|||
fi |
|||
|
|||
|
|||
|
|||
url=$(named-relation-get "web-proxy" url) || exit 1 |
|||
|
|||
CONTROL_URL_FILE="$SERVICE_DATASTORE/.control-url" |
|||
## Was it already properly propagated to database ? |
|||
control_url=$(H "${url}") |
|||
if ! [ -e "$CONTROL_URL_FILE" ] || [ "$control_url" != "$(cat "$CONTROL_URL_FILE")" ]; then |
|||
## In ``configurations`` table, columns login_url, logout_url, root_url |
|||
|
|||
if ! sql < <(e " |
|||
UPDATE configurations |
|||
SET |
|||
root_url = '$url' |
|||
"); then |
|||
debug "Failed to set password for admin users." |
|||
exit 1 |
|||
fi |
|||
e "$control_password" > "$CONTROL_URL_FILE" |
|||
fi |
Write
Preview
Loading…
Cancel
Save
Reference in new issue