fork 0k-charms
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.

63 lines
1.7 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. CONTROL_URL_FILE="$SERVICE_DATASTORE/.control-url"
  35. ## Was it already properly propagated to database ?
  36. control_url=$(H "${url}")
  37. if ! [ -e "$CONTROL_URL_FILE" ] || [ "$control_url" != "$(cat "$CONTROL_URL_FILE")" ]; then
  38. ## In ``configurations`` table, columns login_url, logout_url, root_url
  39. if ! sql < <(e "
  40. UPDATE configurations
  41. SET
  42. root_url = '$url'
  43. "); then
  44. debug "Failed to set password for admin users."
  45. exit 1
  46. fi
  47. e "$control_password" > "$CONTROL_URL_FILE"
  48. fi