helm: Add a Helm chart for installing Arvados
[arvados-k8s.git] / arvados / config / sso / 90-init-db.sh
1 #!/bin/bash
2 # Copyright (C) The Arvados Authors. All rights reserved.
3 #
4 # SPDX-License-Identifier: Apache-2.0
5
6 set -e
7
8 prepare_database() {
9   RAILSPKG_DATABASE_LOAD_TASK="$1"
10   DB_MIGRATE_STATUS=$($COMMAND_PREFIX bundle exec rake db:migrate:status 2>&1 || true)
11   if echo "$DB_MIGRATE_STATUS" | grep -qF 'Schema migrations table does not exist yet.'; then
12       # The database exists, but the migrations table doesn't.
13       bundle exec rake "$RAILSPKG_DATABASE_LOAD_TASK" db:seed
14   elif echo "$DB_MIGRATE_STATUS" | grep -q '^database: '; then
15       bundle exec rake db:migrate
16   elif echo "$DB_MIGRATE_STATUS" | grep -q 'database .* does not exist'; then
17       bundle exec rake db:setup
18   else
19     echo "Warning: Database is not ready to set up." >&2
20     exit 1
21   fi
22
23   if [[ -f "/create-workbench-api-client.rb" ]]; then
24     # This is the API server
25     cd /var/www/arvados-api/current
26     bundle exec script/create_superuser_token.rb thisisnotaverygoodsuperusersecretstring00000000000
27     cd script
28     bundle exec get_anonymous_user_token.rb -t thisisnotaverygoodanonymoussecretstring00000000000 || true
29     bundle exec rails runner /create-workbench-api-client.rb
30   fi
31 }
32
33 prepare_database "db:schema:load"