File: initdb.sh

package info (click to toggle)
diaspora-installer 0.7.6.1+debian1
  • links: PTS, VCS
  • area: contrib
  • in suites: bullseye, sid
  • size: 456 kB
  • sloc: sh: 895; makefile: 8
file content (27 lines) | stat: -rwxr-xr-x 832 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh

check_db_status() {
  echo "Checking if the database is empty..."
  if [ "$DB" = "postgres" ]; then
    db_relations="$(LANG=C runuser -u postgres -- sh -c "psql ${DB_NAME} -c \"\d\"" 2>&1)"
    test "$db_relations" = "No relations found." || \
    test "$db_relations" = "Did not find any relations."
  else
    test -z "$(sudo mysql --defaults-file=/etc/mysql/debian.cnf -e "show tables from ${DB_NAME}")"
  fi
}

# Generate secret token
bundle exec rake generate:secret_token

# Check if the db is already present
if check_db_status ; then
echo "Initializing database..."
	su diaspora -s /bin/sh -c 'bundle exec rake db:create db:migrate'
else
	echo "diaspora_production database is not empty, skipping database setup"
	echo "Running migrations..."
        su diaspora -s /bin/sh -c 'bundle exec rake db:migrate'
fi