2023-06-21 23:53:00 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eux
|
|
|
|
|
|
|
|
dbversion=$(crudini --get /etc/zulip/zulip.conf postgresql version)
|
|
|
|
dbname=$(crudini --get /etc/zulip/zulip.conf postgresql database_name 2>/dev/null || echo zulip)
|
|
|
|
|
2023-09-22 03:58:11 +02:00
|
|
|
if ! su postgres -c "psql -At -c 'SELECT datname FROM pg_database WHERE NOT datistemplate'" | grep -Fx "$dbname"; then
|
|
|
|
echo "No database to install into!"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-06-21 23:53:00 +02:00
|
|
|
sharedir="${1:-/usr/share/postgresql/$dbversion}"
|
|
|
|
applied_file="$sharedir/pgroonga_setup.sql.applied"
|
|
|
|
|
|
|
|
installed_version=$(dpkg-query --show --showformat='${Version}' "postgresql-$dbversion-pgdg-pgroonga")
|
|
|
|
|
|
|
|
if [ ! -f "$applied_file" ]; then
|
2023-06-26 16:17:46 +02:00
|
|
|
sql="CREATE EXTENSION PGROONGA"
|
2023-06-21 23:53:00 +02:00
|
|
|
else
|
|
|
|
sql="ALTER EXTENSION pgroonga UPDATE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$sql" | su postgres -c "psql -v ON_ERROR_STOP=1 $dbname"
|
|
|
|
|
|
|
|
echo "$installed_version" >"$applied_file"
|