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

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