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-09 22:41:11 +02:00
|
|
|
createdb -p "$PGPORT" matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över"
|
|
|
|
|
|
|
|
log "Ställer in schema.sql"
|
|
|
|
psql -p "$PGPORT" "$PBDATABASE" < schema.sql
|
2023-08-09 19:55:23 +02:00
|
|
|
|
|
|
|
log "Redo" "!"
|
2023-08-08 19:09:15 +02:00
|
|
|
|
|
|
|
set +e
|