From 678276b14b56565bd68b086aee6fc4f844ade6fa Mon Sep 17 00:00:00 2001
From: Fredrick Brennan <copypaste@kittens.ph>
Date: Sat, 2 Dec 2023 15:32:56 -0500
Subject: [PATCH] Fix Docker build environment, website went down

http://repo.nasutek.com/arch/contrib/docker-dev/ no longer exists.

---
 arch/DockerBuildEnvironment/Dockerfile        |  50 ++++-
 .../packages/postgresql9/PKGBUILD             | 210 ++++++++++++++++++
 .../packages/postgresql9/pgenv.sh             |   5 +
 .../postgresql9/postgresql-9.6.24.tar.bz2     | Bin 0 -> 19047518 bytes
 .../postgresql9/postgresql-check-db-dir       |  42 ++++
 .../postgresql9/postgresql-command.patch      |  11 +
 .../postgresql9/postgresql-perl-rpath.patch   |  13 ++
 .../postgresql9/postgresql-run-socket.patch   |  12 +
 .../packages/postgresql9/postgresql.install   |   7 +
 .../packages/postgresql9/postgresql.service   |  46 ++++
 .../packages/postgresql9/postgresql.sysusers  |   1 +
 .../packages/postgresql9/postgresql.tmpfiles  |   2 +
 12 files changed, 393 insertions(+), 6 deletions(-)
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/PKGBUILD
 create mode 100755 arch/DockerBuildEnvironment/packages/postgresql9/pgenv.sh
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql-9.6.24.tar.bz2
 create mode 100755 arch/DockerBuildEnvironment/packages/postgresql9/postgresql-check-db-dir
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql-command.patch
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql-perl-rpath.patch
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql-run-socket.patch
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql.install
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql.service
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql.sysusers
 create mode 100644 arch/DockerBuildEnvironment/packages/postgresql9/postgresql.tmpfiles

diff --git a/arch/DockerBuildEnvironment/Dockerfile b/arch/DockerBuildEnvironment/Dockerfile
index d657a60b0..e4627f1d4 100644
--- a/arch/DockerBuildEnvironment/Dockerfile
+++ b/arch/DockerBuildEnvironment/Dockerfile
@@ -1,16 +1,54 @@
-FROM archlinux/base
+FROM archlinux:base
 
-RUN echo "[docker-dev]" >> /etc/pacman.conf
-RUN echo "SigLevel = Optional TrustAll" >> /etc/pacman.conf
-RUN echo "Server = http://repo.nasutek.com/arch/contrib/docker-dev/" >> /etc/pacman.conf
+RUN echo "Server = http://arch.tanuki.agency/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist
+RUN echo "Server = http://mirrors.163.com/archlinux/\$repo/os/\$arch" > /etc/pacman.d/mirrorlist
+RUN echo "Server = http://mirrors.aliyun.com/archlinux/\$repo/os/\$arch" >> /etc/pacman.d/mirrorlist
+RUN echo "Server = http://mirrors.ustc.edu.cn/archlinux/\$repo/os/\$arch" >> /etc/pacman.d/mirrorlist
 
+RUN pacman-key --init
+RUN pacman-key --populate archlinux
 RUN pacman -Syyu --noconfirm
 RUN pacman-db-upgrade
 
