Skip to content

Commit 15dbe0c

Browse files
committed
POC Trunk binary distribution format
`trunk.mk` copies a bunch of the `install` target from PGXS and modifies it to install into a organized according to the [proposed format]. The adds the `make` variables `DISTVERSION`, `LICENSE`, and `LANGUAGE`, but otherwise depends on variables defined by PGXS. It uses `jq` to build `trunk.json`, `shasum` to build the `digests` file, and `tar` to create the `*.trunk` artifact as a tarball. `install_trunk` is a simple shell script to demonstrate unpacking, validating, and installing a trunk file. It too relies on `jq`, `shasum`, and `tar`, and uses `rsync` to do the actual installation. It also does basic trunk version, platform, and Postgres version validation. [proposed format]: https://github.com/orgs/pgxn/discussions/2
1 parent 85db4db commit 15dbe0c

File tree

4 files changed

+386
-2
lines changed

4 files changed

+386
-2
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ results/
44
*.dll
55
tmp/
66
*.o
7+
*.bc
78
regression.diffs
89
regression.out
910
/sql/semver--?.??.?.sql
1011
/semver-*
1112
/latest-changes.md
12-
/src/*.bc
1313
/semver_binary_copy.bin
1414
/.vscode
1515
/*.bin

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ DISTVERSION = $(shell grep -m 1 '[[:space:]]\{3\}"version":' META.json | \
66
sed -e 's/[[:space:]]*"version":[[:space:]]*"\([^"]*\)",\{0,1\}/\1/')
77

88
MODULEDIR = $(EXTENSION)
9-
DATA = $(wildcard sql/*.sql)
9+
DATA = $(wildcard sql/*--*.sql)
1010
DOCS = $(wildcard doc/*.mmd)
1111
TESTS = $(wildcard test/sql/*.sql)
1212
REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
@@ -22,6 +22,7 @@ endif
2222

2323
PGXS := $(shell $(PG_CONFIG) --pgxs)
2424
include $(PGXS)
25+
include ./trunk.mk
2526

2627
all: sql/$(EXTENSION)--$(EXTVERSION).sql
2728

install_trunk

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/bin/bash
2+
3+
# POC for installing Trunk format binaries created with trunk.mk. Requires:
4+
#
5+
# * bash
6+
# * tar
7+
# * shasum
8+
# * jq
9+
# * uname
10+
# * pg_config
11+
# * rsync
12+
13+
trap 'exit' ERR
14+
set -E
15+
16+
install_trunk() {
17+
local trunk=$1
18+
19+
if [ -z "$trunk" ]; then
20+
printf "Usage:\n\n %s PACKAGE_PATH\n" "$0"
21+
exit 1
22+
fi
23+
24+
# Determine the platform.
25+
local my_os my_osv my_arch
26+
my_os=$(uname | tr '[:upper:]' '[:lower:]')
27+
my_osv=$(uname -r)
28+
my_arch="$(uname -m)"
29+
if [ "$my_arch" == "x86_64" ]; then my_arch=amd64; fi
30+
31+
# Unpack.
32+
printf "Unpacking %s\n" "$trunk"
33+
tar zxf "$trunk"
34+
35+
# Go into the directory
36+
local dir="${trunk%.*}"
37+
cd "$dir" || exit
38+
39+
# Verify the checksums.
40+
printf "Verifying all checksums..."
41+
# XXX This does not fail if a file isn't present in digests.
42+
shasum --check -b --strict digests
43+
printf "Done!\n"
44+
45+
# Verify the Trunk version
46+
printf "Verifying compatibility with Trunk package 0.1.0\n"
47+
local tv
48+
tv=$(jq -r .trunk trunk.json)
49+
if [ "$tv" != "0.1.0" ]; then
50+
printf "Unsupported Trunk format version %s\n" "$tv"
51+
exit 1
52+
fi
53+
54+
# Verify the Postgres version.
55+
local pkg_pg my_pg
56+
my_pg=$(pg_config --version | sed -E 's/^[^ ]+ ([^ ]+).*$/\1/')
57+
printf "Verifying compatibility with PostgreSQL %s\n" "$my_pg"
58+
pkg_pg=$(jq -r .postgres.version trunk.json)
59+
if [ "$pkg_pg" != "$my_pg" ]; then
60+
printf "Trunk package contains binaries for Postgres %s but this host runs Postgres %s\n" "$pkg_pg" "$my_pg"
61+
exit 1
62+
fi
63+
64+
printf "Verifying compatibility with %s/%s:%s\n" "$my_os" "$my_arch" "$my_osv"
65+
local pkg_os
66+
pkg_os=$(jq -r .platform.os trunk.json)
67+
if [ "$pkg_os" != "any" ]; then
68+
# Verify the OS
69+
if [ "$pkg_os" != "$my_os" ]; then
70+
printf "Trunk package contains %s binaries but this host runs %s\n" "$pkg_os" "$my_os"
71+
exit 1
72+
fi
73+
74+
# Verify the architecture.
75+
local pkg_arch
76+
pkg_arch=$(jq -r .platform.arch trunk.json)
77+
if [ "$pkg_arch" != "$my_arch" ]; then
78+
printf "Trunk package contains %s binaries but this host runs %s\n" "$pkg_arch" "$my_arch"
79+
exit 1
80+
fi
81+
fi
82+
83+
# Make sure we have pgsql directory.
84+
if [ ! -d 'pgsql' ]; then
85+
printf "Package contains no install files; exiting\n"
86+
exit 1
87+
fi
88+
89+
cd 'pgsql' || exit
90+
for subdir in *; do
91+
[[ -d "$subdir" ]] || continue
92+
case $subdir in
93+
share)
94+
install_dir "$subdir" "$(pg_config --sharedir)"
95+
;;
96+
pkglib)
97+
install_dir "$subdir" "$(pg_config --pkglibdir)"
98+
;;
99+
pkginclude)
100+
install_dir "$subdir" "$(pg_config --pkgincludedir)"
101+
;;
102+
lib)
103+
install_dir "$subdir" "$(pg_config --libdir)"
104+
;;
105+
include)
106+
install_dir "$subdir" "$(pg_config --includedir)"
107+
;;
108+
bin)
109+
install_dir "$subdir" "$(pg_config --bindir)"
110+
;;
111+
doc)
112+
install_dir "$subdir" "$(pg_config --docdir)"
113+
;;
114+
man)
115+
install_dir "$subdir" "$(pg_config --mandir)"
116+
;;
117+
html)
118+
install_dir "$subdir" "$(pg_config --htmldir)"
119+
;;
120+
locale)
121+
install_dir "$subdir" "$(pg_config --localedir)"
122+
;;
123+
sysconf)
124+
install_dir "$subdir" "$(pg_config --sysconfdir)"
125+
;;
126+
*)
127+
printf "Unknown install directory %s; skipping\n" "$subdir"
128+
;;
129+
esac
130+
done
131+
132+
}
133+
134+
install_dir() {
135+
local src="$1"
136+
local dst="$2"
137+
printf "Installing %s into %s..." "$src" "$dst"
138+
cd "$src" || exit
139+
rsync -q -a -v . "$dst" || exit
140+
printf "Done\n"
141+
cd ..
142+
}
143+
144+
install_trunk "$@"

0 commit comments

Comments
 (0)