matabas/build/devShellHook.sh

62 lines
1.3 KiB
Bash
Raw Normal View History

2023-08-08 19:09:15 +02:00
set -e
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-08 19:09:15 +02:00
pg_ctl initdb --pgdata=./matabas-db
}
[ -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-08 19:09:15 +02:00
pg_ctl start --pgdata=./matabas-db --log=./matabas-db/matabas.log --options="-p 2137 -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 20:09:42 +02:00
createdb -p 2137 matabas 2>>./matabas-db/matabas.log || log "Matabasen finns, skriver ej över"
2023-08-08 19:09:15 +02:00
2023-08-09 19:55:23 +02:00
log "Försvensknar miljön"
_cargo() {
cuh="$1"
shift
case "$cuh" in
kör|spring)
cargo run "$@"
;;
ny)
cargo new "$@"
;;
pröva)
cargo test "$@"
;;
bygg)
cargo build "$@"
;;
enna)
cargo init "$@"
;;
*)
echo "vafan gö du"
;;
esac
}
alias 'last=_cargo'
alias cargo=exit
log "Redo" "!"
2023-08-08 19:09:15 +02:00
set +e