-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- MySQL databases management scripts - Better option menus navigation - Modified prompt script helper function - Updated [./README.md]
- Loading branch information
Showing
9 changed files
with
363 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.