2023-08-11 17:07:09 +02:00
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
|
|
|
|
# Check for lock
|
|
|
|
[ -f matabas-db/dev-lock ]
|
|
|
|
IS_OWNER=$? # non-zero is owner
|
|
|
|
|
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-11 17:07:09 +02:00
|
|
|
# Only trapped if owner
|
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-11 17:07:09 +02:00
|
|
|
rm -f matabas-db/dev-lock
|
2023-08-08 20:58:17 +02:00
|
|
|
}
|
|
|
|
|
2023-08-11 17:07:09 +02:00
|
|
|
setupDb() {
|
|
|
|
log "Letar efter existerande brevekorresmapp"
|
|
|
|
[ -d ./matabas-db ] || {
|
|
|
|
log "Finns ej, skapar brevekorresmapp (./matabas-db)"
|
|
|
|
pg_ctl initdb --pgdata=./matabas-db -o "--username=$PGUSER"
|
|
|
|
}
|
2023-08-08 19:09:15 +02:00
|
|
|
|
2023-08-11 17:07:09 +02:00
|
|
|
[ -f matabas-db/matabas.log ] && {
|
|
|
|
log "Flyttar journalen från senaste sittningen till journalarkivet (./matabas-db/matabas.log.old)"
|
|
|
|
cat matabas-db/matabas.log >> matabas-db/matabas.log.old
|
|
|
|
rm -f matabas-db/matabas.log
|
|
|
|
}
|
2023-08-08 19:09:15 +02:00
|
|
|
|
2023-08-11 17:07:09 +02:00
|
|
|
log "Startar brevekorren"
|
|
|
|
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p $PGPORT -k /tmp"
|
|
|
|
log "Låser databasen"
|
|
|
|
:> matabas-db/dev-lock
|
|
|
|
trap exitHook EXIT
|
2023-08-08 19:09:15 +02:00
|
|
|
|
2023-08-11 17:07:09 +02:00
|
|
|
log "Skapar matabas"
|
|
|
|
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
|
|
|
|
2023-08-11 17:07:09 +02:00
|
|
|
log "Ställer in schema.sql"
|
|
|
|
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() {
|
2023-08-11 17:07:09 +02:00
|
|
|
log "Rensar byggnad"
|
|
|
|
rm -rf artifacts
|
2023-08-09 23:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
build() {
|
2023-08-11 17:07:09 +02:00
|
|
|
source "$P/buildScripts/build.sh"
|
2023-08-09 23:05:03 +02:00
|
|
|
}
|
|
|
|
|
2023-08-11 17:07:09 +02:00
|
|
|
if [ "$IS_OWNER" -ne 0 ] ; then
|
|
|
|
setupDb
|
|
|
|
else
|
|
|
|
log "Startar som icke-ägare, startar ej databasen"
|
|
|
|
fi
|
|
|
|
|
2023-08-09 19:55:23 +02:00
|
|
|
log "Redo" "!"
|
2023-08-08 19:09:15 +02:00
|
|
|
|
|
|
|
set +e
|
2023-08-11 17:07:09 +02:00
|
|
|
|
|
|
|
cd - >/dev/null 2>&1
|