Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6Kg9RWSTJzyz6KP9X
41 lines
2.3 KiB
Bash
Executable File
41 lines
2.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Starts the two servers the tests talk to, without Docker. Idempotent. Defaults match Db.java.
|
|
# PostgreSQL 18.6 : zonky embedded-postgres-binaries-linux-amd64 18.6.0 from Maven Central (initdb, pg_ctl, postgres only), port 55432
|
|
# MySQL 8.0.x : Ubuntu packages mysql-server-core-8.0 + mysql-client-core-8.0, port 53306
|
|
# Both refuse to run as root, so this script creates two throwaway OS users (pgj, myj). Run it as root in a disposable sandbox.
|
|
set -euo pipefail
|
|
BASE="${BASE:-/tmp/work/dbs}"
|
|
PGPORT="${PGPORT:-55432}"; MYPORT="${MYPORT:-53306}"
|
|
mkdir -p "$BASE/pg" "$BASE/mysql"
|
|
id pgj >/dev/null 2>&1 || useradd -m pgj
|
|
id myj >/dev/null 2>&1 || useradd -m myj
|
|
|
|
if [ ! -x "$BASE/pg/pg/bin/postgres" ]; then
|
|
curl -sSfL -o "$BASE/pg/pg.jar" \
|
|
https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-linux-amd64/18.6.0/embedded-postgres-binaries-linux-amd64-18.6.0.jar
|
|
(cd "$BASE/pg" && unzip -o -q pg.jar && mkdir -p pg && tar -xJf postgres-linux-x86_64.txz -C pg)
|
|
fi
|
|
chmod -R a+rX "$BASE/pg"
|
|
if [ ! -f "$BASE/pg/data/PG_VERSION" ]; then
|
|
mkdir -p "$BASE/pg/data"; chown pgj "$BASE/pg/data"
|
|
su pgj -c "cd /tmp && $BASE/pg/pg/bin/initdb -D $BASE/pg/data -U postgres -A trust -E UTF8 >/dev/null"
|
|
fi
|
|
su pgj -c "$BASE/pg/pg/bin/pg_ctl -D $BASE/pg/data -o '-p $PGPORT -k /tmp' -l $BASE/pg/data/pg.log -w start" || true
|
|
|
|
if ! command -v mysqld >/dev/null; then
|
|
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends mysql-server-core-8.0 mysql-client-core-8.0
|
|
fi
|
|
if [ ! -d "$BASE/mysql/data/mysql" ]; then
|
|
mkdir -p "$BASE/mysql/data"; chown -R myj "$BASE/mysql"
|
|
su myj -c "mysqld --no-defaults --initialize-insecure --datadir=$BASE/mysql/data >/dev/null 2>&1"
|
|
fi
|
|
chown -R myj "$BASE/mysql"
|
|
if ! mysql -h127.0.0.1 -P"$MYPORT" -uroot -e 'select 1' >/dev/null 2>&1; then
|
|
su myj -c "nohup mysqld --no-defaults --secure-file-priv=NULL --datadir=$BASE/mysql/data --port=$MYPORT \
|
|
--socket=$BASE/mysql/my.sock --mysqlx=OFF --bind-address=127.0.0.1 --pid-file=$BASE/mysql/my.pid \
|
|
--log-error=$BASE/mysql/err.log >/dev/null 2>&1 &"
|
|
for _ in $(seq 1 40); do mysql -h127.0.0.1 -P"$MYPORT" -uroot -e 'select 1' >/dev/null 2>&1 && break; sleep 1; done
|
|
fi
|
|
psql -h 127.0.0.1 -p "$PGPORT" -U postgres -Atc 'select version()'
|
|
mysql -h127.0.0.1 -P"$MYPORT" -uroot -Ne 'select version()'
|