feat: add psql as its own installer

This commit is contained in:
AJ ONeal
2024-10-12 02:20:50 +00:00
parent a2034c99e9
commit 502e3d6aa0
3 changed files with 124 additions and 0 deletions

22
psql/README.md Normal file
View File

@@ -0,0 +1,22 @@
---
title: PSQL (PostgreSQL Client)
homepage: https://www.postgresql.org/
tagline: |
psql: REPL for Postgres that supports standard TLS (+SNI,ALPN), .pgpass, and .psqlrc
---
To update or switch versions, run `webi psql@stable` (or `@v17.0`, `@beta`,
etc).
### Files
These are the files / directories that are created and/or modified with this
install:
```text
~/.config/envman/PATH.env
~/.local/opt/psql/
~/.pgpass
~/.psqlrc
~/.config/psql/
```

52
psql/install.sh Normal file
View File

@@ -0,0 +1,52 @@
#!/bin/sh
# shellcheck disable=SC2034
__init_psql() {
set -e
set -u
##################################
# Install psql (postgres client) #
##################################
# Every package should define these 6 variables
pkg_cmd_name="psql"
pkg_dst_cmd="${HOME}/.local/opt/psql/bin/psql"
pkg_dst_dir="${HOME}/.local/opt/psql"
pkg_dst="${pkg_dst_dir}"
pkg_src_cmd="${HOME}/.local/opt/psql-v${WEBI_VERSION}/bin/psql"
pkg_src_dir="${HOME}/.local/opt/psql-v${WEBI_VERSION}"
pkg_src="${pkg_src_dir}"
pkg_get_current_version() {
# 'psql --version' has output in this format:
# psql (PostgreSQL) 17.0
# This trims it down to just the version number:
# 17.0
psql --version 2> /dev/null | head -n 1 | cut -d' ' -f3
}
pkg_install() {
# mkdir -p $HOME/.local/opt
mkdir -p "$(dirname "$pkg_src")"
# mv ./psql-17 "$HOME/.local/opt/psql-v17.0"
mv ./"psql-"* "$pkg_src"
# initdb is mistakenly included with the client libs
rm -f "$pkg_src_dir"/bin/initdb
rm -f "$pkg_dst_dir"/bin/initdb
}
pkg_done_message() {
echo " Installed $(t_pkg "$pkg_cmd_name v$WEBI_VERSION") as $(t_link "$(fn_sub_home "${pkg_dst_cmd}")")"
echo ""
echo "Connect to PostgreSQL database with the default username and password:"
echo " psql 'postgres://postgres:postgres@localhost:5432/postgres'"
echo ""
}
}
__init_psql

50
psql/releases.js Normal file
View File

@@ -0,0 +1,50 @@
'use strict';
let Releases = module.exports;
var Github = require('../_common/github.js');
var owner = 'bnnanet';
var repo = 'postgresql-releases';
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) {
let isBaseline = dist.name.includes('baseline');
if (isBaseline) {
continue;
}
let isClient = dist.name.includes('psql');
if (!isClient) {
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: ['postgres', 'postgresql', 'pgsql', 'psql'] });
return all;
};
if (module === require.main) {
Releases.latest().then(function (all) {
let normalize = require('../_webi/normalize.js');
all = normalize(all);
let json = JSON.stringify(all, null, 2);
console.info(json);
});
}