Files
Hermes-Ollama_Models/scripts/install_postgresql_storage.sh

52 lines
1.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
usage() {
printf '%s\n' 'Usage: install_postgresql_storage.sh --check|--install'
}
case "${1:-}" in
--check)
if ! command -v psql >/dev/null 2>&1; then
printf '%s\n' 'PostgreSQL is not installed.'
exit 1
fi
psql --version
if command -v pg_lsclusters >/dev/null 2>&1; then
pg_lsclusters
fi
;;
--install)
if [ "$(id -u)" -ne 0 ]; then
printf '%s\n' 'PostgreSQL installation requires root.' >&2
exit 1
fi
export DEBIAN_FRONTEND=noninteractive
codename=''
if [ -r /etc/os-release ]; then
. /etc/os-release
codename="${VERSION_CODENAME:-}"
fi
if [ -z "$codename" ]; then
printf '%s\n' 'Could not determine the Ubuntu/Debian codename.' >&2
exit 1
fi
if [ -x /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh ]; then
bash /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y "$codename"
fi
apt-get update
candidate="$(apt-cache policy postgresql-18 2>/dev/null || true)"
case "$candidate" in
*'Candidate: (none)'*|"") apt-get install -y postgresql postgresql-client ;;
*) apt-get install -y postgresql-18 postgresql-client-18 ;;
esac
systemctl enable --now postgresql
printf '%s\n' 'Native PostgreSQL installation completed.'
psql --version
;;
*)
usage >&2
exit 2
;;
esac