Skip to content

Commit 7bb4c88

Browse files
committed
v2.6.0
- MySQL databases management scripts - Better option menus navigation - Modified prompt script helper function - Updated [./README.md]
1 parent 1de8789 commit 7bb4c88

File tree

9 files changed

+363
-20
lines changed

9 files changed

+363
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ This way, I don't have to worry about the things I've mentioned, plus I gain the
171171

172172
- Choose to [**setup**](./scripts/setup.sh) the lara stacker first, which will install everything necessary and eventually create a [[done-setup.flag](./done-setup.flag)] file in the directory.
173173

174-
- Then choose to [**create**](./scripts/create.sh) your first stacked project and continue onwards...
174+
- Then choose to either create a [**stacked**](./scripts/create.sh) laravel application or just a [**raw**](./scripts/create_raw.sh) one and continue onwards...
175175

176176
That's it. You'll have your first project accessible in the end (displaying the site's URL too). JUST be PATIENT! `:)`
177177

lara-stacker.sh

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ current_version="???"
88
if [[ -f $changelog_dir ]]; then
99
current_version=$(grep -E "^## v[0-9]+" $changelog_dir | head -1 | awk '{print $2}')
1010
fi
11-
echo -e "-=|[ Lara-Stacker [$current_version] ]|=-\n"
11+
echo -e "-=|[ LARA-STACKER [$current_version] ]|=-\n"
1212

1313
# * ===========
1414
# * Validation
@@ -42,7 +42,7 @@ fi
4242
# Double check the environment variables
4343
env_example_vars=$(grep -oE '^[A-Z_]+=' .env.example | sort)
4444
env_vars=$(grep -oE '^[A-Z_]+=' .env | sort)
45-
diff <(echo "$env_example_vars") <(echo "$env_vars") &> /dev/null
45+
diff <(echo "$env_example_vars") <(echo "$env_vars") &>/dev/null
4646
if [ $? -ne 0 ]; then
4747
prompt "Aborted for different environment variables." "Ensure that [.env.example] variables match [.env] ones." true false
4848
fi
@@ -55,6 +55,9 @@ SCRIPTS=(
5555
"./scripts/create_raw.sh"
5656
"./scripts/delete.sh"
5757
"./scripts/update.sh"
58+
"./scripts/databases/list.sh"
59+
"./scripts/databases/create.sh"
60+
"./scripts/databases/delete.sh"
5861
"./scripts/helpers/permit.sh"
5962
)
6063
for script in "${SCRIPTS[@]}"; do
@@ -114,25 +117,27 @@ counter=0
114117
while true; do
115118
counter=$((counter + 1))
116119

117-
echo -e "-=|[ Lara-Stacker [$current_version] ]|=-\n"
120+
echo -e "-=|[ LARA-STACKER [$current_version] ]|=-\n"
118121

119122
echo -e "Supported Stacks:\n"
120123
echo -e "- TALL (TailwindCSS, AlpineJS, Livewire, Laravel)\n"
121124

122125
echo -e "Available Operations:\n"
123126

124-
options=("1. List Projects" "2. Create Project" "3. Create Raw Project" "4. Delete Project" "5. Exit")
127+
options=("1. Stacked Laravel Projects" "2. Manage MySQL Databases" "3. Create A Raw Laravel Project" "4. Exit")
125128

126129
# Conditional options
130+
include_zero=false
127131
if [[ -f "/tmp/updated-lara-stacker.flag" ]]; then
128132
rm /tmp/updated-lara-stacker.flag
129133
update_available=false
130134
fi
131135
if [ "$update_available" == true ]; then
132-
options+=("6. Download Updates")
136+
options+=("5. Download Updates")
133137
fi
134138
if [[ ! -f "$lara_stacker_dir/done-setup.flag" ]]; then
135139
options+=("0. Initial Setup")
140+
include_zero=true
136141
fi
137142

138143
options_count=$((${#options[@]} - 1))
@@ -145,44 +150,111 @@ while true; do
145150
if [[ $counter -eq 1 && "$1" ]]; then
146151
choice="$1"
147152
else
148-
read -p "Choose an operation (0-$options_count): " choice
153+
if [ "$include_zero" == true ]; then
154+
read -p "Choose an operation (0-$options_count): " choice
155+
else
156+
read -p "Choose an operation (1-$options_count): " choice
157+
fi
149158
fi
150159

151160
clear
152161

153162
case $choice in
154163
0)
155164
if [[ -f "$lara_stacker_dir/done-setup.flag" ]]; then
156-
prompt "-=|[ Lara-Stacker [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
165+
prompt "-=|[ LARA-STACKER [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
157166
else
158167
sudo RAN_MAIN_SCRIPT="true" ./scripts/setup.sh
159168
fi
160169
;;
161170
1)
162-
RAN_MAIN_SCRIPT="true" ./scripts/list.sh
171+
while true; do
172+
clear
173+
174+
echo -e "-=|[ Lara-Stacker |> STACKED PROJECTS ]|=-\n"
175+
176+
echo -e "Available Operations:\n"
177+
178+
echo "1. List All Projects"
179+
echo "2. Stack A New Project"
180+
echo "3. Delete A Project"
181+
echo -e "4. Go Back To Main Menu\n"
182+
183+
read -p "Choose an operation (1-3): " stack_choice
184+
185+
case $stack_choice in
186+
1)
187+
RAN_MAIN_SCRIPT="true" ./scripts/list.sh
188+
;;
189+
2)
190+
sudo RAN_MAIN_SCRIPT="true" ./scripts/create.sh
191+
;;
192+
3)
193+
sudo RAN_MAIN_SCRIPT="true" ./scripts/delete.sh
194+
;;
195+
4)
196+
clear
197+
break
198+
;;
199+
*)
200+
clear
201+
prompt "-=|[ Lara-Stacker |> STACKED PROJECTS ]|=-" "Invalid option! Please type one the of digits in the list..." false false true
202+
;;
203+
esac
204+
done
163205
;;
164206
2)
165-
sudo RAN_MAIN_SCRIPT="true" ./scripts/create.sh
207+
while true; do
208+
clear
209+
210+
echo -e "-=|[ Lara-Stacker |> DATABASE MANAGEMENT ]|=-\n"
211+
212+
echo -e "Available Operations:\n"
213+
214+
echo "1. List All Databases"
215+
echo "2. Create A Database"
216+
echo "3. Delete A Database"
217+
echo -e "4. Go Back To Main Menu\n"
218+
219+
read -p "Choose an operation (1-3): " db_choice
220+
221+
case $db_choice in
222+
1)
223+
RAN_MAIN_SCRIPT="true" ./scripts/databases/list.sh
224+
;;
225+
2)
226+
RAN_MAIN_SCRIPT="true" ./scripts/databases/create.sh
227+
;;
228+
3)
229+
RAN_MAIN_SCRIPT="true" ./scripts/databases/delete.sh
230+
;;
231+
4)
232+
clear
233+
break
234+
;;
235+
*)
236+
clear
237+
prompt "-=|[ Lara-Stacker |> DATABASE MANAGEMENT ]|=-" "Invalid option! Please type one the of digits in the list..." false false true
238+
;;
239+
esac
240+
done
166241
;;
167242
3)
168243
sudo RAN_MAIN_SCRIPT="true" ./scripts/create_raw.sh
169244
;;
170245
4)
171-
sudo RAN_MAIN_SCRIPT="true" ./scripts/delete.sh
172-
;;
173-
5)
174246
echo -e "\nExiting Lara-Stacker...\n"
175247
exit 0
176248
;;
177-
6)
249+
5)
178250
if [ "$update_available" == false ]; then
179-
prompt "-=|[ Lara-Stacker [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
251+
prompt "-=|[ LARA-STACKER [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
180252
else
181253
sudo RAN_MAIN_SCRIPT="true" ./scripts/update.sh
182254
fi
183255
;;
184256
*)
185-
prompt "-=|[ Lara-Stacker [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
257+
prompt "-=|[ LARA-STACKER [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false true
186258
;;
187259
esac
188260
done

