Skip to content

Commit

Permalink
v2.6.0
Browse files Browse the repository at this point in the history
- MySQL databases management scripts
- Better option menus navigation
- Modified prompt script helper function
- Updated [./README.md]
  • Loading branch information
GoodM4ven committed Oct 19, 2023
1 parent 1de8789 commit 7bb4c88
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ This way, I don't have to worry about the things I've mentioned, plus I gain the

- 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.

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

That's it. You'll have your first project accessible in the end (displaying the site's URL too). JUST be PATIENT! `:)`
Expand Down
102 changes: 87 additions & 15 deletions lara-stacker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ current_version="???"
if [[ -f $changelog_dir ]]; then
current_version=$(grep -E "^## v[0-9]+" $changelog_dir | head -1 | awk '{print $2}')
fi
echo -e "-=|[ Lara-Stacker [$current_version] ]|=-\n"
echo -e "-=|[ LARA-STACKER [$current_version] ]|=-\n"

# * ===========
# * Validation
Expand Down Expand Up @@ -42,7 +42,7 @@ fi
# Double check the environment variables
env_example_vars=$(grep -oE '^[A-Z_]+=' .env.example | sort)
env_vars=$(grep -oE '^[A-Z_]+=' .env | sort)
diff <(echo "$env_example_vars") <(echo "$env_vars") &> /dev/null
diff <(echo "$env_example_vars") <(echo "$env_vars") &>/dev/null
if [ $? -ne 0 ]; then
prompt "Aborted for different environment variables." "Ensure that [.env.example] variables match [.env] ones." true false
fi
Expand All @@ -55,6 +55,9 @@ SCRIPTS=(
"./scripts/create_raw.sh"
"./scripts/delete.sh"
"./scripts/update.sh"
"./scripts/databases/list.sh"
"./scripts/databases/create.sh"
"./scripts/databases/delete.sh"
"./scripts/helpers/permit.sh"
)
for script in "${SCRIPTS[@]}"; do
Expand Down Expand Up @@ -114,25 +117,27 @@ counter=0
while true; do
counter=$((counter + 1))

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

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

echo -e "Available Operations:\n"

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

# Conditional options
include_zero=false
if [[ -f "/tmp/updated-lara-stacker.flag" ]]; then
rm /tmp/updated-lara-stacker.flag
update_available=false
fi
if [ "$update_available" == true ]; then
options+=("6. Download Updates")
options+=("5. Download Updates")
fi
if [[ ! -f "$lara_stacker_dir/done-setup.flag" ]]; then
options+=("0. Initial Setup")
include_zero=true
fi

options_count=$((${#options[@]} - 1))
Expand All @@ -145,44 +150,111 @@ while true; do
if [[ $counter -eq 1 && "$1" ]]; then
choice="$1"
else
read -p "Choose an operation (0-$options_count): " choice
if [ "$include_zero" == true ]; then
read -p "Choose an operation (0-$options_count): " choice
else
read -p "Choose an operation (1-$options_count): " choice
fi
fi

clear

case $choice in
0)
if [[ -f "$lara_stacker_dir/done-setup.flag" ]]; then
prompt "-=|[ Lara-Stacker [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
prompt "-=|[ LARA-STACKER [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
else
sudo RAN_MAIN_SCRIPT="true" ./scripts/setup.sh
fi
;;
1)
RAN_MAIN_SCRIPT="true" ./scripts/list.sh
while true; do
clear

echo -e "-=|[ Lara-Stacker |> STACKED PROJECTS ]|=-\n"

echo -e "Available Operations:\n"

echo "1. List All Projects"
echo "2. Stack A New Project"
echo "3. Delete A Project"
echo -e "4. Go Back To Main Menu\n"

read -p "Choose an operation (1-3): " stack_choice

case $stack_choice in
1)
RAN_MAIN_SCRIPT="true" ./scripts/list.sh
;;
2)
sudo RAN_MAIN_SCRIPT="true" ./scripts/create.sh
;;
3)
sudo RAN_MAIN_SCRIPT="true" ./scripts/delete.sh
;;
4)
clear
break
;;
*)
clear
prompt "-=|[ Lara-Stacker |> STACKED PROJECTS ]|=-" "Invalid option! Please type one the of digits in the list..." false false true
;;
esac
done
;;
2)
sudo RAN_MAIN_SCRIPT="true" ./scripts/create.sh
while true; do
clear

