|  | 
| 3 | 3 | set -Eexuo pipefail | 
| 4 | 4 | shopt -s nullglob | 
| 5 | 5 | 
 | 
| 6 |  | -PGVERSION=${PGVERSION:-12} | 
|  | 6 | +if [[ $OSTYPE == linux* ]]; then | 
|  | 7 | + PGVERSION=${PGVERSION:-12} | 
| 7 | 8 | 
 | 
| 8 |  | -if [ -e /etc/os-release ]; then | 
| 9 |  | - source /etc/os-release | 
| 10 |  | -elif [ -e /etc/centos-release ]; then | 
| 11 |  | - ID="centos" | 
| 12 |  | - VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.) | 
| 13 |  | -else | 
| 14 |  | - echo "install-postgres.sh: cannot determine which Linux distro this is" >&2 | 
| 15 |  | - exit 1 | 
| 16 |  | -fi | 
|  | 9 | + if [ -e /etc/os-release ]; then | 
|  | 10 | + source /etc/os-release | 
|  | 11 | + elif [ -e /etc/centos-release ]; then | 
|  | 12 | + ID="centos" | 
|  | 13 | + VERSION_ID=$(cat /etc/centos-release | cut -f3 -d' ' | cut -f1 -d.) | 
|  | 14 | + else | 
|  | 15 | + echo "install-postgres.sh: cannot determine which Linux distro this is" >&2 | 
|  | 16 | + exit 1 | 
|  | 17 | + fi | 
|  | 18 | + | 
|  | 19 | + if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then | 
|  | 20 | + export DEBIAN_FRONTEND=noninteractive | 
| 17 | 21 | 
 | 
| 18 |  | -if [ "${ID}" = "debian" -o "${ID}" = "ubuntu" ]; then | 
| 19 |  | - export DEBIAN_FRONTEND=noninteractive | 
| 20 |  | - | 
| 21 |  | - apt-get install -y --no-install-recommends curl gnupg ca-certificates | 
| 22 |  | - curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - | 
| 23 |  | - mkdir -p /etc/apt/sources.list.d/ | 
| 24 |  | - echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \ | 
| 25 |  | - >> /etc/apt/sources.list.d/pgdg.list | 
| 26 |  | - apt-get update | 
| 27 |  | - apt-get install -y --no-install-recommends \ | 
| 28 |  | - "postgresql-${PGVERSION}" \ | 
| 29 |  | - "postgresql-contrib-${PGVERSION}" | 
| 30 |  | -elif [ "${ID}" = "almalinux" ]; then | 
| 31 |  | - yum install -y \ | 
| 32 |  | - "postgresql-server" \ | 
| 33 |  | - "postgresql-devel" \ | 
| 34 |  | - "postgresql-contrib" | 
| 35 |  | -elif [ "${ID}" = "centos" ]; then | 
| 36 |  | - el="EL-${VERSION_ID%.*}-$(arch)" | 
| 37 |  | - baseurl="https://download.postgresql.org/pub/repos/yum/reporpms" | 
| 38 |  | - yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm" | 
| 39 |  | - if [ ${VERSION_ID%.*} -ge 8 ]; then | 
| 40 |  | - dnf -qy module disable postgresql | 
|  | 22 | + apt-get install -y --no-install-recommends curl gnupg ca-certificates | 
|  | 23 | + curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - | 
|  | 24 | + mkdir -p /etc/apt/sources.list.d/ | 
|  | 25 | + echo "deb https://apt.postgresql.org/pub/repos/apt/ ${VERSION_CODENAME}-pgdg main" \ | 
|  | 26 | + >> /etc/apt/sources.list.d/pgdg.list | 
|  | 27 | + apt-get update | 
|  | 28 | + apt-get install -y --no-install-recommends \ | 
|  | 29 | + "postgresql-${PGVERSION}" \ | 
|  | 30 | + "postgresql-contrib-${PGVERSION}" | 
|  | 31 | + elif [ "${ID}" = "almalinux" ]; then | 
|  | 32 | + yum install -y \ | 
|  | 33 | + "postgresql-server" \ | 
|  | 34 | + "postgresql-devel" \ | 
|  | 35 | + "postgresql-contrib" | 
|  | 36 | + elif [ "${ID}" = "centos" ]; then | 
|  | 37 | + el="EL-${VERSION_ID%.*}-$(arch)" | 
|  | 38 | + baseurl="https://download.postgresql.org/pub/repos/yum/reporpms" | 
|  | 39 | + yum install -y "${baseurl}/${el}/pgdg-redhat-repo-latest.noarch.rpm" | 
|  | 40 | + if [ ${VERSION_ID%.*} -ge 8 ]; then | 
|  | 41 | + dnf -qy module disable postgresql | 
|  | 42 | + fi | 
|  | 43 | + yum install -y \ | 
|  | 44 | + "postgresql${PGVERSION}-server" \ | 
|  | 45 | + "postgresql${PGVERSION}-contrib" | 
|  | 46 | + ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config" | 
|  | 47 | + elif [ "${ID}" = "alpine" ]; then | 
|  | 48 | + apk add shadow postgresql postgresql-dev postgresql-contrib | 
|  | 49 | + else | 
|  | 50 | + echo "install-postgres.sh: unsupported Linux distro: ${distro}" >&2 | 
|  | 51 | + exit 1 | 
| 41 | 52 |  fi | 
| 42 |  | - yum install -y \ | 
| 43 |  | -  "postgresql${PGVERSION}-server" \ | 
| 44 |  | - "postgresql${PGVERSION}-contrib" | 
| 45 |  | - ln -s "/usr/pgsql-${PGVERSION}/bin/pg_config" "/usr/local/bin/pg_config" | 
| 46 |  | -elif [ "${ID}" = "alpine" ]; then | 
| 47 |  | - apk add shadow postgresql postgresql-dev postgresql-contrib | 
|  | 53 | + | 
|  | 54 | + useradd -m -s /bin/bash apgtest | 
|  | 55 | + | 
|  | 56 | +elif [[ $OSTYPE == darwin* ]]; then | 
|  | 57 | + brew install postgresql | 
|  | 58 | + | 
| 48 | 59 | else | 
| 49 |  | - echo "install-postgres.sh: Unsupported distro: ${distro}" >&2 | 
|  | 60 | + echo "install-postgres.sh: unsupported OS: ${OSTYPE}" >&2 | 
| 50 | 61 |  exit 1 | 
| 51 | 62 | fi | 
| 52 |  | - | 
| 53 |  | -useradd -m -s /bin/bash apgtest | 
|  | 
0 commit comments