· 8 years ago · Mar 03, 2018, 10:40 PM
1#!/bin/bash
2export COLOR_GHOST="\e[1;96m";
3export COLOR_RESET="\e[0m";
4export COLOR_RED="\e[1;91m";
5export UNKNOWN_ARG="Unrecognised arguments!";
6USAGE="${COLOR_GHOST}Usage:${COLOR_RESET} ./scoreboard.sh <-h usage>
7 - <-r reset scoreboard>
8 - <-s start scoreboard>
9 - <- display help>";
10HELP="show - display scoreboard
11category - create a new category
12score - enter a new score
13update - update a score
14delete - remove a score or category
15exit - exit scoreboard";
16GHOST_ECHO() {
17 echo -e "${COLOR_GHOST}$1${COLOR_RESET}";
18}
19export -f GHOST_ECHO;
20GHOST_ECHO_RED() {
21 echo -e "${COLOR_RED}$1${COLOR_RESET}";
22}
23export -f GHOST_ECHO_RED;
24GHOST_USAGE() {
25 GHOST_ECHO "$USAGE";
26 exit 0;
27}
28export -f GHOST_USAGE;
29GHOST_ERROR_USAGE() {
30 GHOST_ECHO "$2\n$USAGE";
31 exit $1;
32}
33export -f GHOST_ERROR_USAGE;
34GHOST_ARG_UNKNOWN() {
35 GHOST_ERROR_USAGE 1 "$UNKNOWN_ARG";
36}
37export -f GHOST_ARG_UNKNOWN;
38GET_INPUT() {
39 read -p "$1 " data;
40 if [ ! -z "$data" ]; then # Add check to see if not present in database
41 echo "$data";
42 elif [ -z "$data" ]; then
43 GHOST_ECHO_RED "No input supplied!";
44 else
45 GHOST_ECHO_RED "This already exists!";
46 fi
47}
48while [[ $# -gt 0 ]]; do
49 key="$1";
50 case $key in
51 -s|--start-scoreboard)
52 GHOST_ECHO "Scoreboard has started!";
53 while read -p "Command: " r; do
54 case $r in
55 d|delete)
56 category=$(GET_INPUT "Category name:");
57 if [ ! -z "$category" ]; then
58 # Check if user wants to continue
59 score=$(GET_INPUT "Score title:");
60 if [ ! -z "$score" ]; then
61 # Available: $category, $score.
62 echo "not done"; # Make query to delete the score
63 fi
64 fi
65 ;;
66 u|update)
67 category=$(GET_INPUT "Category name:");
68 if [ ! -z "$category" ]; then
69 score=$(GET_INPUT "Score title:");
70 if [ ! -z "$score" ]; then
71 data=$(GET_INPUT "Score data:");
72 if [ ! -z "$data" ]; then
73 echo "not done"; # Available: $category, $score, $data
74 # Make query to alter a row
75 fi
76 fi
77 fi
78 ;;
79 c|category)
80 read -p "New category name: " category;
81 if [ ! -z "$category" ]; then # Add check to see if its in the database
82 echo "not done"; # Available: $category
83 # Make query to create table
84 elif [ -z "$category" ]; then
85 GHOST_ECHO_RED "No category supplied!";
86 else
87 GHOST_ECHO_RED "Category already exists!";
88 fi
89 ;;
90 score)
91 category=$(GET_INPUT "Category name:");
92 if [ ! -z "$category" ]; then
93 score=$(GET_INPUT "New score title:");
94 if [ ! -z "$score" ]; then
95 data=$(GET_INPUT "New score data:");
96 if [ ! -z "$data" ]; then
97 # Available: $category, $score, $data
98 # Query to update table.
99 GHOST_ECHO "New score added!";
100 fi
101 fi
102 fi
103 ;;
104 s|show)
105 GHOST_ECHO "Highscores:";
106 # Query to get all tables.
107 # Display information using: pr
108 ;;
109 quit|exit)
110 break;
111 ;;
112 *)
113 GHOST_ECHO "Unknown command!\nAvailable commands:\n$HELP";
114 ;;
115 esac
116 done
117 GHOST_ECHO "Scoreboard has ended!";
118 exit 0;
119 ;;
120 -r|--reset-scoreboard)
121 if [ ]; then # Add command to drop and create a database
122 GHOST_ECHO "Scoreboard has been reset!";
123 else
124 GHOST_ECHO_RED "Scoreboard data file error!";
125 fi
126 exit 0;
127 ;;
128 -h|--help)
129 GHOST_USAGE;
130 ;;
131 *)
132 GHOST_ARG_UNKNOWN;
133 ;;
134 esac
135done
136GHOST_USAGE;
137exit 0;