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.
 
 

62 lines
1.6 KiB

#!/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