matabas/buildScripts/setupEnv.sh

51 lines
1.1 KiB
Bash
Raw Normal View History

2023-08-08 19:09:15 +02:00
set -e
2023-08-09 22:41:11 +02:00
export PGPORT=2137
export PGDATABASE=matabas
export PGUSER=matabasare
2023-08-08 19:09:15 +02:00
log() {
2023-08-09 19:55:23 +02:00
printf "\e[1m\e[38;5;87m==>\e[0m\e[1m %s%s\e[0m\n" "$1" "${2:-.}"
2023-08-08 19:09:15 +02:00
}
2023-08-08 20:58:17 +02:00
exitHook() {
2023-08-09 19:55:23 +02:00
log "Stoppar brevekorren"
2023-08-08 20:58:17 +02:00
pg_ctl stop --pgdata=./matabas-db
}
2023-08-09 19:55:23 +02:00
log "Letar efter existerande brevekorresmapp"
2023-08-08 19:09:15 +02:00
[ -d ./matabas-db ] || {
2023-08-09 19:55:23 +02:00
log "Finns ej, skapar brevekorresmapp (./matabas-db)"
2023-08-09 22:41:11 +02:00
pg_ctl initdb --pgdata=./matabas-db -o "--username=$PGUSER"
2023-08-08 19:09:15 +02:00
}
[ -f matabas-db/matabas.log ] && {
2023-08-09 19:55:23 +02:00
log "Flyttar journalen från senaste sittningen till journalarkivet (./matabas-db/matabas.log.old)"
2023-08-08 19:09:15 +02:00
cat matabas-db/matabas.log >> matabas-db/matabas.log.old
rm -f matabas-db/matabas.log
}
2023-08-09 19:55:23 +02:00
log "Startar brevekorren"
2023-08-09 22:41:11 +02:00
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p $PGPORT -k /tmp"
2023-08-08 20:58:17 +02:00
trap exitHook EXIT
2023-08-08 19:09:15 +02:00
2023-08-09 19:55:23 +02:00
log "Skapar matabas"
2023-08-10 01:15:19 +02:00
createdb -h localhost -p "$PGPORT" matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över"
2023-08-09 22:41:11 +02:00
log "Ställer in schema.sql"
2023-08-10 01:15:19 +02:00
psql -h localhost -p "$PGPORT" "$PBDATABASE" < schema.sql
2023-08-09 19:55:23 +02:00
2023-08-09 23:05:03 +02:00
P="$PWD"
clean() {
log "Rensar byggnad"
rm -rf artifacts
}
build() {
source "$P/buildScripts/build.sh"
}
2023-08-09 19:55:23 +02:00
log "Redo" "!"
2023-08-08 19:09:15 +02:00
set +e