Added function to add name to confirmation texts, and applied to all applicable functions

master
Aaron Johnson 4 years ago
parent 1300b988f2
commit 0e10b46505

38
bank

@ -98,6 +98,18 @@ Q. Quit
### Primary Functions ### ### Primary Functions ###
dbconnect="psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -d ${DB_NAME}" dbconnect="psql -h ${DB_HOST} -p ${DB_PORT} -U ${DB_USER} -d ${DB_NAME}"
get_name() {
# Arg1 == Account ID
# Arg2 == "bold" for bold text
NAME=$(eval "$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}')
# Strip leading/trailing space from $NAME
NAME=${NAME#"${NAME%%[! ]*}"} NAME=${NAME%"${NAME##*[! ]}"}
if [ "$2" == "bold" ]; then
echo $(tput bold)${NAME}$(tput sgr0)
else
echo $NAME
fi
}
create_account() { create_account() {
read -p "Enter Account Name: " name read -p "Enter Account Name: " name
@ -121,10 +133,12 @@ create_account() {
disable_account() { disable_account() {
#printf "\n$(tput bold)$(tput setaf 3)This action is not yet supported!\n\n$(tput sgr0)" #printf "\n$(tput bold)$(tput setaf 3)This action is not yet supported!\n\n$(tput sgr0)"
eval "$dbconnect -c \"SELECT id,name,created FROM account WHERE enabled = true;\"" eval "$dbconnect -c \"SELECT id,name,created FROM account WHERE enabled = true ORDER BY name;\""
read -p "Enter Account ID: " ID read -p "Enter Account ID: " ID
NAME=$(eval "$dbconnect -c \"SELECT id,name,created FROM account WHERE id = ${ID};\"" | 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=$(eval "$dbconnect -c \"SELECT id,name,created FROM account WHERE id = ${ID};\"" | grep -E "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}" | awk -F '|' '{print $2}')
read -p "$(tput bold)$(tput setaf 3)DISABLING$(tput sgr0) account #${ID}:$(tput bold)${NAME}$(tput sgr0)... Are you sure? (y/N)" -n1 CONFIRM #read -p "$(tput bold)$(tput setaf 3)DISABLING$(tput sgr0) account #${ID}:$(tput bold)${NAME}$(tput sgr0)... Are you sure? (y/N)" -n1 CONFIRM
#read -p "$(tput bold)$(tput setaf 3)DISABLING$(tput sgr0) account #${ID}:$(tput bold)$(get_name $ID)$(tput sgr0)... Are you sure? (y/N)" -n1 CONFIRM
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 case $CONFIRM in
[Yy]) [Yy])
printf "\n$(tput bold)$(tput setaf 3)Disabling account...\n\n$(tput sgr0)" printf "\n$(tput bold)$(tput setaf 3)Disabling account...\n\n$(tput sgr0)"
@ -146,10 +160,9 @@ disable_account() {
enable_account() { enable_account() {
echo "DISABLED Accounts:" echo "DISABLED Accounts:"
eval "$dbconnect -c \"SELECT id,name,created FROM account WHERE enabled = false;\"" eval "$dbconnect -c \"SELECT id,name,created FROM account WHERE enabled = false ORDER BY name;\""
read -p "Enter Account ID: " ID read -p "Enter Account ID: " ID
NAME=$(eval "$dbconnect -c \"SELECT id,name,created FROM account WHERE id = ${ID};\"" | grep -E "[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}" | awk -F '|' '{print $2}') read -p "$(tput bold)Enabling$(tput sgr0) account #${ID}: $(get_name $ID bold). Are you sure? (y/N)" -n1 CONFIRM
read -p "$(tput bold)Enabling$(tput sgr0) account #${ID}:$(tput bold)${NAME}$(tput sgr0)... Are you sure? (y/N)" -n1 CONFIRM
case $CONFIRM in case $CONFIRM in
[Yy]) [Yy])
printf "\n$(tput bold)$(tput setaf 3)Disabling account...\n\n$(tput sgr0)" printf "\n$(tput bold)$(tput setaf 3)Disabling account...\n\n$(tput sgr0)"
@ -170,11 +183,11 @@ enable_account() {
} }
make_deposit() { make_deposit() {
eval "$dbconnect -c \"SELECT id,name FROM account WHERE enabled = true;\"" eval "$dbconnect -c \"SELECT id,name FROM account WHERE enabled = true ORDER BY name;\""
read -p "Enter Account ID: " ID read -p "Enter Account ID: " ID
read -p "Enter amount of gp to deposit: " amount read -p "Enter amount of gp to deposit: " amount
tstamp=$(date +%Y-%m-%d\ %H:%M:%S) tstamp=$(date +%Y-%m-%d\ %H:%M:%S)
read -p "Depositing ${amount}gp into account ${ID}. Are you sure? (y/N)" -n1 CONFIRM read -p "Depositing ${amount}gp into account #${ID}: $(get_name $ID bold). Are you sure? (y/N)" -n1 CONFIRM
case $CONFIRM in case $CONFIRM in
[Yy]) [Yy])
printf "\n$(tput bold)Depositing...\n\n$(tput sgr0)" printf "\n$(tput bold)Depositing...\n\n$(tput sgr0)"
@ -196,11 +209,11 @@ make_deposit() {
} }
make_withdrawal() { make_withdrawal() {
eval "$dbconnect -c \"SELECT id,name FROM account WHERE enabled = true;\"" eval "$dbconnect -c \"SELECT id,name FROM account WHERE enabled = true ORDER BY name;\""
read -p "Enter Account ID: " ID read -p "Enter Account ID: " ID
read -p "Enter amount of gp to withdraw: " amount read -p "Enter amount of gp to withdraw: " amount
tstamp=$(date +%Y-%m-%d\ %H:%M:%S) tstamp=$(date +%Y-%m-%d\ %H:%M:%S)
read -p "Withdrawing ${amount}gp from account ${ID}. Are you sure? (y/N)" -n1 CONFIRM read -p "Withdrawing ${amount}gp from account #${ID}: $(get_name $ID bold). Are you sure? (y/N)" -n1 CONFIRM
case $CONFIRM in case $CONFIRM in
[Yy]) [Yy])
printf "\n$(tput bold)Withdrawing...\n\n$(tput sgr0)" printf "\n$(tput bold)Withdrawing...\n\n$(tput sgr0)"
@ -229,7 +242,8 @@ bank_transfer() {
read -p "Enter Account ID to transfer $(tput bold)TO$(tput sgr0): " TO read -p "Enter Account ID to transfer $(tput bold)TO$(tput sgr0): " TO
read -p "Enter amount of gp to transfer: " amount read -p "Enter amount of gp to transfer: " amount
tstamp=$(date +%Y-%m-%d\ %H:%M:%S) tstamp=$(date +%Y-%m-%d\ %H:%M:%S)
read -p "Transfer ${amount}gp from account ${FROM} to account ${TO}. Are you sure? (y/N)" -n1 CONFIRM #read -p "Transfer ${amount}gp from account #${FROM}:$(tput bold)$(get_name $ID)$(tput sgr0)to account #${TO}:$(tput bold)$(get_name $ID)$(tput sgr0)... Are you sure? (y/N)" -n1 CONFIRM
read -p "Transferring ${amount}gp from $(get_name $FROM bold) to $(get_name $TO bold). Are you sure? (y/N)" -n1 CONFIRM
case $CONFIRM in case $CONFIRM in
[Yy]) [Yy])
printf "\n$(tput bold)Transferring...\n\n$(tput sgr0)" printf "\n$(tput bold)Transferring...\n\n$(tput sgr0)"
@ -269,7 +283,7 @@ show_transactions() {
} }
show_transfers() { show_transfers() {
eval "$dbconnect -c \"SELECT transfer.id,f.name AS from,t.name AS to,gold,timestamp FROM transfer LEFT JOIN account AS f ON f.id = transfer.from_id LEFT JOIN account AS t ON t.id = transfer.to_id;\"" eval "$dbconnect -c \"SELECT transfer.id,f.name AS from,t.name AS to,gold,timestamp FROM transfer LEFT JOIN account AS f ON f.id = transfer.from_id LEFT JOIN account AS t ON t.id = transfer.to_id ORDER BY timestamp;\""
hold_menu hold_menu
} }

Loading…
Cancel
Save