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.

57 lines
1.4 KiB

  1. #!/bin/bash
  2. ##
  3. ## Get domain in option of relation "web-proxy"
  4. ##
  5. ## XXXvlab: there is a tiny lapse of time where database is not yet
  6. ## installed, and admin password is the default value.
  7. . lib/common
  8. set -ex
  9. admin_password=$(options-get admin-password 2>/dev/null ) || exit 1
  10. CONTROL_PASSWORD_FILE="$SERVICE_DATASTORE/.control-pass"
  11. ## Was it already properly propagated to database ?
  12. control_password=$(H "${admin_password}")
  13. if ! [ -e "$CONTROL_PASSWORD_FILE" ] || [ "$control_password" != "$(cat "$CONTROL_PASSWORD_FILE")" ]; then
  14. hash="$(htpasswd -nbBC 10 USER "$admin_password" | cut -f 2- -d :)" || {
  15. err "Couldn't generate hash for admin password."
  16. exit 1
  17. }
  18. if ! sql < <(e "
  19. UPDATE passwords SET value = '$hash'
  20. WHERE user_id = 1
  21. AND status = 'ACTIVE'
  22. AND password_type_id in (
  23. SELECT id FROM password_types
  24. WHERE input_method = 'TEXT_BOX'
  25. AND password_mode = 'MANUAL');
  26. "); then
  27. debug "Failed to set password for admin users."
  28. exit 1
  29. fi
  30. mkdir -p "${CONTROL_PASSWORD_FILE%/*}"
  31. e "$control_password" > "$CONTROL_PASSWORD_FILE"
  32. fi
  33. url=$(named-relation-get "web-proxy" url) || exit 1
  34. ## In ``configurations`` table, columns login_url, logout_url, root_url
  35. if ! sql < <(e "
  36. UPDATE configurations
  37. SET
  38. root_url = '$url'
  39. "); then
  40. debug "Failed to set password for admin users."
  41. exit 1
  42. fi