#!/bin/sh
# Initialize only an existing empty database, owned by the configured DB user.
# Start Gitaly first: systemctl enable --now gitaly
# GitLab 18 defaults to eight characters (Devise and application settings).
# Check before loading Rails: even inspecting the database must wait for this.
# Count UTF-8 characters even when the administrator uses the C locale.
/usr/bin/ruby -e '
  password = ENV.fetch("GITLAB_ROOT_PASSWORD", "").dup.force_encoding(Encoding::UTF_8)
  abort "gitlab-setup: GITLAB_ROOT_PASSWORD must be set to at least 8 characters." unless password.valid_encoding? && password.length >= 8
' || exit
exec /usr/bin/gitlab-rake gitlab:setup:existing_database "$@"
