Merge branch 'master' of ssh://git.skyfall.tech/ajohnson/dnd_bank

master
Aaron Johnson 4 years ago
commit ac9f15e719

@ -0,0 +1,39 @@
# Bank of Skyfall, D&D Edition
This is currently a glorified shell script that functions like an interactive CLI application and uses a PostgreSQL database.
Let's get a couple things, that I know I am going to hear, out of the way first:
#### Will you make a MySQL version?
No.
#### You should use SQLite. Postgres is way overkill for something like this.
Yes. It is. A SQLite version is planned, but I *like* Postgres, so that's what I chose to write for first.
#### Can you set up multiple banks?
Not very easily with this early version, but that will be a thing later on.
## Setup
First, set up your Postgres DB that you intend to use. I recommend using UNICODE in case a player character insists on using diacritics, or of course, if your native language requires it. I use these options:
```sh
# Yes, I know some of these options are redundant, but I never
# remember which ones, it doesn't hurt, and DERPA is easy to remember.
# Please note that your DB password, like is often required, will be
# stored as plain text in the configuration file.
#### DO NOT RE-USE YOUR PASSWORDS, especially here. ####
createuser -DERPA [your_user]
createdb -E UNICODE -O [your_user] dnd_bank
```
Next, import the table structure included in this repo for a blank bank:
```sh
psql -h [db_host] -p [db_port] -U [your_user] -d [db_name] < dnd_bank.psql
```
Finally, set up your configuration file. (This step will be unnecessary via a guided configuration that will be included in a future update)
```sh
cp [repo_location]/dndbank.conf ~/
vim ~/.dndbank.conf
# Fill out the information
```
Now just run the `bank` script and create some accounts. You are good to go!

14
bank

@ -22,7 +22,7 @@ hold_menu() {
}
show_menu() {
#[ "$1" == "init" ] || pre_menu
#[ "$1" = "init" ] || pre_menu
printf 'Select a function by number:
1. Create Account
@ -104,7 +104,7 @@ get_name() {
NAME=$($dbconnect -c "SELECT id,name,created FROM account WHERE id = $1;" | grep -E "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}" | awk -F '|' '{print $2}')
NAME=${NAME#"${NAME%%[! ]*}"} NAME=${NAME%"${NAME##*[! ]}"} #Strip leading/trailing space from $NAME
if [ "$2" == "bold" ]; then
if [ "$2" = "bold" ]; then
echo $(tput bold)${NAME}$(tput sgr0)
else
echo $NAME
@ -113,7 +113,7 @@ get_name() {
create_account() {
read -p "Enter Account Name ('c' to cancel): " name
([ "$name" == "c" ] || [ "$name" == "c" ]) && return
([ "$name" = "c" ] || [ "$name" = "c" ]) && return
tstamp=$(date +%Y-%m-%d\ %H:%M:%S)
read -p "Creating account: '${name}'. Are you sure? (y/N)" -n1 CONFIRM
case $CONFIRM in
@ -134,7 +134,7 @@ create_account() {
disable_account() {
$dbconnect -c "SELECT id,name,created FROM account WHERE enabled = true ORDER BY name;"
read -p "Enter Account ID ('c' to cancel): " ID
([ "$ID" == "c" ] || [ "$ID" == "c" ]) && return
([ "$ID" = "c" ] || [ "$ID" = "c" ]) && return
read -p "$(tput bold)$(tput setaf 3)DISABLING$(tput sgr0) account #${ID}: $(get_name $ID bold). Are you sure? (y/N)" -n1 CONFIRM
case $CONFIRM in
[Yy])
@ -154,7 +154,7 @@ enable_account() {
echo "DISABLED Accounts:"
$dbconnect -c "SELECT id,name,created FROM account WHERE enabled = false ORDER BY name;"
read -p "Enter Account ID ('c' to cancel): " ID
([ "$ID" == "c" ] || [ "$ID" == "c" ]) && return
([ "$ID" = "c" ] || [ "$ID" = "c" ]) && return
read -p "$(tput bold)Enabling$(tput sgr0) account #${ID}: $(get_name $ID bold). Are you sure? (y/N)" -n1 CONFIRM
case $CONFIRM in
[Yy])
@ -173,7 +173,7 @@ enable_account() {
make_deposit() {
$dbconnect -c "SELECT id,name FROM account WHERE enabled = true ORDER BY name;"
read -p "Enter Account ID ('c' to cancel): " ID
([ "$ID" == "c" ] || [ "$ID" == "c" ]) && return
([ "$ID" = "c" ] || [ "$ID" = "c" ]) && return
read -p "Enter amount of gp to deposit: " amount
tstamp=$(date +%Y-%m-%d\ %H:%M:%S)
read -p "Depositing ${amount}gp into account #${ID}: $(get_name $ID bold). Are you sure? (y/N)" -n1 CONFIRM
@ -197,7 +197,7 @@ make_deposit() {
make_withdrawal() {
$dbconnect -c "SELECT account.id,account.name,gold FROM balance INNER JOIN account ON account.id = balance.id WHERE account.enabled = true ORDER BY name;" #Show balances first
read -p "Enter Account ID ('c' to cancel): " ID
([ "$ID" == "c" ] || [ "$ID" == "c" ]) && return
([ "$ID" = "c" ] || [ "$ID" = "c" ]) && return
read -p "Enter amount of gp to withdraw: " amount
tstamp=$(date +%Y-%m-%d\ %H:%M:%S)
read -p "Withdrawing ${amount}gp from account #${ID}: $(get_name $ID bold). Are you sure? (y/N)" -n1 CONFIRM

@ -0,0 +1,12 @@
# Configure these:
DB_HOST=localhost
DB_PORT=5432
DB_USER=testy.mcgee
DB_PASS=12345
DB_NAME=dnd_bank
# DO NOT TOUCH:
export PGPASSWORD=$DB_PASS
Loading…
Cancel
Save