2023-04-29 01:32:09 +08:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
configure|upgrade|1|2)
|
|
|
|
|
|
|
|
fc-cache -f
|
|
|
|
|
2023-11-28 22:36:07 +08:00
|
|
|
runuser -u postgres -- psql -c "alter user postgres password 'bbb_graphql'"
|
|
|
|
runuser -u postgres -- psql -c "drop database if exists bbb_graphql with (force)"
|
|
|
|
runuser -u postgres -- psql -c "create database bbb_graphql WITH TEMPLATE template0 LC_COLLATE 'C.UTF-8'"
|
|
|
|
runuser -u postgres -- psql -c "alter database bbb_graphql set timezone to 'UTC'"
|
|
|
|
runuser -u postgres -- psql -U postgres -d bbb_graphql -q -f /usr/share/bbb-graphql-server/bbb_schema.sql --set ON_ERROR_STOP=on
|
2023-07-20 08:31:02 +08:00
|
|
|
|
|
|
|
DATABASE_NAME="hasura_app"
|
2023-11-28 22:36:07 +08:00
|
|
|
DB_EXISTS=$(runuser -u postgres -- psql -U postgres -tAc "SELECT 1 FROM pg_database WHERE datname='$DATABASE_NAME'")
|
2023-07-20 08:31:02 +08:00
|
|
|
if [ "$DB_EXISTS" = '1' ]
|
|
|
|
then
|
|
|
|
echo "Database $DATABASE_NAME already exists"
|
|
|
|
else
|
2023-11-28 22:36:07 +08:00
|
|
|
runuser -u postgres -- psql -c "create database hasura_app"
|
2023-07-20 08:31:02 +08:00
|
|
|
echo "Database $DATABASE_NAME created"
|
|
|
|
fi
|
|
|
|
|
2024-01-30 23:35:39 +08:00
|
|
|
# Create a readonly user that will be used by Meteor to check authToken (while Meteor not removed from the project)
|
|
|
|
DATABASE_FRONTEND_USER="bbb_frontend"
|
|
|
|
FRONT_USER_EXISTS=$(sudo -u postgres psql -U postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname = '$DATABASE_FRONTEND_USER'")
|
|
|
|
if [ "$FRONT_USER_EXISTS" = '1' ]
|
|
|
|
then
|
|
|
|
echo "User $DATABASE_FRONTEND_USER already exists"
|
|
|
|
else
|
|
|
|
sudo -u postgres psql -q -c "CREATE USER $DATABASE_FRONTEND_USER WITH PASSWORD '$DATABASE_FRONTEND_USER'"
|
|
|
|
sudo -u postgres psql -q -c "GRANT CONNECT ON DATABASE bbb_graphql TO $DATABASE_FRONTEND_USER"
|
|
|
|
sudo -u postgres psql -q -d bbb_graphql -c "REVOKE ALL ON ALL TABLES IN SCHEMA public FROM $DATABASE_FRONTEND_USER"
|
|
|
|
sudo -u postgres psql -q -d bbb_graphql -c "GRANT USAGE ON SCHEMA public TO $DATABASE_FRONTEND_USER"
|
|
|
|
echo "User $DATABASE_FRONTEND_USER created on database bbb_graphql"
|
|
|
|
fi
|
|
|
|
|
2024-02-02 21:52:50 +08:00
|
|
|
sudo -u postgres psql -q -d bbb_graphql -c "GRANT SELECT ON v_user_connection_auth TO $DATABASE_FRONTEND_USER"
|
2024-01-30 23:35:39 +08:00
|
|
|
|
2023-04-29 01:32:09 +08:00
|
|
|
echo "Postgresql configured"
|
|
|
|
|
2024-07-05 22:26:54 +08:00
|
|
|
#Generate a random password to Hasura to improve security
|
2024-05-08 22:44:44 +08:00
|
|
|
HASURA_ADM_PASSWORD=$(grep '^HASURA_GRAPHQL_ADMIN_SECRET=' /etc/default/bbb-graphql-server | cut -d '=' -f 2)
|
2024-07-05 22:26:54 +08:00
|
|
|
if [ "$HASURA_ADM_PASSWORD" = "bigbluebutton" ]; then
|
|
|
|
echo "Set a random password to Hasura replacing the default 'bigbluebutton'"
|
|
|
|
HASURA_RANDOM_ADM_PASSWORD=$(openssl rand -base64 32 | sed 's/=//g' | sed 's/+//g' | sed 's/\///g')
|
|
|
|
sed -i "s/HASURA_GRAPHQL_ADMIN_SECRET=bigbluebutton/HASURA_GRAPHQL_ADMIN_SECRET=$HASURA_RANDOM_ADM_PASSWORD/g" /etc/default/bbb-graphql-server
|
|
|
|
HASURA_ADM_PASSWORD="$HASURA_RANDOM_ADM_PASSWORD"
|
|
|
|
fi
|
|
|
|
|
|
|
|
sed -i "s/^admin_secret: .*/admin_secret: $HASURA_ADM_PASSWORD/g" /usr/share/bbb-graphql-server/config.yaml
|
2024-05-08 01:29:35 +08:00
|
|
|
|
2023-08-15 03:37:22 +08:00
|
|
|
if [ ! -f /.dockerenv ]; then
|
|
|
|
systemctl enable bbb-graphql-server.service
|
|
|
|
systemctl daemon-reload
|
|
|
|
startService bbb-graphql-server || echo "bbb-graphql-server service could not be registered or started"
|
2023-09-15 23:51:47 +08:00
|
|
|
|
|
|
|
#Check if Hasura is ready before applying metadata
|
2024-05-07 22:39:34 +08:00
|
|
|
HASURA_PORT=8085
|
2023-09-15 23:51:47 +08:00
|
|
|
while ! netstat -tuln | grep ":$HASURA_PORT " > /dev/null; do
|
|
|
|
echo "Waiting for Hasura's port ($HASURA_PORT) to be ready..."
|
|
|
|
sleep 1
|
|
|
|
done
|
2023-08-15 04:01:52 +08:00
|
|
|
|
|
|
|
# Apply BBB metadata in Hasura
|
|
|
|
cd /usr/share/bbb-graphql-server
|
2023-09-27 01:24:36 +08:00
|
|
|
/usr/local/bin/hasura metadata apply --skip-update-check
|
2023-08-15 04:01:52 +08:00
|
|
|
cd ..
|
|
|
|
rm -rf /usr/share/bbb-graphql-server/metadata
|
2023-08-15 03:37:22 +08:00
|
|
|
fi
|
2023-07-18 04:26:07 +08:00
|
|
|
|
2023-04-29 01:32:09 +08:00
|
|
|
;;
|
|
|
|
|
|
|
|
abort-upgrade|abort-remove|abort-deconfigure)
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
|
|
|
echo "postinst called with unknown argument \`$1'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|