scripts/create.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
clear
44

55
# Status indicator
6-
echo -e "-=|[ Lara-Stacker |> CREATE ]|=-\n"
6+
echo -e "-=|[ Lara-Stacker |> Stacked Projects |> CREATE ]|=-\n"
77

88
# * ===========
99
# * Validation

scripts/databases/create.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
3+
clear
4+
5+
# Status indicator
6+
echo -e "-=|[ Lara-Stacker |> Database Management |> CREATE ]|=-\n"
7+
8+
# * ===========
9+
# * Validation
10+
# * =========
11+
12+
# Check if prompt function exists and source it
13+
function_path="./scripts/functions/prompt.sh"
14+
if [[ ! -f $function_path ]]; then
15+
echo -e "Error: Working directory isn't the script's main.\n"
16+
17+
echo -e "Tip: Maybe run [cd ~/Downloads/lara-stacker/ && sudo ./lara-stacker.sh] commands.\n"
18+
19+
echo -n "Press any key to exit..."
20+
read whatever
21+
22+
clear
23+
exit 1
24+
fi
25+
source $function_path
26+
27+
# Ensure the script isn't ran directly
28+
if [[ -z "$RAN_MAIN_SCRIPT" ]]; then
29+
prompt "Aborted for direct execution flow." "Please use the main [lara-stacker.sh] script." true false
30+
fi
31+
32+
# Confirm if setup script isn't run
33+
if [ ! -e "$PWD/done-setup.flag" ]; then
34+
echo -n "Setup script isn't run yet. Are you sure you want to continue? (y/n) "
35+
read confirmation
36+
37+
case "$confirmation" in
38+
n|N|no|No|NO|nope|Nope|NOPE)
39+
echo -e "\nAborting...\n"
40+
41+
echo -n "Press any key to continue..."
42+
read whatever
43+
44+
clear
45+
exit 1
46+
;;
47+
esac
48+
fi
49+
50+
# * ============
51+
# * Preparation
52+
# * ==========
53+
54+
# Get environment variables and defaults
55+
lara_stacker_dir=$PWD
56+
source $lara_stacker_dir/.env
57+
58+
# Setting the echoing level
59+
conditional_quiet="--quiet"
60+
cancel_suppression=false
61+
case $LOGGING_LEVEL in
62+
# Notifications Only
63+
1)
64+
exec 3>&1
65+
exec > /dev/null 2>&1
66+
;;
67+
# Notifications + Errors + Warnings
68+
2)
69+
exec 3>&1
70+
exec > /dev/null
71+
;;
72+
# Everything
73+
*)
74+
exec 3>&1
75+
conditional_quiet=""
76+
cancel_suppression=true
77+
;;
78+
esac
79+
80+
# * ========
81+
# * Process
82+
# * ======
83+
84+
# Get the db name
85+
echo -ne "Enter the database name: " >&3
86+
read db_name
87+
88+
# Escape and format the name
89+
db_name=$(echo "$db_name" | tr ' ' '-' | tr '_' '-' | tr '[:upper:]' '[:lower:]')
90+
db_name=${db_name// /}
91+
db_name=$(echo "$db_name" | sed 's/\([[:lower:]]\)\([[:upper:]]\)/\1_\2/g' | sed 's/\([[:upper:]]\)\([[:upper:]][[:lower:]]\)/\1_\2/g' | tr '-' '_' | tr '[:upper:]' '[:lower:]' | sed 's/__/_/g' | sed 's/^_//')
92+
93+
# DB Creation
94+
export MYSQL_PWD=$DB_PASSWORD
95+
if mysql -u root -e "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME='$db_name'" | grep "$db_name" > /dev/null; then
96+
echo -e "\nMySQL database '$db_name' already exists!" >&3
97+
else
98+
mysql -u root -e "CREATE DATABASE $db_name;"
99+
echo -e "\nCreated '$db_name' MySQL database." >&3
100+
fi
101+
102+
echo -ne "\nPress any key to continue..." >&3
103+
read whatever
104+
105+
clear >&3

0 commit comments

Comments
 (0)