feat(postgres): add latest releases

This commit is contained in:
AJ ONeal
2024-10-14 07:41:48 +00:00
parent c503f105fb
commit 500b69e70c
2 changed files with 205 additions and 152 deletions
+83 -64
View File
@@ -1,76 +1,95 @@
#!/bin/sh
# shellcheck disable=SC2034
set -e
set -u
__init_postgres() {
set -e
set -u
pkg_cmd_name="postgres"
#WEBI_SINGLE=""
####################
# Install postgres #
####################
POSTGRES_DATA_DIR=$HOME/.local/share/postgres/var
# Every package should define these 6 variables
pkg_cmd_name="postgres"
pkg_get_current_version() {
# 'postgres --version' has output in this format:
# postgres (PostgreSQL) 10.13
# This trims it down to just the version number:
# 10.13
postgres --version 2> /dev/null | head -n 1 | cut -d' ' -f3
}
pkg_dst_cmd="${HOME}/.local/opt/postgres/bin/postgres"
pkg_dst_dir="${HOME}/.local/opt/postgres"
pkg_dst="${pkg_dst_dir}"
pkg_install() {
# mkdir -p $HOME/.local/opt
mkdir -p "$(dirname "$pkg_src")"
pkg_src_cmd="${HOME}/.local/opt/postgres-v${WEBI_VERSION}/bin/postgres"
pkg_src_dir="${HOME}/.local/opt/postgres-v${WEBI_VERSION}"
pkg_src="${pkg_src_dir}"
# mv ./pgqsl* "$HOME/.local/opt/postgres-v10.13"
mv ./"p"* "$pkg_src"
}
POSTGRES_DATA_DIR="$HOME/.local/share/postgres/var"
pkg_link() {
# rm -f "$HOME/.local/opt/postgres"
rm -f "$pkg_dst"
rm -f "$HOME/Applications/pgAdmin"*.app || true
rm -f "/Applications/pgAdmin"*.app || true
pkg_get_current_version() {
# 'postgres --version' has output in this format:
# postgres (PostgreSQL) 17.0
# This trims it down to just the version number:
# 17.0
postgres --version 2> /dev/null | head -n 1 | cut -d' ' -f3
}
# ln -s "$HOME/.local/opt/postgres-v10.13" "$HOME/.local/opt/postgres"
ln -s "$pkg_src" "$pkg_dst"
if [ "Darwin" = "$(uname -s)" ]; then
mkdir -p /Applications
ln -s "$pkg_src/pgAdmin 4.app" "/Applications/pgAdmin 4.app" || true
if [ -e "$pkg_src/pgAdmin 4.app/Contents/Resources/venv/lib/libpython3.8.dylib" ]; then
# a simple patch to fix the bad link in the package
rm "$pkg_src/pgAdmin 4.app/Contents/Resources/venv/lib/libpython3.8.dylib"
ln -s "../../../Frameworks/Python" "$pkg_src/pgAdmin 4.app/Contents/Resources/venv/lib/libpython3.8.dylib"
pkg_install() {
# mkdir -p $HOME/.local/opt
mkdir -p "$(dirname "$pkg_src")"
# mv ./postgres-17 "$HOME/.local/opt/postgres-v17.0"
# mv ./pgqsl* "$HOME/.local/opt/postgres-v10.13" # old version
mv ./"p"* "$pkg_src"
}
pkg_link() {
# rm -f "$HOME/.local/opt/postgres"
rm -f "$pkg_dst"
rm -f "$HOME/Applications/pgAdmin"*.app || true
rm -f "/Applications/pgAdmin"*.app || true
# ln -s "$HOME/.local/opt/postgres-v17.0" "$HOME/.local/opt/postgres"
# for the old postgres version
ln -s "$pkg_src" "$pkg_dst"
if test "Darwin" = "$(uname -s)" && test -e "$pkg_src/pgAdmin 4.app"; then
mkdir -p /Applications
ln -s "$pkg_src/pgAdmin 4.app" "/Applications/pgAdmin 4.app" || true
if test -e "$pkg_src/pgAdmin 4.app/Contents/Resources/venv/lib/libpython3.8.dylib"; then
# a simple patch to fix the bad link in the package
rm "$pkg_src/pgAdmin 4.app/Contents/Resources/venv/lib/libpython3.8.dylib"
ln -s "../../../Frameworks/Python" "$pkg_src/pgAdmin 4.app/Contents/Resources/venv/lib/libpython3.8.dylib"
fi
fi
fi
}
pkg_post_install() {
webi_path_add "$pkg_dst_bin"
#echo "Initializing PostgreSQL with database at $POSTGRES_DATA_DIR/"
PWFILE="$(pwd)/pwfile.tmp"
mkdir -p "$POSTGRES_DATA_DIR"
chmod 0700 "$POSTGRES_DATA_DIR"
if ! test -f "$POSTGRES_DATA_DIR/postgresql.conf"; then
echo "postgres" > "$PWFILE"
"$pkg_src/bin/initdb" \
-D "$POSTGRES_DATA_DIR/" \
--username postgres --pwfile "$PWFILE" \
--auth-local=password --auth-host=password
fi
}
pkg_done_message() {
# TODO show with serviceman
echo "Installed 'postgres' and 'psql' at $pkg_dst"
echo ""
echo "IMPORTANT!!!"
echo ""
echo "Database initialized at $POSTGRES_DATA_DIR:"
echo " postgres -D $POSTGRES_DATA_DIR -p 5432"
echo ""
echo "Username and password set to 'postgres':"
echo " psql 'postgres://postgres:postgres@localhost:5432/postgres'"
echo ""
}
}
pkg_post_install() {
webi_path_add "$pkg_dst_bin"
#echo "Initializing PostgreSQL with database at $POSTGRES_DATA_DIR/"
PWFILE="$(pwd)/pwfile.tmp"
mkdir -p "$POSTGRES_DATA_DIR"
chmod 0700 "$POSTGRES_DATA_DIR"
if [ ! -f "$POSTGRES_DATA_DIR/postgresql.conf" ]; then
echo "postgres" > "$PWFILE"
"$pkg_src/bin/initdb" \
-D "$POSTGRES_DATA_DIR/" \
--username postgres --pwfile "$PWFILE" \
--auth-local=password --auth-host=password
fi
}
pkg_done_message() {
# TODO show with serviceman
echo "Installed 'postgres' and 'psql' at $pkg_dst"
echo ""
echo "IMPORTANT!!!"
echo ""
echo "Database initialized at $POSTGRES_DATA_DIR:"
echo " postgres -D $POSTGRES_DATA_DIR -p 5432"
echo ""
echo "Username and password set to 'postgres':"
echo " psql 'postgres://postgres:postgres@localhost:5432/postgres'"
echo ""
}
__init_postgres
+122 -88
View File
@@ -1,95 +1,129 @@
'use strict';
module.exports = async function () {
// TODO scape some combination of
// - https://www.enterprisedb.com/download-postgresql-binaries
// - https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
// - https://www.postgresql.org/download/
// - https://www.postgresql.org/download/linux/debian/
return {
releases: [
{
name: 'postgresql-10.12-1-linux-x64-binaries.tar.gz',
version: '10.12',
lts: false,
channel: 'stable',
date: '',
os: 'linux',
arch: 'amd64',
ext: 'tar',
download: '',
},
{
name: 'postgresql-10.12-1-linux-binaries.tar.gz',
version: '10.12',
lts: false,
channel: 'stable',
date: '',
os: 'linux',
arch: 'x86',
ext: 'tar',
download: '',
},
{
name: 'postgresql-10.12-1-osx-binaries.zip',
version: '10.12',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
{
name: 'postgresql-10.13-1-osx-binaries.zip',
version: '10.13',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
{
name: 'postgresql-11.8-1-osx-binaries.zip',
version: '11.8',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
{
name: 'postgresql-12.3-1-osx-binaries.zip',
version: '12.3',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
].map(function (rel) {
rel._version = `${rel.version}-1`;
rel.download =
'https://get.enterprisedb.com/postgresql/' +
rel.name +
'?ls=Crossover&type=Crossover';
return rel;
}),
download: '',
_names: ['PostgreSQL', 'postgresql', 'Postgres', 'postgres', 'binaries'],
};
let Releases = module.exports;
var Github = require('../_common/github.js');
var owner = 'bnnanet';
var repo = 'postgresql-releases';
let originalReleases = {
_names: ['PostgreSQL', 'postgresql', 'Postgres', 'postgres', 'binaries'],
releases: [
{
name: 'postgresql-10.12-1-linux-x64-binaries.tar.gz',
version: '10.12',
lts: false,
channel: 'stable',
date: '',
os: 'linux',
arch: 'amd64',
libc: 'gnu',
ext: 'tar',
download: '',
},
{
name: 'postgresql-10.12-1-linux-binaries.tar.gz',
version: '10.12',
lts: false,
channel: 'stable',
date: '',
os: 'linux',
arch: 'x86',
libc: 'gnu',
ext: 'tar',
download: '',
},
{
name: 'postgresql-10.12-1-osx-binaries.zip',
version: '10.12',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
{
name: 'postgresql-10.13-1-osx-binaries.zip',
version: '10.13',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
{
name: 'postgresql-11.8-1-osx-binaries.zip',
version: '11.8',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
{
name: 'postgresql-12.3-1-osx-binaries.zip',
version: '12.3',
lts: false,
channel: 'stable',
date: '',
os: 'macos',
arch: 'amd64',
ext: 'zip',
download: '',
},
].map(function (rel) {
//@ts-ignore - it's a special property
rel._version = `${rel.version}-1`;
rel.download = `https://get.enterprisedb.com/postgresql/${rel.name}?ls=Crossover&type=Crossover`;
return rel;
}),
download: '',
};
Releases.latest = async function () {
let all = await Github.getDistributables(null, owner, repo);
/** @type {Array<Awaited<ReturnType<typeof Github.getDistributables>>>[Number]["releases"]} */
let distributables = [];
for (let dist of all.releases) {
console.log(dist);
console.log(dist.name, 'niche', /psql|baseline/.test(dist.name));
let isNiche = /psql|baseline/.test(dist.name);
if (isNiche) {
continue;
}
// REL_17_0 => 17.0
dist.version = dist.version.replace(/REL_/g, '');
dist.version = dist.version.replace(/_/g, '.');
let isHardMusl = dist.name.includes('musl');
if (isHardMusl) {
Object.assign(dist, { libc: 'musl', _musl: true });
}
distributables.push(dist);
}
all.releases = distributables;
Object.assign(all, { _names: originalReleases._names });
//@ts-ignore - mixing old and new release types
all.releases = all.releases.concat(originalReleases.releases);
return all;
};
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
all = require('../_webi/normalize.js')(all);
console.info(JSON.stringify(all));
Releases.latest().then(function (all) {
let normalize = require('../_webi/normalize.js');
all = normalize(all);
let json = JSON.stringify(all, null, 2);
console.info(json);
});
}