-RUN pacman -S --noconfirm base-devel sudo grep wget xscreensaver libxss libgphoto2 fribidi sane xmms2 alsa-plugins alsa-tools alsa-utils audiofile glib2 libmad libogg libvorbis pulseaudio-alsa avahi nss-mdns dbus libraw1394 libxtst lm_sensors ttf-dejavu ttf-freefont xorg-server xorg-xinit openssl-1.0 aspell hspell jasper libcups libidn libutempter libxcomposite libxslt openexr pcre xorg-iceauth xorg-xmessage xorg-xprop xorg-xset xorg-xsetroot glu taglib gtk3 dbus-glib speex wireless_tools wpa_supplicant boost boost-libs gnokii curl libraw pkgconfig autoconf imake cmake python2 imlib automake libtool libxkbfile smbclient rpcsvc-proto xorg-bdftopcf libiodbc libxi mariadb unixodbc libmng xorg-xrandr libxft flex subversion mplayer exiv2 doxygen
-RUN pacman -S --noconfirm htdig lcms postgresql-9.6
+RUN >&2 echo "Installing dependencies for Trinity Desktop Environment..."
+RUN pacman -S --noconfirm base-devel sudo grep wget xscreensaver libxss libgphoto2 fribidi sane xmms2 alsa-plugins alsa-tools alsa-utils audiofile glib2 libmad libogg libvorbis pulseaudio-alsa avahi nss-mdns dbus libraw1394 libxtst lm_sensors ttf-dejavu ttf-freefont xorg-server xorg-xinit aspell hspell jasper libcups libidn libutempter libxcomposite libxslt openexr pcre xorg-iceauth xorg-xmessage xorg-xprop xorg-xset xorg-xsetroot glu taglib gtk3 dbus-glib speex wireless_tools wpa_supplicant boost boost-libs curl libraw pkgconfig autoconf imake cmake imlib automake libtool libxkbfile smbclient rpcsvc-proto xorg-bdftopcf libiodbc libxi mariadb unixodbc libmng xorg-xrandr libxft flex subversion mplayer exiv2 doxygen
+# to build postgresql9
+RUN >&2 echo "Installing dependencies for building PostgreSQL 9.6.24..."
+RUN pacman -S --noconfirm compiler-rt clang tcl
 
 RUN echo "%wheel ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
 
 RUN useradd -m dev
 RUN gpasswd -a dev wheel