echo -e "-=|[ Lara-Stacker |> DATABASE MANAGEMENT ]|=-\n"

echo -e "Available Operations:\n"

echo "1. List All Databases"
echo "2. Create A Database"
echo "3. Delete A Database"
echo -e "4. Go Back To Main Menu\n"

read -p "Choose an operation (1-3): " db_choice

case $db_choice in
1)
RAN_MAIN_SCRIPT="true" ./scripts/databases/list.sh
;;
2)
RAN_MAIN_SCRIPT="true" ./scripts/databases/create.sh
;;
3)
RAN_MAIN_SCRIPT="true" ./scripts/databases/delete.sh
;;
4)
clear
break
;;
*)
clear
prompt "-=|[ Lara-Stacker |> DATABASE MANAGEMENT ]|=-" "Invalid option! Please type one the of digits in the list..." false false true
;;
esac
done
;;
3)
sudo RAN_MAIN_SCRIPT="true" ./scripts/create_raw.sh
;;
4)
sudo RAN_MAIN_SCRIPT="true" ./scripts/delete.sh
;;
5)
echo -e "\nExiting Lara-Stacker...\n"
exit 0
;;
6)
5)
if [ "$update_available" == false ]; then
prompt "-=|[ Lara-Stacker [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
prompt "-=|[ LARA-STACKER [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
else
sudo RAN_MAIN_SCRIPT="true" ./scripts/update.sh
fi
;;
*)
prompt "-=|[ Lara-Stacker [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false
prompt "-=|[ LARA-STACKER [$current_version] ]|=-" "Invalid option! Please type one the of digits in the list..." false false true
;;
esac
done
2 changes: 1 addition & 1 deletion scripts/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
clear

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

# * ===========
# * Validation
Expand Down
105 changes: 105 additions & 0 deletions scripts/databases/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/bash

clear

# Status indicator
echo -e "-=|[ Lara-Stacker |> Database Management |> CREATE ]|=-\n"

# * ===========
# * Validation
# * =========

# Check if prompt function exists and source it
function_path="./scripts/functions/prompt.sh"
if [[ ! -f $function_path ]]; then
echo -e "Error: Working directory isn't the script's main.\n"

echo -e "Tip: Maybe run [cd ~/Downloads/lara-stacker/ && sudo ./lara-stacker.sh] commands.\n"

echo -n "Press any key to exit..."
read whatever

clear
exit 1
fi
source $function_path

# Ensure the script isn't ran directly
if [[ -z "$RAN_MAIN_SCRIPT" ]]; then
prompt "Aborted for direct execution flow." "Please use the main [lara-stacker.sh] script." true false
fi

# Confirm if setup script isn't run
if [ ! -e "$PWD/done-setup.flag" ]; then
echo -n "Setup script isn't run yet. Are you sure you want to continue? (y/n) "
read confirmation

case "$confirmation" in
n|N|no|No|NO|nope|Nope|NOPE)
echo -e "\nAborting...\n"

echo -n "Press any key to continue..."
read whatever

clear
exit 1
;;
esac
fi

# * ============
# * Preparation
# * ==========

# Get environment variables and defaults
lara_stacker_dir=$PWD
source $lara_stacker_dir/.env

# Setting the echoing level
conditional_quiet="--quiet"
cancel_suppression=false
case $LOGGING_LEVEL in
# Notifications Only
1)
exec 3>&1
exec > /dev/null 2>&1
;;
# Notifications + Errors + Warnings
2)
exec 3>&1
exec > /dev/null
;;
# Everything
*)
exec 3>&1
conditional_quiet=""
cancel_suppression=true
;;
esac

# * ========
# * Process
# * ======

# Get the db name
echo -ne "Enter the database name: " >&3
read db_name

# Escape and format the name
db_name=$(echo "$db_name" | tr ' ' '-' | tr '_' '-' | tr '[:upper:]' '[:lower:]')
db_name=${db_name// /}
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/^_//')

# DB Creation
export MYSQL_PWD=$DB_PASSWORD
if mysql -u root -e "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME='$db_name'" | grep "$db_name" > /dev/null; then
echo -e "\nMySQL database '$db_name' already exists!" >&3
else
mysql -u root -e "CREATE DATABASE $db_name;"
echo -e "\nCreated '$db_name' MySQL database." >&3
fi

echo -ne "\nPress any key to continue..." >&3
read whatever

clear >&3
Loading

0 comments on commit 7bb4c88

Please sign in to comment.