mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-08-18 19:46:59 +00:00
feat(postgres): add pg as alias
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
---
|
||||
title: PG (Postgres alias)
|
||||
homepage: https://webinstall.dev/postgres
|
||||
tagline: |
|
||||
Alias for https://webinstall.dev/postgres
|
||||
alias: postgres
|
||||
description: |
|
||||
See https://webinstall.dev/postgres
|
||||
---
|
||||
|
||||
Alias for https://webinstall.dev/postgres
|
||||
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
__init_pg() {
|
||||
set -e
|
||||
set -u
|
||||
|
||||
##################################
|
||||
# Install postgres server+client #
|
||||
##################################
|
||||
|
||||
# Every package should define these 6 variables
|
||||
pkg_cmd_name="postgres"
|
||||
|
||||
pkg_dst_cmd="${HOME}/.local/opt/postgres/bin/postgres"
|
||||
pkg_dst_bin="${HOME}/.local/opt/postgres/bin"
|
||||
pkg_dst_dir="${HOME}/.local/opt/postgres"
|
||||
pkg_dst="${pkg_dst_dir}"
|
||||
|
||||
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}"
|
||||
|
||||
POSTGRES_DATA_DIR=$HOME/.local/share/postgres/var
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
pkg_install() {
|
||||
# mkdir -p $HOME/.local/opt
|
||||
mkdir -p "$(dirname "$pkg_src")"
|
||||
|
||||
# mv ./postgres-17 "$HOME/.local/opt/postgres-v17.0"
|
||||
mv ./"postgres-"* "$pkg_src"
|
||||
}
|
||||
|
||||
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 $(t_pkg "$pkg_cmd_name v$WEBI_VERSION") (and $(t_pkg "psql")) to $(t_link "$(fn_sub_home "${pkg_dst_bin}")")"
|
||||
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_pg
|
||||
@@ -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 isServer = dist.name.includes('postgres');
|
||||
if (!isServer) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user