+
+# Fredrick R. Brennan (copypaste)
+RUN pacman-key --recv-key 0xB5ACB79E11F1BF7F49F32BB85853056962F14E58 && \
+    pacman-key --lsign-key 0xB5ACB79E11F1BF7F49F32BB85853056962F14E58
+# Trinity Desktop Environment Signing Key
+RUN pacman-key --recv-key 0xD6D6FAA25E9A3E4ECD9FBDBEC93AF1698685AD8B && \
+    pacman-key --lsign-key 0xD6D6FAA25E9A3E4ECD9FBDBEC93AF1698685AD8B
+ADD packages /tmp/packages
+RUN pacman -U --noconfirm $(find /tmp/packages -name "*.pkg.tar.xz" -or -name "*.pkg.tar.zst")
+
+RUN >&2 echo "Installing PostgreSQL 9.6.24..."
+RUN env NPROC="$(nproc)" && \
+    echo MAKEFLAGS="-j${NPROC}" >> /etc/makepkg.conf && \
+    echo BUILDDIR="/tmp/makepkg" >> /etc/makepkg.conf && \
+    echo PACKAGER="'Trinity Desktop Environment Developer <anonymous@localhost.localdomain>'" >> /etc/makepkg.conf
+RUN useradd -m tmpuser && \
+    chown -R tmpuser:tmpuser /tmp/packages && \
+    cd /tmp/packages/postgresql9 && \
+    usermod -aG wheel tmpuser && \
+    sudo -u tmpuser makepkg --verifysource --noconfirm -f
+RUN cd /tmp/packages/postgresql9 && \
+    sudo -u tmpuser makepkg --nobuild --noconfirm -f
+RUN cd /tmp/packages/postgresql9 && \
+    sudo -u tmpuser bash -ic "set -m && makepkg --noconfirm -f"
+RUN cd /tmp/packages/postgresql9 && \
+    pacman -U --noconfirm $(find . -name "*.pkg.tar.xz" -or -name "*.pkg.tar.zst") && \
+    userdel -r tmpuser
+RUN pacman -Rc --noconfirm postgresql11{,-libs} && \
+    pacman -Qi postgresql9{,-libs,-docs} && \
+    >&2 echo "PostgreSQL 9.6.24 installed successfully."
+
+RUN >&2 echo "Build complete."
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/PKGBUILD b/arch/DockerBuildEnvironment/packages/postgresql9/PKGBUILD
new file mode 100644
index 000000000..2dbcff23a
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/PKGBUILD
@@ -0,0 +1,210 @@
+# Adaptor to build PostgreSQL 9.6.24 on Arch Linux:
+#   Fredrick R. Brennan <copypaste@kittens.ph>
+# Main author: Marc Rechté <marc4@rechte.fr>
+
+pkgbase=postgresql9
+pkgver=9.6.24
+_majorver=${pkgver%.*}
+pkgname=("${pkgbase}-libs" "${pkgbase}-docs" "${pkgbase}")
+pkgrel=1
+pkgdesc='Sophisticated object-relational DBMS'
+url='https://www.postgresql.org/'
+arch=('x86_64')
+license=('custom:PostgreSQL')
+makedepends=('krb5' 'libxml2' 'python' 'tcl>=8.6.0' 'openssl>=1.0.0'
+             'pam' 'zlib' 'icu' 'systemd' 'libldap' 'clang' )
+optdepends=('perl')
+source=(https://ftp.postgresql.org/pub/source/v${pkgver}/postgresql-${pkgver}.tar.bz2
+        postgresql-run-socket.patch
+        postgresql-perl-rpath.patch
+        postgresql-command.patch
+        postgresql.service
+        postgresql-check-db-dir
+        postgresql.sysusers
+        postgresql.tmpfiles
+        pgenv.sh)
+md5sums=('132c726216a0e4b8540fcf974d25dc06'
+         '92249e35353927d9f79df66a4101b3fa'
+         '7d899fe96b0044e120e49bab4205610d'
+         '2c74b38d3ca580733daaf60d7c564792'
+         '77f41e79ec546d40b24a46cd646e3c2f'
+         '848c7c58ac8831fb5323e3446be5afcf'
+         '2050d34e4dfa05f3c6fe4cd7615eaa4b'
+         '9f34d430c5ef0ddca8843b58f71c0b3d'
+         '37bbc58222c61b8e0533eab845ca94f5')
+
+prepare() {
+  cd postgresql-${pkgver}
+  patch -p1 < ../postgresql-run-socket.patch
+  patch -p1 < ../postgresql-perl-rpath.patch
+  #patch -p1 < ../postgresql-command.patch
+  cp ../pgenv.sh .
+}
+
+build() {
+  cd postgresql-${pkgver}
+  # removed: --with-libxml, --with-ldap --with-llvm
+  local options=(
+    --prefix=/opt/${pkgbase}
+    --sysconfdir=/etc
+    --with-gssapi
+    --with-openssl
+#    --with-perl
+    --with-python3
+    --with-tcl
+    --with-pam
+    --with-system-tzdata=/usr/share/zoneinfo
+    --with-uuid=e2fs
+    --with-icu
+    --with-systemd
+    --enable-nls
+    --enable-thread-safety
+    --disable-rpath
+  )
+
+  # only build plpython3 for now
+  #./configure ${options[@]} \
+  #  PYTHON=/usr/bin/python
+  #make -C src/pl/plpython all
+  #make -C contrib/hstore_plpython all
+  #make -C contrib/ltree_plpython all
+
+  # save plpython3 build and Makefile.global
+  #cp -a src/pl/plpython{,3}
+  #cp -a contrib/hstore_plpython{,3}
+  #cp -a contrib/ltree_plpython{,3}
+  #cp -a src/Makefile.global{,.python3}
+  #make distclean
+
+  # regular build with everything
+  ./configure ${options[@]}
+  #  PYTHON=/usr/bin/python2
+  make world
+}
+
+_postgres_check() {
+  make "${1}" || (find . -name regression.diffs | \
+    while read -r line; do
+      echo "make ${1} failure: ${line}"
+      cat "${line}"
+    done; exit 1)
+}
+
+package_postgresql9-libs() {
+  pkgdesc="Libraries for use with PostgreSQL"
+  depends=('krb5' 'openssl>=1.0.0' 'readline>=6.0' 'zlib' 'libldap')
+  provides=("${pkgbase}-client" 'libpq.so' 'libecpg.so' 'libecpg_compat.so' 'libpgtypes.so')
+  conflicts=("${pkgbase}-client")
+
+  pushd "$srcdir/postgresql-${pkgver}"
+
+  # install license
+  install -Dm 644 COPYRIGHT -t "${pkgdir}/opt/${pkgbase}/share/licenses/${pkgname}"
+
+  
+
+  # install libs and non-server binaries
+  for dir in src/interfaces src/bin/pg_config src/bin/pg_dump src/bin/psql src/bin/scripts; do
+    make -C ${dir} DESTDIR="${pkgdir}" install
+  done
+
+  for util in pg_config pg_dump pg_dumpall pg_restore psql \
+      clusterdb createdb createuser dropdb dropuser pg_isready reindexdb vacuumdb; do
+    install -Dm 644 doc/src/sgml/man1/${util}.1 "${pkgdir}"/opt/${pkgbase}/share/man/man1/${util}.1
+  done
+
+  cd src/include
+
+  install -d "${pkgdir}"/opt/${pkgbase}/include/{libpq,postgresql/internal/libpq}
+
+  # these headers are needed by the public headers of the interfaces
+  install -m 644 pg_config.h "${pkgdir}/opt/${pkgbase}/include"
+  install -m 644 pg_config_os.h "${pkgdir}/opt/${pkgbase}/include"
+  install -m 644 pg_config_ext.h "${pkgdir}/opt/${pkgbase}/include"
+  install -m 644 postgres_ext.h "${pkgdir}/opt/${pkgbase}/include"
+  install -m 644 libpq/libpq-fs.h "${pkgdir}/opt/${pkgbase}/include/libpq"
+  install -m 644 pg_config_manual.h "${pkgdir}/opt/${pkgbase}/include"
+
+  # these he aders are needed by the not-so-public headers of the interfaces
+  install -m 644 c.h "${pkgdir}/opt/${pkgbase}/include/postgresql/internal"
+  install -m 644 port.h "${pkgdir}/opt/${pkgbase}/include/postgresql/internal"
+  install -m 644 postgres_fe.h "${pkgdir}/opt/${pkgbase}/include/postgresql/internal"
+  install -m 644 libpq/pqcomm.h "${pkgdir}/opt/${pkgbase}/include/postgresql/internal/libpq"
+
+  # this utility is to be sourced in order to find proper libs and bins
+  popd
+  install -m 755 "${srcdir}/pgenv.sh" "${pkgdir}/opt/${pkgbase}/bin"
+}
+
+package_postgresql9-docs() {
+  pkgdesc="HTML documentation for PostgreSQL"
+  options=('docs')
+
+  cd postgresql-${pkgver}
+
+  install -Dm 644 COPYRIGHT -t "${pkgdir}/opt/${pkgbase}/share/licenses/${pkgname}"
+
+  make -C doc/src/sgml DESTDIR="${pkgdir}" install-html
+  chown -R root:root "${pkgdir}/opt/${pkgbase}/share/doc/html"
+
+  # clean up
+  rmdir "${pkgdir}"/opt/${pkgbase}/share/man/man{1,3,7}
+  rmdir "${pkgdir}"/opt/${pkgbase}/share/man
+}
+
+package_postgresql9() {
+  pkgdesc='Sophisticated object-relational DBMS'
+  # backup=('etc/pam.d/postgresql' 'etc/logrotate.d/postgresql')
+  depends=("${pkgbase}-libs>=${pkgver}" 'krb5' 'libxml2' 'readline>=6.0'
+           'openssl>=1.0.0' 'pam' 'icu' 'systemd-libs' 'libldap' 'llvm-libs' 'libxslt')
+  optdepends=('python2: for PL/Python 2 support'
+              'python: for PL/Python 3 support'
+              'perl: for PL/Perl support'
+              'tcl: for PL/Tcl support')
+  options=('staticlibs')
+  install=postgresql.install
+
+  pushd "$srcdir/postgresql-${pkgver}"
+
+  # install
+  make DESTDIR="${pkgdir}" install
+  make -C contrib DESTDIR="${pkgdir}" install
+  make -C doc/src/sgml DESTDIR="${pkgdir}" install-man
+
+  # install plpython3
+  #mv src/Makefile.global src/Makefile.global.save
+  #cp src/Makefile.global.python3 src/Makefile.global
+  #touch -r src/Makefile.global.save src/Makefile.global
+  #make -C src/pl/plpython3 DESTDIR="${pkgdir}" install
+  #make -C contrib/hstore_plpython3 DESTDIR="${pkgdir}" install
+  #make -C contrib/ltree_plpython3 DESTDIR="${pkgdir}" install
+
+  # we don't want these, they are in the -libs package
+  for dir in src/interfaces src/bin/pg_config src/bin/pg_dump src/bin/psql src/bin/scripts; do
+    make -C ${dir} DESTDIR="${pkgdir}" uninstall
+  done
+  for util in pg_config pg_dump pg_dumpall pg_restore psql \
+      clusterdb createdb createuser dropdb dropuser pg_isready reindexdb vacuumdb; do
+    rm "${pkgdir}"/opt/${pkgbase}/share/man/man1/${util}.1
+  done
+
+  install -Dm 644 COPYRIGHT -t "${pkgdir}/opt/${pkgbase}/share/licenses/${pkgname}"
+
+  popd
+  install -Dm 755 postgresql-check-db-dir -t "${pkgdir}/opt/${pkgbase}/bin"
+
+  #install -Dm 644 postgresql.pam "${pkgdir}/etc/pam.d/${pkgname}"
+
+  install -Dm 644 postgresql.service  "${pkgdir}/usr/lib/systemd/system/${pkgname}.service"
+  install -Dm 644 postgresql.sysusers "${pkgdir}/usr/lib/sysusers.d/${pkgname}.conf"
+  install -Dm 644 postgresql.tmpfiles "${pkgdir}/usr/lib/tmpfiles.d/${pkgname}.conf"
+
+  # clean up unneeded installed items
+  rm -rf "${pkgdir}/opt/${pkgbase}/include/internal"
+  rm -rf "${pkgdir}/opt/${pkgbase}/include/informix"
+  rm -rf "${pkgdir}/opt/${pkgbase}/include/libpq"
+  find "${pkgdir}//opt/${pkgbase}/include" -maxdepth 1 -type f -execdir rm {} +
+  rmdir "${pkgdir}/opt/${pkgbase}/share/doc/html"
+}
+
+# vim: ts=2 sw=2 et:
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/pgenv.sh b/arch/DockerBuildEnvironment/packages/postgresql9/pgenv.sh
new file mode 100755
index 000000000..49fa2a0d0
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/pgenv.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+export PGDATA=/var/lib/postgres/data11
+export PATH=/opt/postgresql11/bin:$PATH
+export LD_LIBRARY_PATH=/opt/postgresql11/lib
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-9.6.24.tar.bz2 b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-9.6.24.tar.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..b9642ce9064fb0bc50393af4ef2e574b023a019e
GIT binary patch
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-check-db-dir b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-check-db-dir
new file mode 100755
index 000000000..8d4bac149
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-check-db-dir
@@ -0,0 +1,42 @@
+#!/bin/sh
+
+# This script verifies that the postgresql data directory has been correctly
+# initialized.  We do not want to automatically initdb it, because that has
+# a risk of catastrophic failure (ie, overwriting a valuable database) in
+# corner cases, such as a remotely mounted database on a volume that's a
+# bit slow to mount.  But we can at least emit a message advising newbies
+# what to do.
+
+PGDATA="$1"
+
+if [ -z "$PGDATA" ]
+then
+    echo "Usage: $0 database-path"
+    exit 1
+fi
+
+# PGMAJORVERSION is major version
+PGMAJORVERSION=11
+
+# Check for the PGDATA structure
+if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
+then
+    # Check version of existing PGDATA
+    if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
+    then
+        : A-OK
+    else
+        echo $"An old version of the database format was found."
+        echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
+        echo $"See http://www.postgresql.org/docs/$PGMAJORVERSION/static/upgrading.html"
+        exit 1
+    fi
+else
+    # No existing PGDATA! Warn the user to initdb it.
+    echo $"\"$PGDATA\" is missing or empty. Use a command like"
+    echo $"  su - postgres -c \"initdb --locale en_US.UTF-8 -D '$PGDATA'\""
+    echo $"with relevant options, to initialize the database cluster."
+    exit 1
+fi
+
+exit 0
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-command.patch b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-command.patch
new file mode 100644
index 000000000..ad832c25d
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-command.patch
@@ -0,0 +1,11 @@
+--- postgresql-11.9/src/backend/commands/collationcmds.c.ori	2020-08-10 23:17:40.000000000 +0200
++++ postgresql-11.9/src/backend/commands/collationcmds.c	2022-03-29 14:33:57.291063452 +0200
+@@ -444,7 +444,7 @@ get_icu_language_tag(const char *localen
+ 	UErrorCode	status;
+ 
+ 	status = U_ZERO_ERROR;
+-	uloc_toLanguageTag(localename, buf, sizeof(buf), TRUE, &status);
++	uloc_toLanguageTag(localename, buf, sizeof(buf), true, &status);
+ 	if (U_FAILURE(status))
+ 		ereport(ERROR,
+ 				(errmsg("could not convert locale name \"%s\" to language tag: %s",
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-perl-rpath.patch b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-perl-rpath.patch
new file mode 100644
index 000000000..cad6118d6
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-perl-rpath.patch
@@ -0,0 +1,13 @@
+diff -upr postgresql-11.9/src/pl/plperl/GNUmakefile.orig postgresql-11.9/src/pl/plperl/GNUmakefile
+--- postgresql-11.9/src/pl/plperl/GNUmakefile.orig	2022-03-27 16:11:28.482361857 +0200
++++ postgresql-11.9/src/pl/plperl/GNUmakefile	2022-03-27 16:15:57.076855848 +0200
+@@ -55,6 +55,9 @@ endif # win32
+ 
+ SHLIB_LINK = $(perl_embed_ldflags)
+ 
++# Force rpath to be used even though we disable it everywhere else
++SHLIB_LINK += $(rpath)
++
+ REGRESS_OPTS = --dbname=$(PL_TESTDB) --load-extension=plperl  --load-extension=plperlu
+ REGRESS = plperl plperl_lc plperl_trigger plperl_shared plperl_elog plperl_util plperl_init plperlu plperl_array plperl_call plperl_transaction
+ # if Perl can support two interpreters in one backend,
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-run-socket.patch b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-run-socket.patch
new file mode 100644
index 000000000..cf191faae
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql-run-socket.patch
@@ -0,0 +1,12 @@
+diff -upr postgresql-11.9/src/include/pg_config_manual.h.orig postgresql-11.9/src/include/pg_config_manual.h
+--- postgresql-11.9/src/include/pg_config_manual.h.orig	2022-03-27 15:53:14.701448511 +0200
++++ postgresql-11.9/src/include/pg_config_manual.h	2022-03-27 16:04:25.334369068 +0200
+@@ -179,7 +179,7 @@
+  * here's where to twiddle it.  You can also override this at runtime
+  * with the postmaster's -k switch.
+  */
+-#define DEFAULT_PGSOCKET_DIR  "/tmp"
++#define DEFAULT_PGSOCKET_DIR  "/run/postgresql"
+ 
+ /*
+  * This is the default event source for Windows event log.
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.install b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.install
new file mode 100644
index 000000000..0edb9fbe3
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.install
@@ -0,0 +1,7 @@
+post_upgrade() {
+  # Prints the warning message if the database version on disk
+  # does not match the PostgreSQL major version.
+  if [ -d /var/lib/postgres/data11 ]; then
+	/opt/postgresql14/bin/postgresql-check-db-dir /var/lib/postgres/data || true
+  fi
+}
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.service b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.service
new file mode 100644
index 000000000..722f7ee4f
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.service
@@ -0,0 +1,46 @@
+[Unit]
+Description=PostgreSQL 11 database server
+After=network.target
+
+[Service]
+Type=notify
+TimeoutSec=120
+User=postgres
+Group=postgres
+
+Environment=PGROOT=/var/lib/postgres
+Environment=PATH=/opt/postgresql11/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+Environment=LD_LIBRARY_PATH=/opt/postgresql11/lib
+
+SyslogIdentifier=postgres
+PIDFile=/var/lib/postgres/data11/postmaster.pid
+RuntimeDirectory=postgresql
+RuntimeDirectoryMode=755
+
+ExecStartPre=/opt/postgresql11/bin/postgresql-check-db-dir ${PGROOT}/data11
+ExecStart=/opt/postgresql11/bin/postgres -D ${PGROOT}/data11
+ExecStartPost=/usr/bin/echo "Before using, source /opt/postgresql11/bin/pgenv.sh to set PostgreSQL environment"
+ExecReload=/bin/kill -HUP ${MAINPID}
+KillMode=mixed
+KillSignal=SIGINT
+
+# Due to PostgreSQL's use of shared memory, OOM killer is often overzealous in
+# killing Postgres, so adjust it downward
+OOMScoreAdjust=-200
+
+# Additional security-related features
+PrivateTmp=true
+ProtectHome=true
+ProtectSystem=full
+NoNewPrivileges=true
+ProtectControlGroups=true
+ProtectKernelModules=true
+ProtectKernelTunables=true
+PrivateDevices=true
+RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
+RestrictNamespaces=true
+RestrictRealtime=true
+SystemCallArchitectures=native
+
+[Install]
+WantedBy=multi-user.target
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.sysusers b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.sysusers
new file mode 100644
index 000000000..a1711b1cc
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.sysusers
@@ -0,0 +1 @@
+u postgres - "PostgreSQL user" /var/lib/postgres /bin/bash
diff --git a/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.tmpfiles b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.tmpfiles
new file mode 100644
index 000000000..f01dcc0e4
--- /dev/null
+++ b/arch/DockerBuildEnvironment/packages/postgresql9/postgresql.tmpfiles
@@ -0,0 +1,2 @@
+d /var/lib/postgres/data11 700 postgres postgres
+h /var/lib/postgres/data11 -   -        -        - +C
-- 
2.43.0

