This commit is contained in:
tavo 2025-01-09 11:02:47 -06:00
parent 2a1352f6e0
commit ea9acaaded
Signed by: tavo
GPG key ID: D490F27B624CECB0
3 changed files with 76 additions and 0 deletions

36
wrappers/pgsql-start Executable file
View file

@ -0,0 +1,36 @@
#!/bin/sh
PODMAN_NAME="PostgreSQL"
PGSQL_IMAGE="docker.io/library/postgres"
: "${HOST:=localhost}"
: "${PORT:=5455}"
: "${PASS:=1234}"
: "${USER:=postgres}"
: "${DB:=local}"
if ! command -v podman >/dev/null 2>&1 ; then
echo "podman not found in PATH"
exit 1
fi
if command -v fuser >/dev/null 2>&1 ; then
if fuser "$PORT"/tcp >/dev/null 2>&1 ; then
echo "Port already in use"
exit 1
fi
fi
if ! podman run \
--name "$PODMAN_NAME" \
-p "$PORT":5432 \
-e POSTGRES_USER="$USER" \
-e POSTGRES_PASSWORD="$PASS" \
-e POSTGRES_DB="$DB" \
--replace \
-d \
"$PGSQL_IMAGE" 1>&- ; then
exit 1
fi
echo "postgresql://$USER:$PASS@$HOST:$PORT/$DB"

7
wrappers/pgsql-stop Executable file
View file

@ -0,0 +1,7 @@
#!/bin/sh
PODMAN_NAME="PostgreSQL"
if ! podman stop "$PODMAN_NAME" 1>&- ; then
echo "Failed to stop podman running postgres"
fi

33
wrappers/pgweb Executable file
View file

@ -0,0 +1,33 @@
#!/bin/sh
PGWEB="$HOME/.local/share/pgweb/pgweb_linux_amd64"
if ! [ -d "${PGWEB%/*}" ] ; then
mkdir -p "${PGWEB%/*}"
fi
LATEST="$(curl -s https://api.github.com/repos/sosedoff/pgweb/releases/latest |
grep '"tag_name":' | cut -d'"' -f 4)"
INSTALLED="$($PGWEB --version | cut -d ' ' -f 2)"
if [ "$INSTALLED" != "$LATEST" ] ; then
opt="$(printf 'Yes\nNo\n' | menu "Newer pgweb version available, update?")"
if [ "$opt" = "Yes" ] ; then
echo "Updating pgweb..."
if ! curl -L --progress-bar -o "$PGWEB.zip" \
https://github.com/sosedoff/pgweb/releases/latest/download/pgweb_linux_amd64.zip ; then
echo "Error updating pgweb"
exit 1
fi
(cd "${PGWEB%/*}" && unzip "$PGWEB.zip")
chmod +x "$PGWEB"
fi
unset opt
fi
exec $PGWEB